Contents
On Windows, Python’s tarfile extraction filters let an archive member named C:report.txt through. If you called extractall("out", filter="data") with a relative destination, or relied on data being the default since Python 3.14, that member was written into the process’s current working directory instead of out. Symlink targets of the same shape were accepted too. CPython fixed it as CVE-2026-107784, announced on November 23.
The fix was merged on November 4. As of today it is in 3.16.0a2 and nowhere else that ships. The latest stable releases, 3.14.10 and 3.15.2, were both tagged on October 25.
Two joins, two destinations
extractall(path) calls the filter with path exactly as you passed it. The filter resolves that to an absolute path, joins the member name onto the result, and checks that the outcome is still under the destination. Then the extractor writes to os.path.join(path, tarinfo.name), joining onto the original, possibly relative, path.
On POSIX those two joins always agree, since a name either starts with / or it doesn’t. Windows has a third kind of path: a drive with no root, such as C:report.txt, which means “report.txt in the current directory of drive C”. ntpath.isabs() says it is not absolute. ntpath.join() treats it differently depending on whether the left side already names the same drive:
>>> import ntpath
>>> ntpath.join(r"C:\work\dest", "C:report.txt") # what the filter checked
'C:\\work\\dest\\report.txt'
>>> ntpath.join("dest", "C:report.txt") # what extraction wrote
'C:report.txt'
The filter saw a path inside the destination and approved it. The extractor got C:report.txt and opened it with mode "wb". With the working directory at C:\work, that is C:\work\report.txt, one level above the folder you meant to extract into. Existing files are overwritten.
ntpath behaves the same on any OS, so that output can be reproduced on Linux. CPython’s own regression test for this bug swaps os.path for ntpath in the same way.
The normalization step made it worse
There was a second ordering problem. The old filter checked os.path.isabs(name) first and normalized .. components afterwards. A name like x/../C:report.txt isn’t absolute and has no drive, so it passed the check, then normpath turned it into C:report.txt, and the filter returned that rewritten name for extraction. Link targets had the same order: ./C:report.txt passed the absolute-path check and was normalized into C:report.txt afterwards.
The fix does two things. It moves the check after normalization, and it widens it from isabs() to isabs() or splitdrive()[0], raising AbsolutePathError for names and AbsoluteLinkError for link targets. Any name with a drive is now refused, absolute or not.
Checked against an unpatched stdlib
The data_filter that ships in Python 3.11.18 has the old code. Calling it with Windows path rules and the destination C:\work\dest gives:
| Member | Stock data_filter returns |
|---|---|
file C:report.txt | accepted, name C:report.txt |
file x/../C:report.txt | accepted, name rewritten to C:report.txt |
symlink to C:report.txt | accepted |
symlink to ./C:report.txt | accepted, target rewritten to C:report.txt |
Every row is a member the filter was supposed to stop. The comparison with the extraction-side join is the part a unit test calling the filter directly won’t show you: the filter’s check is internally consistent, and its answer applies to a different path from the one that gets written.
Who is exposed
You need all three of these:
- The code runs on Windows.
- It extracts a tar archive that someone else controls, using the
dataortarfilter. That includes passing no filter on 3.14 or later, because 3.14 madedatathe default, and callingshutil.unpack_archive(), which passes through toextractall. - The destination is relative, and the archive’s drive letter matches the drive of the working directory. An attacker guessing
C:will usually be right.
An absolute destination on the same drive closes the file-name case, because then both joins see the drive and agree. If the destination is on another drive, the filter’s containment check raises ValueError (“Paths don’t have the same drive”) and extraction stops. That’s still a failure, but it doesn’t write anything. Code on 3.12 or 3.13 that never passed a filter is in a worse position: its default is fully_trusted, which checks nothing at all.
The working directory is a bad place to receive surprise files. In a CI job or a build script it’s usually the repository root, where a conftest.py gets imported by pytest and config files get read by every tool that runs next.
What to do before a release ships
The 3.14 and 3.15 branches have the fix, so the next patch releases will carry it. Backport PRs exist for 3.13, 3.12 and 3.11, but none had landed on those branches as of their latest commits, from November 16. Until you’re on a fixed version, a wrapper that applies the same rule works on every Python that has extraction filters (3.12 and later, plus the 3.8 to 3.11 security releases that received them under PEP 706):
import os
import tarfile
def strict_data_filter(member, dest_path):
if os.path.splitdrive(os.path.normpath(member.name))[0]:
raise tarfile.AbsolutePathError(member)
if (member.issym() or member.islnk()) and \
os.path.splitdrive(os.path.normpath(member.linkname))[0]:
raise tarfile.AbsoluteLinkError(member)
return tarfile.data_filter(member, dest_path)
with tarfile.open(archive) as tar:
tar.extractall(os.path.abspath(dest), filter=strict_data_filter)
Run against 3.11.18’s stdlib with Windows path rules, it raises on all four rows of the table above and leaves ordinary names like ok/report.txt and links like ok/x alone. On POSIX, splitdrive never returns a drive, so it adds nothing there.
Passing os.path.abspath(dest) is worth doing even after you upgrade. The bug only existed because the filter and the extractor were given the same string and each turned it into a path in its own way. If the destination is already absolute before either of them sees it, there’s one less place for that kind of disagreement to hide.
Sources
- oss-security: CPython CVE-2026-107784, tarfile extraction filters accept drive-relative paths on Windows
- CPython PR #161334: Refuse drive-relative paths in tarfile extraction filters
- CPython issue #161323
- Fix commit e4c751b on main
- 3.16.0a2 changelog entry
tarfileextraction filters documentation- PEP 706: Filter for tarfile.extractall