SKY-D346 · Security in code
Flask app started in debug mode
app.run(debug=True) starts Flask's development server with the Werkzeug debugger switched on. When a request fails, that debugger shows a page with a Python console in the browser. SKY-D346 reports run(debug=True) on a Flask app or a Flask-SocketIO server.
- Languages
- Python
- Quality gate
- counted toward the gate limits (full and diff scans)
- Finding type
- review
- Catalog name
- Flask debug mode enabled
Why it matters
The debugger console runs any Python code typed into it, with the rights of the server process. If the server is reachable, often because it also listens on 0.0.0.0, one error page is enough for a visitor to read files, steal secrets or take over the machine. The PIN that guards the console can be worked out from information the server leaks.
What Skylos flags
from shop import create_app app = create_app() if __name__ == "__main__": app.run(host="0.0.0.0", port=5000, debug=True)What Skylos leaves alone
import os from shop import create_app app = create_app() if __name__ == "__main__": debug = os.environ.get("FLASK_DEBUG") == "1" app.run(host="127.0.0.1", port=5000, debug=debug)Why Skylos leaves it alone
debug is a variable read from the environment, not the literal True, so debug mode is off unless a developer turns it on locally. The rule only reports debug=True written in the call.
More languages
Python
Flagged
from flask import Flaskfrom flask_socketio import SocketIO app = Flask(__name__)socketio = SocketIO(app) @socketio.on("message")def relay(message): socketio.emit("message", message) if __name__ == "__main__": socketio.run(app, host="0.0.0.0", port=5000, debug=True)Not flagged
from etl import Pipeline, steps pipeline = Pipeline([steps.extract, steps.clean, steps.load]) if __name__ == "__main__": pipeline.run(debug=True)Why Skylos leaves it alone
Flask-SocketIO serves the app through Werkzeug too, so socketio.run(..., debug=True) is reported. pipeline.run(debug=True) has the same shape, but pipeline is neither a Flask app nor named like one, so it is left alone.
How Skylos decides
- Runs with
--dangeron Python files. Looks only at.run()calls that pass the keyworddebugwith the literal valueTrue. - Reports HIGH when the receiver is proven to be a
flask.Flaskobject, for exampleapp = Flask(__name__)in the same file. - Otherwise also reports, outside test files, when the receiver is named
app,applicationorflask_app, issocketio(or aSocketIOobject), or is the result ofFlask(),create_app(),make_app(),build_app(),get_app(),Dash()orAPIFlask(). uvicorn.run(app, debug=True),hypercornand other objects with a.run()method are not reported. Test files aretest_*.py,*_test.py,conftest.pyand files undertest/ortests/.
How to fix it
Never hard-code debug=True. Turn debug mode on only on your own machine, through FLASK_DEBUG=1 or flask run --debug, and keep the development server on 127.0.0.1. In production, run the app under a real WSGI server such as gunicorn, which has no debugger.
Added: import osAdded: from shop import create_app app = create_app() if __name__ == "__main__":Removed: app.run(host="0.0.0.0", port=5000, debug=True)Added: debug = os.environ.get("FLASK_DEBUG") == "1"Added: app.run(host="127.0.0.1", port=5000, debug=debug)When it can be wrong
- A local-only script that is never deployed, such as a demo launcher in the repository root, is still reported.
- Missed:
debug=DEBUGfrom a settings constant,app.debug = True,app.config["DEBUG"] = Trueand debug mode set through theFLASK_DEBUGenvironment variable on a server.
Seeing a case that isn't listed here? Report the wrong result so the rule can be fixed. Don't paste company code: describe the shape of it.
How to silence it
Mark the
run()line and say why it never reaches a shared server.Python app.run(debug=True) # skylos: ignore[SKY-D346] local demo script, never deployed[tool.skylos] ignore = ["SKY-D346"]turns the rule off for the whole project.skylos baseline .and then--baselineaccept the current calls and report only new ones.