Repository navigation
Hub: Flask and Django multi-value request inputs are now taint sources - #2388
Merged
Merged
Conversation
The Python taint rules read request.args[...] and request.args.get(...) as sources but not request.args.getlist(...), so a Flask or Django multi-value read (args, form, values, GET, POST) reaching a sink was missed. Every rule that lists the request.$A.get(...) source now also lists request.$A.getlist(...). perun.py.unsafe-api-consumption reported the chained `requests.get(URL).text` for any non-literal URL: the response source expression contains the URL sink, so the call counted as its own source. A sink argument that is an ALL_CAPS constant name is now skipped, as the existing literal-URL skip already did. A tainted URL in the same chained form still reports. Known limit: a lowercase local assigned a literal is still reported in the chained form. Checked against bench/tool-only: all nine vuln hits are unchanged and the clean twins stay silent for the perun rules. Tests: 3/3 (test_semgrep_py_guards with getlist, constant-URL chained ok and response-derived chained ruleid cases, test_semgrep_py_pathtrav, test_semgrep_defaults) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The perun.py.unsafe-api-consumption sink regexes skipped any argument named like an ALL_CAPS constant. A name says nothing about where the value came from, so a response-derived ALL_CAPS variable or module global reached the sink with no finding (for example a callback URL or query string read from an API response and bound to a constant-style name). Only an inline http(s) string literal is skipped now. Known limit: a chained requests.get(CONSTANT_URL).text or .json() on a constant URL reports again, because the sink counts as its own source. A false positive is cheaper than a bypass. The fully qualified flask.request.$A.getlist(...) form is now a source wherever flask.request.$A.get(...) is. Tests: 3/3 (test_semgrep_py_guards with response-derived ALL_CAPS url, sql and global probes plus flask.request getlist, test_semgrep_py_pathtrav, test_semgrep_defaults). Bench: vuln hits unchanged, clean silent for perun rules, MAX_FALSE_POSITIVES unchanged. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
test_semgrep_injection pinned the exact source list of the git-argument-injection rule; it now includes the request.$A.getlist and flask.request.$A.getlist sources, still an exact match. test_semgrep_taint expected no finding on a requests.get("https://" + h) behind an `in` allowlist guard, but the ssrf rule no longer honors that bypassable guard, so line 13 is an expected finding now.
Tests: 13/13 scripts/test_semgrep_*.py pass offline
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
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.
Python taint rules missed attacker input read through multi-value accessors. request.args.getlist(...), request.form.getlist(...), request.GET.getlist(...), request.POST.getlist(...) and the fully qualified flask.request.$A.getlist(...) are now sources at every site where the single-value accessors already were.
An intermediate commit skipped sink arguments named in ALL_CAPS to silence a false positive on a constant URL. The independent review showed that the skip was bypassable: a response-derived value stored in an ALL_CAPS name (a callback URL, a SQL string, a module global) reached requests or cursor.execute with no finding. The skip is removed, and those three probes plus the flask getlist form are ruleid cases in scripts/test_semgrep_py_guards.py. Known limit (a false positive, accepted over a bypass): a chained requests.get(CONST).text or .json() with a constant-variable URL still reports.
Tests: 3/3 (test_semgrep_py_guards, test_semgrep_py_pathtrav, test_semgrep_defaults). Bench: vuln hits unchanged, clean twins silent for perun rules, MAX_FALSE_POSITIVES unchanged.
🤖 Generated with Claude Code