Description
Django and FastAPI debug responses can expose tracebacks, source, or configuration. Flask debug mode can expose the Werkzeug interactive debugger. Flask’s TESTING setting separately affects exception handling and extensions.
Potential impact
Detailed errors can disclose internal data to clients. An exposed interactive debugger poses a code-execution risk even when its PIN is enabled. With Flask testing enabled, exceptions propagate by default unless PROPAGATE_EXCEPTIONS is set explicitly.
Remediation
- In production, set Django
DEBUG, FlaskDEBUGandTESTING, and FastAPIdebugto the booleanFalse. Parse environment values before passing them to a boolean setting. Python treats the nonempty string"False"as true. - Keep development and test settings separate. Check effective values automatically before deploying. Run a production server with generic error responses, server-side logs, and alerts.
Examples
Django
Before
python
# settings/production.py
DEBUG = True
After
python
# settings/production.py
DEBUG = False
Flask debug mode
Before
python
from flask import Flask
app = Flask(__name__)
app.run(debug=True)
After
python
from flask import Flask
app = Flask(__name__)
app.config["DEBUG"] = False
# Run with a production WSGI server, not the Flask development server.
Flask testing mode
Before
python
from flask import Flask
app = Flask(__name__)
app.config.update(TESTING=True)
# app.testing = True enables the same setting.
After
python
from flask import Flask
app = Flask(__name__)
app.config.update(TESTING=False)
FastAPI
Before
python
from fastapi import FastAPI
app = FastAPI(debug=True)
After
python
from fastapi import FastAPI
app = FastAPI(debug=False)
References
- Flask 3.1.x: Configuration Handling —
TESTING - Flask 3.1.x: Debugging Application Errors
- Django 5.2 LTS: Deployment checklist —
DEBUG - FastAPI:
FastAPIclass —debug - OWASP: A02:2025 Security Misconfiguration
- OWASP: A05:2021 Security Misconfiguration
- CWE: CWE-489: Active Debug Code