Skip to main content

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
Wrong result? Report itA false positive, a missed case or a confusing message: it goes privately to the founder.

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

run.py · PythonReported on line 6
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

run.py · Python
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

chat.py · PythonReported on line 14
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

nightly.py · Python
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

  1. Runs with --danger on Python files. Looks only at .run() calls that pass the keyword debug with the literal value True.
  2. Reports HIGH when the receiver is proven to be a flask.Flask object, for example app = Flask(__name__) in the same file.
  3. Otherwise also reports, outside test files, when the receiver is named app, application or flask_app, is socketio (or a SocketIO object), or is the result of Flask(), create_app(), make_app(), build_app(), get_app(), Dash() or APIFlask().
  4. uvicorn.run(app, debug=True), hypercorn and other objects with a .run() method are not reported. Test files are test_*.py, *_test.py, conftest.py and files under test/ or tests/.

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.

run.py · Python · the fix, against the flagged file
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=DEBUG from a settings constant, app.debug = True, app.config["DEBUG"] = True and debug mode set through the FLASK_DEBUG environment 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 --baseline accept the current calls and report only new ones.

From the Skylos rule handbook, Skylos 5.8.0 (commit 5b880b0). All rules.