Repository navigation
Hub: Flask path-traversal taint rule covers pathlib and shutil, send_from_directory only on its base dir - #2384
Merged
Merged
Conversation
…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>
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.
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