Skip to content

fix(cli): extract sdist with data filter to prevent symlink traversal - #1302

Closed
feiiiiii5 wants to merge 1 commit into
pypa:mainfrom
feiiiiii5:fix/sdist-symlink-extraction
Closed

feiiiiii5 wants to merge 1 commit into
pypa:mainfrom
feiiiiii5:fix/sdist-symlink-extraction

Conversation

@feiiiiii5

Copy link
Copy Markdown
Contributor

Why I decided to contribute

build is the standard build frontend for Python projects across the packaging ecosystem, and ensuring archives unpack securely without symlink traversal vulnerabilities is vital for safe builds in automated and sandbox environments.

Description

Fixes #1265.

In _prepare_sdist_archive, archive members were filtered with tarfile.data_filter(m, extract_dir) up-front, and then extractall was called with filter='fully_trusted'. Because extraction filters must inspect the filesystem dynamically as members are extracted, an up-front check cannot detect symlinks that resolve through earlier extracted symlinks in a chain (such as demo-1.0/self -> . followed by nested symlinks escaping the extraction root).

Passing filter='data' to archive.extractall ensures each member is dynamically verified against the current filesystem state during extraction, correctly rejecting symlink traversal chains with tarfile.LinkOutsideDestinationError before any files outside the destination directory can be created or modified.

Added a regression test test_extract_sdist_rejects_symlink_chain_traversal 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 (or clearly explain why it's better if it is)
  • Tests pass locally (some combination of tox, tox -e fix, tox -e type, tox -e docs, depending on the change)
  • The PR description is not significantly longer than the change not counting tests (use <details> tags if you really need more)

Signed-off-by: fei <204683769+feiiiiii5@users.noreply.github.com>
@feiiiiii5
feiiiiii5 force-pushed the fix/sdist-symlink-extraction branch from 7ef8472 to 1399610 Compare November 20, 2026 04:25
@henryiii

Copy link
Copy Markdown
Contributor

Duplicate of #1274. Please check duplicates including closed ones.

@henryiii henryiii closed this Nov 20, 2026
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