Rules / Python
SHIELD-PY-012
Flask debug mode enabled
What it detects
Running Flask in debug mode in production exposes an interactive debugger.
How to fix
Disable debug mode in production. Use environment variables to control debug settings.
Vulnerable — Shield flags thisapp.py
from flask import Flask
app = Flask(__name__)
@app.route("/")
def index():
return "hello"
if __name__ == "__main__":
app.run(host="0.0.0.0", debug=True)
Fixed — scans cleanapp.py
import os
from flask import Flask
app = Flask(__name__)
@app.route("/")
def index():
return "hello"
if __name__ == "__main__":
app.run(debug=os.environ.get("FLASK_DEBUG") == "1")
Both snippets are verified against the shipped scanner: the vulnerable one triggers SHIELD-PY-012, the fixed one does not.