Commit e2a3703
committed
Prevent path traversal in static file routes (#912)
static_route and static_route_exts interpolate the {fname:path} URL
segment straight into FileResponse(f'{static_path}/{fname}...'). The path
converter matches '..', so a request like /%2e%2e/%2e%2e/secret.gz
resolves outside static_path and serves any file the process can read.
Add _static_fpath, which resolves the requested path against static_path
and raises 404 when it escapes, and route both static handlers through
it. Nested paths and an explicit static_path above the app dir still
work; only '..' within the request path is rejected.1 parent 23a415f commit e2a3703
3 files changed
Lines changed: 42 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
130 | 130 | | |
131 | 131 | | |
132 | 132 | | |
| 133 | + | |
133 | 134 | | |
134 | 135 | | |
135 | 136 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
975 | 975 | | |
976 | 976 | | |
977 | 977 | | |
| 978 | + | |
| 979 | + | |
| 980 | + | |
| 981 | + | |
| 982 | + | |
| 983 | + | |
| 984 | + | |
978 | 985 | | |
979 | 986 | | |
980 | 987 | | |
981 | 988 | | |
982 | | - | |
| 989 | + | |
| 990 | + | |
983 | 991 | | |
984 | 992 | | |
985 | 993 | | |
986 | 994 | | |
987 | 995 | | |
988 | 996 | | |
989 | | - | |
| 997 | + | |
| 998 | + | |
990 | 999 | | |
991 | 1000 | | |
992 | 1001 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4349 | 4349 | | |
4350 | 4350 | | |
4351 | 4351 | | |
| 4352 | + | |
| 4353 | + | |
| 4354 | + | |
| 4355 | + | |
| 4356 | + | |
| 4357 | + | |
| 4358 | + | |
4352 | 4359 | | |
4353 | 4360 | | |
4354 | 4361 | | |
4355 | 4362 | | |
4356 | | - | |
| 4363 | + | |
4357 | 4364 | | |
4358 | 4365 | | |
4359 | 4366 | | |
| |||
4394 | 4401 | | |
4395 | 4402 | | |
4396 | 4403 | | |
4397 | | - | |
| 4404 | + | |
4398 | 4405 | | |
4399 | 4406 | | |
4400 | 4407 | | |
| |||
4408 | 4415 | | |
4409 | 4416 | | |
4410 | 4417 | | |
| 4418 | + | |
| 4419 | + | |
| 4420 | + | |
| 4421 | + | |
| 4422 | + | |
| 4423 | + | |
| 4424 | + | |
| 4425 | + | |
| 4426 | + | |
| 4427 | + | |
| 4428 | + | |
| 4429 | + | |
| 4430 | + | |
| 4431 | + | |
| 4432 | + | |
| 4433 | + | |
| 4434 | + | |
| 4435 | + | |
| 4436 | + | |
| 4437 | + | |
| 4438 | + | |
4411 | 4439 | | |
4412 | 4440 | | |
4413 | 4441 | | |
| |||
0 commit comments