Summary
fastcore's untar_dir() helper can extract tar archive members outside the intended destination when given a crafted archive. If an application extracts untrusted archives using this helper on affected Python runtimes, files writable by the application may be overwritten.
Affected context
The issue concerns applications using fastcore.xtras.untar_dir() to extract tar archives. The risk arises when an attacker can supply or influence an archive that the application extracts, and extraction does not enforce safe member paths or destination containment. The described behavior applies on Python versions before 3.14.
Exploit preconditions
- Attack surface: Application functionality that extracts tar archives through
untar_dir() - Required access: Ability to provide or influence an archive that the application processes
- Trigger point: Archive extraction via the helper
- Why exploitation is possible: Archive member paths are not filtered or checked to ensure their resolved destinations remain inside the intended extraction directory
Why this happens
The extraction path passes archive data to shutil.unpack_archive() without applying a tar extraction filter, validating member paths, or checking containment. This is an improper limitation of a pathname to a restricted directory, mapped to CWE-22: Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal'). As a result, archive members may resolve outside the intended extraction location.
Potential impact
- Application files or configuration may be overwritten.
- Importable code may be replaced, which could lead to code execution when that code is later loaded.
- Data may be modified or made unavailable.
- The application or host may experience denial of service.
General mitigation guidance
Defensive patterns focus on treating archives as untrusted input and constraining extraction:
- Use extraction APIs or filters that reject unsafe archive members by default.
- Validate each member path and confirm its resolved destination remains within the intended extraction directory.
- Avoid extracting untrusted archives where possible; otherwise, extract into an isolated, restricted location.
- Run extraction with least-privilege permissions and limit which files and directories the process can write.
- Apply resource limits and validate expected archive contents before making extracted files available to the application.
How teams detect issues like this
Look for archive extraction helpers that process untrusted data without safe filters, member-path validation, or destination containment checks. Code review and static analysis can flag calls to untar_dir() and archive APIs, then verify that paths are constrained before files are written. Policy checks can require safe extraction behavior and restrict archive-processing services to least-privilege filesystem access.

