Skip to content

gh-160297: Fix tarfile setting attributes through a hard link fallback - #160298

Open
gpshead wants to merge 2 commits into
python:mainfrom
gpshead:scanfix-tarfile-y0h1y0er
Open

gpshead wants to merge 2 commits into
python:mainfrom
gpshead:scanfix-tarfile-y0h1y0er

Conversation

@gpshead

@gpshead gpshead commented Oct 22, 2026 •

Copy link
Copy Markdown
Member

When a hard link member's target is missing, makelink_with_filter() extracts a copy of the referenced member instead. If that member is a symlink, _extract_member() went on to apply the hard link's owner, mode and mtime with calls that follow the symlink, so they could land on a file outside the destination with the 'tar' and 'fully_trusted' filters. Attribute setting is now skipped when a hard link member ended up as a symlink; the nested extraction has already applied the symlink member's own attributes without following it. A hard link extracted as a copy of a regular file still gets the hard link's attributes, as before.

Fixes #160297

ANT-2026-Y0H1Y0ER

…allback

When a hard link member is extracted as a copy of a symlink member, do
not apply the hard link's owner, mode and mtime to the symlink's target.

ANT-2026-Y0H1Y0ER
@gpshead gpshead added needs backport to 3.11 only security fixes needs backport to 3.12 only security fixes needs backport to 3.13 only security fixes needs backport to 3.14 bugs and security fixes needs backport to 3.15 bugs and security fixes labels Oct 22, 2026
@gpshead gpshead self-assigned this Oct 22, 2026
@gpshead
gpshead requested a review from JelleZijlstra October 22, 2026 18:34
@gpshead
gpshead marked this pull request as ready for review October 22, 2026 18:35
@gpshead
gpshead requested a review from ethanfurman as a code owner October 22, 2026 18:35
@gpshead gpshead added the sprint label Oct 23, 2026
@github-project-automation github-project-automation Bot moved this to Todo in Sprint Oct 23, 2026
@gpshead gpshead moved this from Todo to In Progress in Sprint Oct 25, 2026
@gpshead gpshead removed the sprint label Oct 25, 2026
@gpshead gpshead removed this from Sprint Oct 25, 2026

@StanFromIreland StanFromIreland left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, properly reviewing this now I don't think this is a type-security issue (more so a correctness issue). As documented, tarfile.tar_filter:

This filter does not check link targets (TarInfo.linkname). It allows benign cases (like links to /dev/null), but it also allows links (symbolic and hard) to arbitrary files on the filesystem, potentially granting unintended access to these files.

Because of that, a single hard link member with linkname ../flag already creates a hard link to the outside file and applies the member's mode, mtime and owner to it. The PR's two-member fallback route reaches nothing the filter does not already permit directly. The data filter, which is the documented to refuse to extract links (hard or soft) that link to absolute paths, or ones that link outside the destination, already rejects this fallback with LinkFallbackError, and fully_trusted is trusted by definition, so no documented security boundary is crossed under any built-in filter.

@bedevere-app

bedevere-app Bot commented Oct 25, 2026

Copy link
Copy Markdown

When you're done making the requested changes, leave the comment: I have made the requested changes; please review again.

@gpshead

gpshead commented Oct 25, 2026

Copy link
Copy Markdown
Member Author

Sorry, properly reviewing this now I don't think this is a type-security issue (more so a correctness issue).

FWIW - agreed, this felt borderline given it required specific less-strict filters. if agreed, do we keep the cve assignment or undo that one?

i'm happy to move the news entry to Library, remove the cve ref, and reduce the level of backporting.

@gpshead gpshead added type-bug An unexpected behavior, bug, or error and removed needs backport to 3.11 only security fixes needs backport to 3.12 only security fixes needs backport to 3.13 only security fixes labels Oct 25, 2026
@StanFromIreland

Copy link
Copy Markdown
Member

'm happy to move the news entry to Library, remove the cve ref, and reduce the level of backporting.

Sounds good to me, as for the CVE, closing the GHSA will tidy up the CVE. Sorry for the trouble!

@gpshead
gpshead force-pushed the scanfix-tarfile-y0h1y0er branch from b91deed to 7304f21 Compare October 25, 2026 23:36
@gpshead

gpshead commented Oct 25, 2026

Copy link
Copy Markdown
Member Author

I have made the requested changes; please review again.

@bedevere-app

bedevere-app Bot commented Oct 25, 2026

Copy link
Copy Markdown

Thanks for making the requested changes!

@StanFromIreland: please review the changes made to this pull request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting change review needs backport to 3.14 bugs and security fixes needs backport to 3.15 bugs and security fixes type-bug An unexpected behavior, bug, or error

Projects

None yet

Development

Successfully merging this pull request may close these issues.

tarfile applies a hard link member's attributes through a symlink extracted in its place

2 participants