/

CVE-2025-13462

Severity:

CRITICAL RISK

(9.8)

Archive Parsing Inconsistency and Path Handling (CWE-20) in Python tarfile Module

CVE-2025-13462

Analyzed

Vulnerability type

Category:

Archive Parsing and Path Handling Vulnerability

CWE:

CWE-20, CWE-74, CWE-434

Impact:

Inconsistent Archive Interpretation and Potential File Write Redirection

Severity:

CRITICAL RISK

(9.8)

CVSS version:

3.1

Catch this CVE while code is being written

Detect vulnerable code directly in pull requests, so CVEs are fixed before merge.

Summary

The Python tarfile module normalizes certain special AREGTYPE (\x00) blocks into directory entries even while processing multi-block members like GNUTYPE_LONGNAME or GNUTYPE_LONGLINK.

A crafted tar archive can therefore be interpreted differently by tarfile than by other tar implementations, potentially enabling an attacker to control extracted paths or file mappings under specific extraction workflows.

Affected context

This vulnerability affects applications and tools that:

  • Use Python's standard tarfile module to read or extract untrusted or semi-trusted .tar archives
  • Rely on consistent behavior with other tar implementations (e.g., GNU tar, BSD tar) for validation, scanning, or pre-processing
  • Use GNUTYPE_LONGNAME / GNUTYPE_LONGLINK style multi-block members in their workflows or accept archives that may use them

The risk increases when downstream logic assumes that all consumers (security scanners, validators, and extractors) interpret tar headers identically, or when extracted paths influence where files are written or later executed.

Exploit preconditions

  • Attack surface: Tar archives provided to a Python-based service, CLI tool, or application that uses tarfile for inspection or extraction.
  • Required access: Ability to supply or influence a tar archive (e.g., file upload, API input, package or backup file).
  • Trigger point: The archive is opened and processed by tarfile (e.g., tarfile.open() followed by getmembers(), extract() or extractall()).
  • Why exploitation is possible: The module normalizes AREGTYPE blocks to directory entries even while in the middle of handling multi-block entries such as GNUTYPE_LONGNAME or GNUTYPE_LONGLINK, which can cause tarfile to produce member records (names, types, paths) that do not match how other tools interpret the same archive. Workflows that mix trust decisions from one implementation with extraction behavior from another can be subverted.

Why this happens

At its core, this is an input validation and parsing logic flaw in how the tarfile module interprets tar headers.

According to the tar format, multi-block members like GNUTYPE_LONGNAME and GNUTYPE_LONGLINK span several blocks and must be interpreted as a unit. The Python tarfile module, however, applies normalization of AREGTYPE (\x00) blocks to directory entries even while it is still logically in the middle of processing such a multi-block structure.

This maps primarily to CWE-20: Improper Input Validation, because the parser fails to strictly respect the multi-block semantics and contextual constraints of the format. Inconsistently normalized entries can then interact with:

  • CWE-74 (Improper Neutralization of Data in Output Used by a Downstream Component) when downstream systems (other tar tools, security scanners, or path-based policy engines) consume a different representation of the archive and make mismatched trust decisions.
  • CWE-434 (Unrestricted Upload of File with Dangerous Type) in scenarios where archives are used to deploy or upload files and the misinterpretation lets an attacker control which files land where, or with what names, undermining filtering or allowlist logic.

Conceptually, the insecure pattern is: parsing and normalizing complex structured input without strictly honoring the sequencing and grouping constraints of the format, leading to divergent interpretations across tools.

Potential impact

  • Crafted archives could be interpreted differently by tarfile and other tar implementations, undermining validation or scanning performed by non-Python tools.
  • An attacker may be able to influence final file paths, types, or directory structure resulting from extraction when application logic combines multiple tools or assumptions.
  • Path- or name-based security checks (e.g., denylisting certain paths, extensions, or locations) may be bypassed if they rely on a different tar implementation than the one actually extracting files.
  • Files could end up written to unexpected but writable locations within an application's working directory or data directories, potentially enabling follow-on attacks depending on how those files are used.

