Commit 505ed8d
committed
Use
Previously we used `os.path.commonprefix()` which will treat paths like
`/foo/bar_suffix` as matching `/foo/bar`. This gave rise to a potential
security vulnerability given the following conditions:
* An application running Whitenoise with `autorefresh` enabled.
* A sibling directory of a static root directory which shares a prefix
with it (e.g. `static` and `static_disallowed`).
* Knowledge of the absolute paths at which these directories are
located.
* A Windows server hosting the application.
An attacker could craft a URL like:
http://example.com/static/C:/path/to/static_disallowed/sensitive-file.txt
This would allow them to read a file from `static_disallowed` when they
should only be able to read files from `static`.
This is related to the Windows path traversal attack identified in #197
and to the `commonprefix()` path traversal attack identified in pip:
https://www.cve.org/CVERecord?id=CVE-2026-1703
Thanks to Seth Larson for reporting this.
This is a good opportunity to reiterate the warning in the documentation
that `autorefresh` is provided as a convenience for development and, for
both security and performance reasons, is not suitable for production
use.os.path.commonpath() to identify child paths1 parent b6d8ed4 commit 505ed8d
3 files changed
Lines changed: 30 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| 6 | + | |
6 | 7 | | |
7 | 8 | | |
8 | 9 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
147 | 147 | | |
148 | 148 | | |
149 | 149 | | |
150 | | - | |
| 150 | + | |
151 | 151 | | |
152 | 152 | | |
153 | 153 | | |
| |||
184 | 184 | | |
185 | 185 | | |
186 | 186 | | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
187 | 196 | | |
188 | 197 | | |
189 | 198 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
380 | 380 | | |
381 | 381 | | |
382 | 382 | | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
0 commit comments