Skip to content

tarfile: Windows same-drive drive-relative symlink not caught by data filter #161323

Open

Description

@gpshead

Bug report

On Windows, a member name or link target with a drive but no root, such as C:foo, is not absolute, so the 'tar' and 'data' extraction filters let it through. Their containment check joins it onto the resolved destination, which has the same drive, so it looks contained. Extraction then joins the name onto the destination as given: with extractall("out"), os.path.join("out", "C:foo") is "C:foo", a file in the current directory of drive C:. A symlink to C:foo passes the 'data' filter the same way and is resolved against that directory too. x/../C:foo and ./C:foo become C:foo through the filter's own normalization.

This runs the filters with Windows path handling on any OS:

import ntpath, os, tarfile
os.path = ntpath
os.getcwd = lambda: r'C:\work'
for name in 'C:evil.txt', 'x/../C:evil.txt':
    member = tarfile.data_filter(tarfile.TarInfo(name), 'out')
    print(repr(name), '->', ntpath.abspath(ntpath.join('out', member.name)))
link = tarfile.TarInfo('link')
link.type = tarfile.SYMTYPE
link.linkname = './C:evil.txt'
print('symlink ->', repr(tarfile.data_filter(link, 'out').linkname))
'C:evil.txt' -> C:\work\evil.txt
'x/../C:evil.txt' -> C:\work\evil.txt
symlink -> 'C:evil.txt'

The filters should refuse these with AbsolutePathError and AbsoluteLinkError. gh-154987 is the different-drive case, where the containment check raises ValueError instead.


Reported as a security issue via GHSA by Girish Konda. Assigned CVE-2026-107784.
also later found by anthropic/oss-scanner as ANT-2026-RSL1F4AT

PR ready, reviewed, and approved via GHSA, i'll push that after opening this.

CPython versions tested on:

CPython main branch

Operating systems tested on:

Windows

Linked PRs

Activity

  1. self-assigned this
    on Nov 4, 2026
  2. added
    stdlibStandard Library Python modules in the Lib/ directory
    3.11only security fixes
    3.12only security fixes
    3.13only security fixes
    3.14bugs and security fixes
    3.15bugs and security fixes
    3.16new features, bugs and security fixes
    and removed
    type-bugAn unexpected behavior, bug, or error
    on Nov 4, 2026
  3. added 3 commits that reference this issue on Nov 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

3.11only security fixes3.12only security fixes3.13only security fixes3.14bugs and security fixes3.15bugs and security fixes3.16new features, bugs and security fixesOS-windowsstdlibStandard Library Python modules in the Lib/ directorytype-securityA security issue

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions