The Werkzeug debugger
Running with debug=True enables an interactive debugger that executes arbitrary Python from the browser. It is protected by a PIN, but the Flask and Werkzeug documentation both say it must never be enabled in production and that the PIN should not be relied on. Public exploits exist for exposed consoles, and the PIN can sometimes be derived when a file-read bug exists elsewhere in the app. A tester looks for /console and for tracebacks with the debugger UI.
Template injection and other injection
- render_template_string with user input concatenated in gives server-side template injection, which in Jinja2 usually leads to code execution.
- Raw SQL via db.engine.execute or cursor.execute with f-strings bypasses SQLAlchemy's parameterisation.
- send_file or send_from_directory with user-controlled paths can lead to path traversal if not constrained.
- Pickle or yaml.load on request data leads to deserialisation attacks.
Sessions and authentication
- Flask's default session is a signed, not encrypted, cookie. Anyone can read its contents, and a weak SECRET_KEY lets an attacker forge it, for example setting is_admin.
- Flask-Login's @login_required checks that a user is logged in, not that they own the object in the URL.
- Without Flask-WTF or equivalent, state-changing forms have no CSRF protection.
Running Pentest-Swarm against a Flask app
Pentest-Swarm tests the running Flask service from outside, so it sees exactly what an attacker would see on your staging host.
- The owasp-top10 playbook covers injection, template injection and path traversal classes on discovered routes.
- Pass a logged-in session cookie with
--cookieto reach routes behind @login_required. - Template injection and command injection findings can be confirmed with out-of-band callbacks when you run with
--verify. - Findings come with evidence, severity and CVSS, plus a sandboxed Python proof of concept where one can be generated.
Where it falls short
From outside, a tester can confirm that a forged session works but cannot tell you what your SECRET_KEY is or where render_template_string is called. Bandit and similar SAST tools flag debug=True, render_template_string and unsafe deserialisation in code, and complement a black-box run well.
Questions
Is the Werkzeug debugger PIN enough to run debug mode in production?
No. The Werkzeug docs describe the PIN as a helper, not a security boundary. Debug mode belongs on developer machines only.
Can someone read my Flask session cookie?
Yes. The default session is base64-encoded and signed, not encrypted. Do not store secrets in it, and use a long random SECRET_KEY so it cannot be forged.
How is Flask testing different from Django testing?
Django ships more protections by default (CSRF, admin, ORM). Flask apps vary more, so testers check basics like CSRF and session signing that Django handles out of the box.