Commit bb0b615
authored
fix(serve): prevent code injection in capture_dependencies path interpolation (#5792)
capture_dependencies built a `python -c` script by f-string interpolating
pkl_path and dest_path, both derived from a user-supplied model directory,
directly into Python source. A directory name containing `"` could break out
of the string literal and execute arbitrary Python via expression chaining
(e.g. `model" + __import__("os").system("...") + "`), giving an attacker
local code execution when a victim extracted a malicious tarball and passed
it to ModelBuilder with dependencies={"auto": True}.
Use the !r conversion so repr() emits properly escaped Python string
literals for both paths. Any embedded quotes, backslashes, or control
characters are escaped, so the paths arrive at get_requirements_for_pkl_file
as inert string constants rather than executable code.
Affects Linux/macOS; Windows was not exploitable because `"` is an invalid
filename character on NTFS. Reported via AWS Vulnerability Reporting Program
(P414309851, CWE-94).1 parent 92f8d42 commit bb0b615
1 file changed
Lines changed: 7 additions & 4 deletions
Lines changed: 7 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
36 | 36 | | |
37 | 37 | | |
38 | 38 | | |
39 | | - | |
40 | | - | |
| 39 | + | |
| 40 | + | |
41 | 41 | | |
42 | 42 | | |
43 | 43 | | |
| |||
46 | 46 | | |
47 | 47 | | |
48 | 48 | | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
49 | 52 | | |
50 | 53 | | |
51 | 54 | | |
52 | | - | |
| 55 | + | |
53 | 56 | | |
54 | 57 | | |
55 | 58 | | |
56 | 59 | | |
57 | | - | |
| 60 | + | |
58 | 61 | | |
59 | 62 | | |
60 | 63 | | |
| |||
0 commit comments