Repository navigation
Add CodeQL variant-analysis pack: Tar Slip (PEP 706) - #14
Open
phlppgdfry wants to merge 6 commits into
Open
phlppgdfry wants to merge 6 commits into
phlppgdfry wants to merge 6 commits into
Conversation
Two custom Python queries for targeted multi-repo variant analysis: - UnsafeTarExtract.ql (problem): every filterless tarfile extractall/extract - UntrustedTarExtract.ql (path-problem): extraction reachable from a remote/user-controlled source — every hit is a lead Includes qhelp, an MRVA-ready qlpack.yml, a pinned lock file, and unit tests (both pass: the true positive is flagged, filter="data" is treated as safe). Documents the method in docs/codeql-variant-analysis.md: why generic suites over hardened apps fail, and why one sharp sink over a large corpus works. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Extends the variant-analysis pack with the genuinely-correct zip case and packages the scale-up step. - UnsafeZipExtract.ql (@kind path-problem): flags only hand-rolled zip extraction — a member name from namelist()/infolist()/ZipInfo.filename that flows into os.path.join()/open(), bypassing zipfile's own sanitization. extractall()/extract() are deliberately NOT sinks. - Verified empirically (Python 3.15) that stdlib zipfile.extractall()/extract() already strip '..' and absolute paths and write symlink members as plain files, so a naive "every extractall = Zip Slip" query would be almost all false positives. Documented this in the method writeup and README. - UnsafeZipExtract.qhelp + unit test (zipmanual); all 3 pack tests pass. - codeql/mrva/: runbook (VS Code MRVA + local fallback) and the 19-repo seed corpus for scaling the Tar/Zip Slip hunt over hundreds of repos. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
- .github/codeql/codeql-config.yml: paths-ignore codeql/python/tests, the deliberately-vulnerable fixtures that unit-test our own queries. GitHub's default CodeQL setup flags tests/zipmanual/test.py as py/path-injection (which actually corroborates UnsafeZipExtract.ql) — but it is test-only code. - codeql/mrva/python-archive-apps.txt: add two non-CTF/non-PoC candidates from a fresh code-search round (shellphish/artiphishell, LazyAGI/LazyCraft), marked unverified. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…gging The zipmanual fixture used request.files only to look realistic, which made GitHub's own py/path-injection see a remote source and raise a (test-only) high alert on the PR. UnsafeZipExtract.ql's source is the zip member itself (namelist()), not an HTTP request, so the Flask dependency was never needed. Rewrote the fixture to take the zip path as a parameter: the query still flags both sinks (verified, all 3 tests pass) and the default-setup alert no longer has a remote source to report. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
codeql/mrva/VSCODE-MRVA.md: full first-time setup (CodeQL extension, controller repo, target repo list from python-archive-apps.txt, running variant analysis, triage + export, costs). README links to it. Heavy compute runs on GitHub's servers; the local machine only runs the editor. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Demoting os.path.join from a sink to a taint step removes a false-positive class where a zip-member-derived path flowed into a non-write call (e.g. a delete helper using os.remove), which is not a Zip Slip. The write sink is now open(). Re-validated against a live corpus: FOSSEE/online_test 2->0 (FP gone), ha-china/hass-panel 2->1 (same real write, no longer double-counted). Tests re-learned, all three pass. Co-Authored-By: Claude Opus 4.8 <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.
What
Adds a tested CodeQL pack for targeted multi-repo variant analysis of Tar Slip
(filterless
tarfileextraction, CWE-022, PEP 706), plus a method writeup.codeql/python/UnsafeTarExtract.ql(problem): every filterlessextractall/extracton a tarfile object.codeql/python/UntrustedTarExtract.ql(path-problem): extraction reachable from a remote/user-controlled source — every hit is a lead.qlpack.yml, pinned lock file, passing unit tests.docs/codeql-variant-analysis.md: why generic suites over hardened apps fail, and why one sharp sink over a large corpus works.Why
Two earlier generic-suite hunts over ~18 hardened apps produced zero reportable findings
(all false positives against sound guards). This pack is the opposite approach: model one
sharp, syntactically-distinctive sink and run it across a large corpus.
Validation
codeql test run codeql/python/tests— both tests pass: the true positive is flagged, afilter="data"call and a non-tarfile.extractallare correctly ignored.🤖 Generated with Claude Code