Commit b483e95
Backport CVE-2026-1703: use os.path.commonpath in is_within_directory
`os.path.commonprefix` operates character-by-character, so it treated
`/foo/parent/child` and `/foo/parent/childfoo` as sharing the prefix
`/foo/parent/child` and reported them as "within" the same directory.
A crafted wheel could exploit this to write files into a sibling
directory whose name is a prefix of the install path.
Switch to `os.path.commonpath`, which operates on path components, and
add a regression test for the prefix-vs-component substring case.
Equivalent of upstream commit 4c651b7 (Seth Michael Larson,
"Use os.path.commonpath() instead of commonprefix()"). `os.path.commonpath`
is available since CPython 3.5, so this is safe on Python 3.7.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent 0087814 commit b483e95
2 files changed
Lines changed: 3 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
81 | 81 | | |
82 | 82 | | |
83 | 83 | | |
84 | | - | |
| 84 | + | |
85 | 85 | | |
86 | 86 | | |
87 | 87 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
386 | 386 | | |
387 | 387 | | |
388 | 388 | | |
| 389 | + | |
| 390 | + | |
389 | 391 | | |
390 | 392 | | |
391 | 393 | | |
| |||
0 commit comments