Skip to content

fix(sdist): reject symlink path traversal and members under symlinked paths - #1303

Draft
Abdur-Rafay-AR wants to merge 2 commits into
pypa:mainfrom
Abdur-Rafay-AR:fix/1265-sdist-symlink-traversal
Draft

Abdur-Rafay-AR wants to merge 2 commits into
pypa:mainfrom
Abdur-Rafay-AR:fix/1265-sdist-symlink-traversal

Conversation

@Abdur-Rafay-AR

Copy link
Copy Markdown

Why I decided to contribute

Passionate Python developer interested in packaging security and improving build tooling reliability across the PyPA ecosystem.

Description

Fixes #1265.

In _prepare_sdist_archive():

  1. Rejects archive members whose parent path was introduced as a symlink member in the archive, preventing symlink directory traversal attacks where files are written outside the extraction root through symlink chains.
  2. Rejects invalid symlinks with linkname in ('.', './').
  3. In archive.extractall, switches filter='fully_trusted' back to filter='data' to ensure stdlib dynamic runtime filtering remains active during extraction.

Added regression test test_extract_sdist_rejects_symlink_chaining in tests/test_main.py.

Changelog

  • Added changelog fragment: docs/changelog/1265.bugfix.rst

Checklist

  • I looked at the contributing guide (docs/development/contributing.rst)
  • I made sure this was not a duplicate PR
  • Tests pass locally (tests/test_main.py - 133 passed)
  • The PR description is concise and focused

… paths

Fixes pypa#1265

Signed-off-by: Abdur-Rafay-AR <abdurrafay.tech@gmail.com>
Signed-off-by: Abdur-Rafay-AR <abdurrafay.tech@gmail.com>
@Abdur-Rafay-AR
Abdur-Rafay-AR marked this pull request as draft November 20, 2026 06:14
@Abdur-Rafay-AR

Copy link
Copy Markdown
Author

I realized I jumped ahead of the open design discussion on #1265 here — converting this to draft while you and @henryiii discuss whether to address this behavior and whether rejecting parent symlinks is too strict. Happy to wait for consensus on the direction before this goes any further, or to rework/close it once you've landed on an approach.

@henryiii

Copy link
Copy Markdown
Contributor

I think we should do the things I mentioned on the issue:

  • A test needs to check a path longer than PATH_MAX, this is the one that allows the chain to validate on older Pythons. It has to go over the max only on the last link (see CVE-2025-4517 for info).
  • We only need the extra step if os.path.ALLOW_MISSING is missing. We could also put in that it can be dropped after Python 3.X (forget which one had the fix in the .0 release). (Adding it to the if would help it be dropped automatically by Ruff when we drop whatever Python that is; comment is probably fine too, though).
    • We'll need a coverage skip here if we don't run any un-patched Pythons in CI, which I assume we don't.
  • Fixed Pythons will throw OSError instead of BuildException with filter='data'.

I have not checked the added logic to see if that's the right place to put it.

However, we should agree on this in the issue first. We might decide it's not our place to patch and we should expect users to upgrade Python if they are worried about this CVE. In that case, this is just a simple change.

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Sdist extraction can write outside its directory through a symlink chain

2 participants