Skip to content

Hub: Flask path-traversal taint rule covers pathlib and shutil, send_from_directory only on its base dir - #2384

Merged
remigiusz-antczak merged 4 commits into
mainfrom
feat/hub-pathtrav-taint
Nov 15, 2026
Merged

remigiusz-antczak merged 4 commits into
mainfrom
feat/hub-pathtrav-taint

Conversation

@remigiusz-antczak

Copy link
Copy Markdown
Collaborator

perun.py.path-traversal fired on send_from_directory(base, name), which confines the name to its base directory, so the bench's CWE-22 clean twin matched the same rule as the vulnerable seed and the seed did not count as a hit. send_from_directory is now a sink only on its base-dir argument. New sinks: pathlib.Path(...).open/read_text/read_bytes/write_text/write_bytes/unlink, shutil.copy/copy2/copyfile/move (source and destination), copytree and rmtree. safe_join and werkzeug secure_filename are sanitizers (matched by name). The allowlist-guard skip now also covers the new sinks. Annotated ruleid/ok fixtures live in scripts/test_semgrep_py_pathtrav.py, wired via scripts/ci-tests.d/semgrep-py-pathtrav.sh.

Tests: 4/4 (test_semgrep_py_pathtrav live and offline pins, semgrep-taint, test_semgrep_defaults 17 bad / 0 clean, test_semgrep_injection)

🤖 Generated with Claude Code

remigiusz-antczak and others added 4 commits November 15, 2026 16:50
…is safe

perun.py.path-traversal now treats pathlib.Path(...).open/read_text/read_bytes and
shutil.copy/copy2/copyfile/move as sinks, accepts safe_join and the qualified
werkzeug secure_filename as sanitizers, and drops send_from_directory as a sink
(it confines the name to its base directory, so it was a false positive).
New annotated ruleid/ok fixtures in scripts/test_semgrep_py_pathtrav.py, wired via
scripts/ci-tests.d/semgrep-py-pathtrav.sh; the test fails against the previous rules.

Tests: 4/4 (py_pathtrav live 24 annotated cases, ci-tests-d-masking, semgrep-taint, semgrep-py-pathtrav vs old rules fails as expected). semgrep-defaults.sh errors with a JSON decode failure in this sandbox; not isolated as pre-existing.
No-Mechanism-Reason: n/a, commit touches scripts/test_semgrep_py_pathtrav.py

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…kips; tainted base dir for send_from_directory

send_from_directory is a sink on its base-directory argument only. Added shutil copy/move dst, copytree, rmtree and Path write_text/write_bytes/unlink sinks, extended the allowlist-guard skip to the pathlib/shutil/send_from_directory sinks, and noted that sanitizers match by name. Offline pin now checks the sink pattern, not a raw substring. Fixtures cover both send_from_directory shapes, the new sinks and guarded variants.

Tests: 4/4 (test_semgrep_py_pathtrav live, semgrep-taint, test_semgrep_defaults and test_semgrep_injection with HOME set to a temp dir)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@remigiusz-antczak
remigiusz-antczak merged commit 44a8d9c into main Nov 15, 2026
13 checks passed
@remigiusz-antczak
remigiusz-antczak deleted the feat/hub-pathtrav-taint branch November 15, 2026 17:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant