Skip to content

Add CodeQL variant-analysis pack: Tar Slip (PEP 706) - #14

Open
phlppgdfry wants to merge 6 commits into
mainfrom
feature/codeql-tarslip-pack
Open

phlppgdfry wants to merge 6 commits into
mainfrom
feature/codeql-tarslip-pack

Conversation

@phlppgdfry

Copy link
Copy Markdown
Owner

What

Adds a tested CodeQL pack for targeted multi-repo variant analysis of Tar Slip
(filterless tarfile extraction, CWE-022, PEP 706), plus a method writeup.

  • codeql/python/UnsafeTarExtract.ql (problem): every filterless extractall/extract on a tarfile object.
  • codeql/python/UntrustedTarExtract.ql (path-problem): extraction reachable from a remote/user-controlled source — every hit is a lead.
  • qhelp for both, MRVA-ready 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, a
filter="data" call and a non-tarfile .extractall are correctly ignored.

🤖 Generated with Claude Code

phlppgdfry and others added 2 commits December 1, 2026 07:27
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>
phlppgdfry and others added 4 commits December 1, 2026 11:56
- .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>
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.

2 participants