Commit 1d858ac
committed
fix(android): validate ZIP entry paths against destination (Zip Slip)
Prior to this commit, HybridUnzipTask.kt's Android extraction path resolved
every entry as `File(destDir, entry.name)` and wrote to that path without
checking that the resolved file actually sits inside destDir. A malicious
ZIP containing an entry named `../../databases/poi.db` would resolve to
`destDir/../../databases/poi.db` and FileOutputStream would happily write
to it — the classic Zip Slip vulnerability.
Fix: introduce a canonical-path validation helper that's called once per
entry in pass 1 (header collection) and again per entry in pass 2 (file
write) for defence in depth. The check resolves the candidate path under
the canonical destDir and rejects anything that doesn't start with the
destDir prefix. Absolute paths, `..` traversal, and exotic separators all
canonicalise into something the prefix check catches.
Same validation applied to the zip4j password-protected path before
delegating to zip4j.extractFile() — zip4j 2.10+ has its own check but
defence in depth is cheap and shields against older transitive versions.
iOS path is unaffected: SSZipArchive ~> 2.5 validates paths since 2.4.0.
Bumps to 0.3.1.1 parent 66a6acf commit 1d858ac
2 files changed
Lines changed: 41 additions & 1 deletion
Lines changed: 40 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
71 | 71 | | |
72 | 72 | | |
73 | 73 | | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
74 | 77 | | |
75 | 78 | | |
76 | 79 | | |
| |||
84 | 87 | | |
85 | 88 | | |
86 | 89 | | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
87 | 94 | | |
88 | 95 | | |
89 | 96 | | |
| |||
112 | 119 | | |
113 | 120 | | |
114 | 121 | | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
115 | 126 | | |
116 | 127 | | |
117 | 128 | | |
| |||
185 | 196 | | |
186 | 197 | | |
187 | 198 | | |
| 199 | + | |
188 | 200 | | |
189 | 201 | | |
190 | 202 | | |
| |||
195 | 207 | | |
196 | 208 | | |
197 | 209 | | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
198 | 217 | | |
199 | 218 | | |
200 | 219 | | |
| |||
251 | 270 | | |
252 | 271 | | |
253 | 272 | | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
254 | 294 | | |
255 | 295 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
| 3 | + | |
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| |||
0 commit comments