Skip to content

Prevent path traversal (tar slip) in untar_dir/_unpack (CVE-2026-65320) - #973

Open
rahulreddykarne wants to merge 1 commit into
AnswerDotAI:mainfrom
rahulreddykarne:fix-untar_dir-tarslip
Open

rahulreddykarne wants to merge 1 commit into
AnswerDotAI:mainfrom
rahulreddykarne:fix-untar_dir-tarslip

Conversation

@rahulreddykarne

Copy link
Copy Markdown

_unpack() extracts tar archives via shutil.unpack_archive() with no filter
or member validation, so a crafted tar with ../ members can write files
OUTSIDE the intended dest (arbitrary file write → code execution if an
extracted file is later imported/loaded).

Fix: route tar extraction through tarfile with filter='data' (Python 3.12+ /
3.11.4+), with a manual containment + symlink/hardlink check fallback for
older 3.11.x. Zip/other formats keep using shutil (stdlib already strips '..').
Adds a notebook regression test. Built with nbdev (edited nbs/03_xtras.ipynb,
regenerated fastcore/xtras.py).

_unpack() delegated tar extraction to shutil.unpack_archive() with no
extraction filter or member validation, so a crafted tar with '../' members
could write files outside the intended destination directory (arbitrary file
write). Route tar extraction through tarfile with filter='data' (Python
3.12+/3.11.4+), with a manual member-containment and symlink/hardlink check as
a fallback for older 3.11.x. Zip and other formats continue via shutil
(stdlib already sanitizes '..'). Adds a notebook regression test.

This branch has not been deployed

No deployments
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