Skip to content

fix: refuse to write files outside the target directory during sdist extraction - #11027

Merged
radoering merged 4 commits into
python-poetry:mainfrom
radoering:tar-extraction-fallback
Aug 29, 2026
Merged

radoering merged 4 commits into
python-poetry:mainfrom
radoering:tar-extraction-fallback

Conversation

@radoering

Copy link
Copy Markdown
Member

Pull Request Check List

Only relevant for outdated Python versions.

  • Added tests for changed code.
  • Updated documentation for changed code.

@radoering
radoering force-pushed the tar-extraction-fallback branch from 111c7fc to 695a5b5 Compare August 29, 2026 15:17

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Hey - I've found 1 issue

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="src/poetry/utils/helpers.py" line_range="348" />
<code_context>
+                            mode = None
+                        else:
+                            # Reject special files
+                            raise ValueError(
+                                "Refusing to extract special file {member.name}"
+                            )
+                        if mode != member.mode:
</code_context>
<issue_to_address>
**nitpick (bug_risk):** The special-file rejection error contains the literal text `{member.name}` because the string is not an f-string, so callers cannot identify which archive member caused extraction to fail.

**Triggers:** When an sdist contains a FIFO, device, or other unsupported special file.

**Suggested fix:** Prefix the string with `f` so the member name is interpolated.

```suggestion
                                f"Refusing to extract special file {member.name}"
```
</issue_to_address>

Sourcery assessment

Needs a human reviewer. If the path and link validation is wrong, archive extraction could write or overwrite files outside the destination, and those changes would remain after reverting the code. A fully correct revert would stop future incidents but would not undo files already written; otherwise, overly strict filtering would cause ordinary extraction failures that can be fixed normally.


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment thread src/poetry/utils/helpers.py Outdated
radoering and others added 3 commits August 29, 2026 17:21
Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>
@radoering
radoering merged commit 812a816 into python-poetry:main Aug 29, 2026
52 checks passed
radoering added a commit that referenced this pull request Aug 29, 2026
mwalbeck pushed a commit to mwalbeck/docker-python-poetry that referenced this pull request Sep 6, 2026
This PR contains the following updates:

| Package | Update | Change | Pending |
|---|---|---|---|
| [poetry](https://github.com/python-poetry/poetry) ([changelog](https://python-poetry.org/history/)) | patch | `2.4.1` → `2.4.2` | `2.4.3` |

---

### Release Notes

<details>
<summary>python-poetry/poetry (poetry)</summary>

### [`v2.4.2`](https://github.com/python-poetry/poetry/blob/HEAD/CHANGELOG.md#242---2026-08-29)

[Compare Source](python-poetry/poetry@2.4.1...2.4.2)

##### Fixed

- Fix an issue where Poetry installs an artifact that is not listed in the lockfile when the package source does not provide a hash for this artifact ([#&#8203;11030](python-poetry/poetry#11030)).
- Fix a path traversal vulnerability when downloading files from a compromised URL and/or package source ([#&#8203;11029](python-poetry/poetry#11029)).
- Fix a path traversal vulnerability in sdist extraction on Python 3.10.0-3.10.12 and 3.11.0-3.11.4 that could allow malicious tarball files to write files outside the target directory ([#&#8203;11027](python-poetry/poetry#11027)).

</details>

---

### Configuration

📅 **Schedule**: (UTC)

- Branch creation
  - At any time (no schedule defined)
- Automerge
  - At any time (no schedule defined)

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box

---

This PR has been generated by [Mend Renovate](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0My4yNjAuMCIsInVwZGF0ZWRJblZlciI6IjQzLjI2MC4wIiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6W119-->

Reviewed-on: https://git.walbeck.it/mwalbeck/docker-python-poetry/pulls/1760
@github-actions

Copy link
Copy Markdown

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Sep 29, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant