Security essentials for Flask APIs — CORS, Talisman security headers, rate
99
94%
Does it follow best practices?
Impact
100%
1.17xAverage score across 10 eval scenarios
Passed
No known issues
You have been given a minimal Flask application that currently has no security protections. Your job is to add the necessary security configuration so the app is safe to deploy to production.
Create the following file at app.py:
import os
from flask import Flask, request, jsonify
def create_app():
app = Flask(__name__)
app.config['SECRET_KEY'] = 'dev-secret-hardcoded'
app.debug = True
@app.route('/api/items', methods=['GET'])
def list_items():
return jsonify({'items': []})
@app.route('/api/items', methods=['POST'])
def create_item():
data = request.get_json()
return jsonify({'created': True}), 201
@app.route('/api/items/<int:item_id>', methods=['DELETE'])
def delete_item(item_id):
return jsonify({'deleted': True})
return app
if __name__ == '__main__':
app = create_app()
app.run()Add CORS support so the app only allows requests from origins listed in an ALLOWED_ORIGINS environment variable (falling back to http://localhost:5173 if the variable is not set). Do not allow all origins.
Add HTTP security headers using an appropriate Flask extension.
Add rate limiting:
Fix the secret key so it is loaded from the SECRET_KEY environment variable. The application must raise an error at startup if the variable is missing and the app is not in testing mode.
Disable debug mode.
app.py — the updated application file with all security measures applied.requirements.txt — listing every Python package needed to run the hardened app.Do not add a frontend, database, or authentication layer. Focus solely on the security hardening described above.
evals
scenario-1
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
skills
flask-security-basics
verifiers