Proposal: Detecting Flask file-serving API misuse
Nobody has claimed this yet.
- #1459 by @Varshith-Kali — closed without merging
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 67/100
Research direction
Start by reviewing Bandit's existing Flask and API-misuse plugins, especially B201 and B202, then compare the attached flask-secure-static-file.zip prototype with those patterns. Done means a narrow plugin recognizes direct request.args.get(), request.form.get(), or request.values.get() use in send_file(), plus the described simple local assignment case.
Written by the indexing model from the issue text.
Description
Is your feature request related to a problem? Please describe.
Yes. I'm using Bandit on Flask code and ran into a gap around send_file().
Bandit already has targeted plugins for specific risky APIs and framework misuse, for example B201 for Flask debug mode and B202 for unsafe tarfile.extractall(). But there does not seem to be a similar plugin for a very common Flask pattern: passing a request-controlled path into send_file().
A real example is CVE-2025-6166 in Agent-Zero:
path = input.get("path", request.args.get("path", ""))
if not path:
raise ValueError("No path provided")
return send_file(path)
This ended up as a false negative in my Bandit baseline run, even though it is a straightforward arbitrary file read / path traversal case.
Similar Flask send_file traversal cases also exist in:
CVE-2022-31583CVE-2022-31549CVE-2022-31506
Describe the solution you'd like
I'd like a small Flask-specific plugin that warns when send_file() is called with a path taken directly from common request accessors such as:
request.args.get(...)request.form.get(...)request.values.get(...)
A minimal first version could stay narrow and only cover:
- direct use inside the call, or
- a simple local assignment right before the call
For example:
return send_file(request.args.get("path"))
or
path = request.args.get("path")
return send_file(path)
This feels similar in spirit to other Bandit plugins that target one dangerous API pattern without trying to do full taint tracking.
Describe alternatives you've considered
I first looked for an existing Bandit plugin that could be extended, but I couldn't find one that was close enough. B202 is the nearest match conceptually because it covers a path-traversal-style misuse of a specific API, but it is limited to archive extraction.
I also considered asking for a more general request-to-file-path plugin, but that seems broader than Bandit's scope. A narrow send_file() plugin looks like the smallest useful change.
Additional context
I implemented a plugin prototype according to one of CodeQL's rules for Flask, which could be used as a reference. It worked well on my project, and could detect CVE-2025-6166 and CVE-2022-31549 with no FPs on fixed commits.
Love this idea? Give it a 👍. We prioritize fulfilling features with the most 👍.
- Dominant language
- Python
- Stars
- 8.4k
- Forks
- 893
- Avg merge
- 6h 52m
- Merged PRs (30d)
- 3
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from PyCQA/bandit
-
Difficulty 1/5 1-3 hours Newbie friendliness 85/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
-
Turn off progress bar in CIPossibly taken @silvatechf claimed this 28 days ago. Openenhancement
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
-
Difficulty 1/5 1-3 hours Newbie friendliness 88/100
-
`bandit -ii -ll -ii -ll` raises an `IndexError`Possibly taken @botbikamordehai2-sketch claimed this 181 days ago. Openbug
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
Similar issues
-
bug
Difficulty 1/5 Under an hour Newbie friendliness 85/100
NatLabRockies/openstudio-mcp#286 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
intersystems/ipm#1338 ·
Maintainers usually reply within 1 day
-
separate_packages splits imports from the same explicitly configured packagePossibly taken @rahul05ranjan claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Maintainers usually reply within 2 days
-
The v0-through-v1 path derives ShutdownDuration its own way, silently overriding a user's definitionOpenv1
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
Maintainers usually reply within 1 day