Repository navigation
Conversation
Six checks, and the first one is the most dangerous default this repository has catalogued. Flask's debug mode serves an interactive debugger on any unhandled exception, and that debugger executes Python typed into the page. Reachable from the internet it is remote code execution as the application user, behind a pin derived from information the same page leaks. Beside it, a committed or placeholder secret key lets anyone mint a session for any user, including an administrator, without touching the database. Both are critical and both are one line. The rest: a production server rather than the built-in one, which is single-threaded and documented as unsuitable, session cookies restricted to HTTPS and to the server, forwarded headers handled behind a proxy, and a bound on request bodies. Each command was run against an application that gets all six wrong and one that gets them right. The production-server check uses the quote-tolerant pattern learned from FastAPI, so it catches the Dockerfile exec form as well as the shell form.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Tier 2, item 1.
universal → python → web → python.flask, 6 new checks.The debug one deserves its own paragraph
python.flask.debug-offis the most dangerous default catalogued here so far.Flask's debug mode serves an interactive debugger on any unhandled exception,
and that debugger executes Python typed into the page. Reachable from the
internet, it is remote code execution as the application user — behind a pin
derived from information the same page leaks.
It is also two characters to enable and easy to leave on, which is why the check
looks in the code, the environment, the Dockerfile and the compose files rather
than just one of them.
Next to it,
secret-key-strong-and-external: a committed or placeholder keylets anyone mint a session for any user, including an administrator, without
touching the database. Both critical, both one line.
The rest
Production server rather than the built-in one (single-threaded, documented as
unsuitable), session cookies restricted to HTTPS and to the server, forwarded
headers behind a proxy, request bodies bounded.
Verification
Run against an application that gets all six wrong —
app.run(debug=True),SECRET_KEY = "dev",FLASK_DEBUG=1,CMD ["flask", "run"], no cookie flags,no ProxyFix, no size limit — and against one that gets them all right. Both
directions confirmed.
The production-server check uses the quote-tolerant pattern learned from the
FastAPI PR, so it catches
CMD ["flask", "run"]as well as the shell form. Thattrap would otherwise have repeated here verbatim.