Skip to content

Add tarfile-unsafe-extraction rule (CWE-22 tarslip) - #4033

Open
rahulreddykarne wants to merge 1 commit into
semgrep:developfrom
rahulreddykarne:rahulreddykarne-patch-1
Open

Add tarfile-unsafe-extraction rule (CWE-22 tarslip)#4033
rahulreddykarne wants to merge 1 commit into
semgrep:developfrom
rahulreddykarne:rahulreddykarne-patch-1

Conversation

@rahulreddykarne

Copy link
Copy Markdown

Adds a rule detecting tar-archive extraction via extractall()/extract() with no filter= argument - the CVE-2007-4559 "tarslip" path-traversal class (CWE-22). Motivating case: CVE-2026-43637.

Validated against torchvision, keras, scikit-learn, and cornac: 1 true positive (torchvision's _extract_tar) and 0 false positives. Ignores every filter= form and all zipfile usage.

Known limitation: matches inline open→extract usage and helpers typed tarfile.TarFile; does not follow archives passed into untyped helper functions, since the open-source Semgrep taint engine is intra-function.

Adds a rule detecting tar-archive extraction via extractall()/extract() with no filter= argument - the CVE-2007-4559 "tarslip" path-traversal class (CWE-22). 
Motivating case: CVE-2026-43637.

Validated against torchvision, keras, scikit-learn, and cornac: 1 true positive (torchvision's _extract_tar) and 0 false positives. Ignores every filter= form and all zipfile usage.

Known limitation: matches inline open→extract usage and helpers typed tarfile.TarFile; does not follow archives passed into untyped helper functions, since the open-source Semgrep taint engine is intra-function.
@CLAassistant

CLAassistant commented Jul 31, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@semgrep-code-dev-returntocorp

Copy link
Copy Markdown

Semgrep found 5 tarfile-extractall-traversal findings:

Possible path traversal through tarfile.open($PATH).extractall() if the source tar is controlled by an attacker

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