When Path Filters Meet Hard Links to Symlinks in CPython
Walking through CVE-2026-82049 in CPython's tarfile module, from archive link representation to os.link() behavior on symlinks.
- Record
- CVE-2026-82049
- Severity
- CVSS 8.4 High
- Weakness
- CWE-59
- Affected
- CPython < 3.14.0b1
Python 3.12 introduced PEP 706 extraction filters to tarfile so applications could unpack untrusted archives without writing or exposing files outside the destination directory. While auditing how tarfile handles chained link entries on Linux, I found a way past those filters using a two-entry sequence: a symbolic link followed by a hard link pointing at that symbolic link.
Every path in the archive stays within the target directory during filter validation, so the archive passes inspection cleanly. At extraction time, however, os.link() duplicates the symlink inode itself, leaving an active symlink inside the extracted tree that points outside the extraction root. Subsequent metadata updates and downstream file reads then follow that symlink to the external target. The bug is tracked as CVE-2026-82049 and affects CPython 3.13 and earlier releases prior to 3.14.0b1.
What PEP 706 extraction filters validate
Historically, Python's tarfile.extractall() trusted archive metadata verbatim, meaning an archive member named ../../../../etc/cron.d/job or /etc/passwd would write directly to that path if permissions allowed. PEP 706 addressed this by adding filter policies that inspect and sanitize each TarInfo object before anything touches disk.
The built-in tar filter strips leading slashes and rejects relative paths that traverse above the destination root. The stricter data filter, intended for untrusted archives, also blocks special device nodes, strips high permission bits, and validates link targets so that symbolic links and hard links resolve within the destination subtree. I tested this behavior against CPython 3.13.15 on Linux.
Symlinks and hard links in tar archives
On POSIX filesystems, symbolic links and hard links behave differently at the inode layer. A symbolic link has its own inode storing a target path string, which the kernel resolves dynamically whenever a syscall dereferences the path. A hard link is a directory entry that binds a new filename directly to an existing inode in the same filesystem.
The tar format uses the same header field, linkname, for both entry types, distinguishing them via the typeflag (SYMTYPE vs LNKTYPE). When tarfile unpacks a symbolic link, member.linkname is the path string to store inside the new symlink. When it unpacks a hard link, member.linkname refers to a previously extracted member inside the archive that the new entry should share an inode with. The interesting interaction occurs when a LNKTYPE member names a SYMTYPE member as its target.
report and copy are two names for one inode.How validation and extraction diverged
Suppose an archive contains two entries extracted into /tmp/dest. The first entry, link_target, is a symbolic link pointing to /outside/sensitive_file (or a relative traversal that resolves outside the root). The second entry, link_entry, is a hard link whose linkname is link_target.
When the filter inspects link_entry, it checks how the hard link's source and destination paths relate to /tmp/dest. Because member.name is link_entry and member.linkname is link_target, both paths sit directly inside /tmp/dest.
01# Conceptual validation02source = dest / member.linkname # /tmp/dest/link_target03target = dest / member.name # /tmp/dest/link_entry04assert source.is_relative_to(dest)05assert target.is_relative_to(dest)Once link_entry passes filter checks, tarfile calls os.link(source, target) to create the hard link on disk. By default on Linux, link(2) (and linkat(2) without AT_SYMLINK_FOLLOW) does not dereference oldpath if it is a symbolic link. Instead, it creates a second directory entry bound to the symlink inode itself. On disk, /tmp/dest/link_entry becomes a symbolic link pointing to /outside/sensitive_file.
/tmp/dest. 2 os.link() does not follow the symlink, so link_entry becomes a second name for the symlink object itself. 3 Metadata restoration on link_entry follows that symlink out of the tree and changes the permissions and timestamps of /outside/sensitive_file.Reaching the external file
Immediately after creating a filesystem entry, tarfile applies the member's stored metadata, including permissions and timestamps. Unlike os.link(), the metadata restoration calls (chmod() and utime()) follow symbolic links unless follow_symlinks=False is explicitly supported and used. When tarfile applies mode bits and timestamps to link_entry, the kernel dereferences the symlink and modifies /outside/sensitive_file.
Beyond metadata modification during extraction, the unpacked directory now contains a live symbolic link to /outside/sensitive_file under an ordinary-looking filename. Any application that unpacks an archive with a filter and then serves, indexes, or packages the extracted files will read the external file whenever it opens link_entry.
Impact and scoring
The advisory classifies CVE-2026-82049 under CWE-59 (Improper Link Resolution Before File Access) with a CVSS v4.0 score of 8.4 High (CVSS:4.0/AV:L/AC:L/AT:N/PR:N/UI:P/VC:H/VI:H/VA:N/SC:N/SI:N/SA:N).
- Integrity (High): extracting a crafted archive can alter permissions (
chmod) and timestamps (utime) on arbitrary files outside the extraction directory accessible to the running process. - Confidentiality (High): the extracted directory retains a symlink to the external file, allowing applications that read or serve the unpacked tree to disclose its contents.
- Availability (None): the primitive preserves the contents of the external file and does not delete or truncate it.
How commit b38be2e fixes the mismatch
In a tar archive, a hard-link entry means 'make this path share the underlying file object of that earlier archive member.' The filter validates that relationship under the assumption that the hard link resolves to the target file. The bug existed because os.link() stopped at the symlink inode instead of resolving through it.
CPython issue #157190 tracks the vulnerability, with the fix landing in PR #157191 and backports in PR #157192. Commit b38be2e, titled Follow symlinks when extracting tarfile hard links, updates hard-link extraction so os.link() resolves symbolic links when creating the link. With that change, both the extraction filter and the filesystem call resolve to the same target object.
link_target points to, while os.link() copied the symlink entry itself. After commit b38be2e, hard-link extraction follows the symlink, so both steps resolve the same object.Takeaways for archive extractors
Path-filtering code often treats validation as a string-normalization problem: strip leading slashes, collapse .. segments, and check prefixes. As soon as an archive format supports both symbolic links and hard links, string prefixes alone stop describing what the kernel will touch.
POSIX syscalls also differ in how they treat symlinks by default: open(), chmod(), and utime() dereference the final path component, while link() and unlink() operate on the link entry itself unless told otherwise. When a sandbox or extraction filter validates a link target using one resolution rule and executes the operation using another, chained links can slip through the gap.
Timeline and credits
- 8 September 2026: Reported to the Python Security Response Team and tracked in CPython issue #157190.
- 10 September 2026: Fix merged into main and maintained CPython branches.
- 14 September 2026: PSF security advisory and CVE-2026-82049 published.
Reported by Jing Qian (Civitasmass). Coordinated by Stan Ulbrych and reviewed by Petr Viktorin.