General mitigation guidance

Mitigation generally focuses on strict archive handling practices and defensive path management rather than format-specific tweaks alone:

  • Treat all externally supplied tar archives as untrusted input and minimize the circumstances in which they are automatically extracted.
  • Ensure that the same tool or library is used for both validation and extraction wherever possible, avoiding mixed-tool workflows that can be confused by parsing differences.
  • Implement strong path safety measures when using tarfile:
  • Normalize and validate member paths against an intended base directory before extraction.
  • Reject entries that escape the target directory via .., absolute paths, or control characters.
  • Avoid automatically honoring symbolic links or hard links from untrusted archives.
  • Enforce application-level policies around what kinds of files may be accepted and where they may be written, independent of the tar library's interpretation.
  • Run archive-processing code with the least privileges necessary, in isolated directories or sandboxes, to limit the blast radius of any misinterpretation.

How teams detect issues like this

Detection focuses on identifying risky tar-processing patterns and spotting crafted archives:

  • Static analysis and code review:
  • Search for use of the Python tarfile module, especially extract() / extractall() on untrusted inputs.
  • Flag any workflows where tar archives are validated or scanned using one tool (e.g., system tar, AV scanner) but extracted using Python tarfile, or vice versa.
  • Review logic that assumes archive metadata (paths, file types) is trustworthy or consistent across tools.
  • Policy and process checks:
  • Enforce that uploaded or externally sourced archives are processed in a controlled environment and subject to uniform validation and extraction rules.
  • Add CI checks to ensure new code does not introduce ad hoc tar parsing or extraction bypassing centralized security wrappers.
  • Runtime monitoring:
  • Log and monitor extraction paths and filenames generated from tar processing, alerting on attempts to write outside expected directories or with suspicious names.
  • Use file integrity or configuration management tooling to detect unexpected files created by archive-processing services.

Automated code scanning tools can assist by flagging uses of tarfile with untrusted data and highlighting missing path validation or inconsistent validation/extraction toolchains.

Sources

SourceLink
github.comgithub.com/python/cpython/commit/42d754e34c06e57ad6b8e7f92f32af679912d8ab
github.comgithub.com/python/cpython/commit/72dde1016493c52abe857fc4a7bf6c40138b4114
github.comgithub.com/python/cpython/commit/7ad3093d76a748af55bdb1d2e8aad3638163b017
github.comgithub.com/python/cpython/commit/9a23b753552afa28e3a2f4d8863572fc66479406
github.comgithub.com/python/cpython/commit/ae99fe3a33b43e303a05f012815cef60b611a9c7
github.comgithub.com/python/cpython/commit/d10950739a78f54d0718d88fb5a868374603c084
github.comgithub.com/python/cpython/issues/141707
github.comgithub.com/python/cpython/pull/143934
mail.python.orgmail.python.org/archives/list/security-announce@python.org/thread/EOMI5I66ZMKQ2INNFT6T7IAIKUGPZYIE/

Frequently asked

questions

It can be, if a remote attacker can supply a crafted tar archive to an application that uses tarfile to process or extract its contents. The actual impact depends on how the application uses the parsed results and where files are written.

The attacker needs the ability to influence or provide archive content—typically via an upload endpoint, API that ingests backups or packages, or any automated process that downloads and processes tar files from remote sources.

Apply strict input validation and path safety when handling tar archives, ensure that the same implementation is used for both validation and extraction, and confine extraction to dedicated, locked-down directories with strong path normalization and rejection rules.

When working with complex formats, use well-specified parsing routines, respect multi-block or multi-part semantics, avoid mixing multiple implementations for different stages of processing, and layer defenses such as sandboxing, least privilege, and robust path and type validation around all archive-handling code.

Find out what's already
exploitable in your codebase.