Commit 1bb158d
committed
fix: FileProvider.validate() leaked files outside root
Fixes two issues and adds two improvements:
* FileProvider would read files outside the root if the root were
a prefix of the file path string-wise. Consider a root path
`/tmp/sample/root` and a relative path `../root.txt`, resulting in
reading a file `/tmp/sample/root.txt`.
* The "inside root" check was performed after checking if file existed.
This would expose information about files outside the root through the
exception. While an exploit would be difficult (if possible at all),
it is better to fix this weakness anyway.
* The exception type is changed from the most generic `Exception` to
`ValueError` to make it easier to distinguish it from
`ContentException` that is raised in other cases.
* The `"/"` literal in path operations is changed to `os.sep` to improve
portability.
Signed-off-by: Jan Holeček <71874510+jholecek-rh@users.noreply.github.com>1 parent 6a819a7 commit 1bb158d
File tree
2 files changed
+25
-10
lines changed- insights
- core
- tests/core/spec_factory
2 files changed
+25
-10
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
215 | 215 | | |
216 | 216 | | |
217 | 217 | | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
218 | 229 | | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
219 | 234 | | |
220 | 235 | | |
221 | 236 | | |
| |||
225 | 240 | | |
226 | 241 | | |
227 | 242 | | |
228 | | - | |
229 | | - | |
| 243 | + | |
| 244 | + | |
230 | 245 | | |
231 | 246 | | |
232 | | - | |
233 | | - | |
234 | | - | |
235 | | - | |
236 | | - | |
237 | 247 | | |
238 | 248 | | |
239 | 249 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
35 | | - | |
| 35 | + | |
| 36 | + | |
36 | 37 | | |
37 | 38 | | |
38 | 39 | | |
| |||
48 | 49 | | |
49 | 50 | | |
50 | 51 | | |
51 | | - | |
| 52 | + | |
52 | 53 | | |
53 | 54 | | |
54 | 55 | | |
| |||
59 | 60 | | |
60 | 61 | | |
61 | 62 | | |
62 | | - | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
63 | 68 | | |
64 | 69 | | |
65 | 70 | | |
| |||
0 commit comments