Commit 77b5934
authored
Defense-in-depth zip-entry validation in zip_utils (#4509)
## Summary
- Adds `_validate_zip_entries()` in `nvflare/fuel/utils/zip_utils.py`
that rejects zip entries with absolute paths or `..` components before
`extractall()` is called.
- Wires the helper into both `unzip_all_from_bytes` and
`unzip_all_from_file`.
## Context
NVBugs **6128822** flagged `zip_utils.py:178` / `:195` as exploitable
path traversal (CVSS 8.8). The claim does not reproduce on any supported
Python version: CPython's `zipfile.extractall` already strips `..`
components and absolute-path roots from member names before extraction
(see CVE-2014-4616 hardening and the [zipfile
docs](https://docs.python.org/3/library/zipfile.html#zipfile.ZipFile.extract)).
Empirical check on 3.12: a malicious archive containing
`../../../../site-packages/nvflare/malicious.py` extracts to
`<out>/site-packages/nvflare/malicious.py` — never escapes the output
dir.
So this PR is **not a security fix**; it's defense-in-depth so the
operator gets a clear `ValueError` on a suspicious archive instead of
silently rewritten paths, and to satisfy the external reporter.
## Test plan
- [x] Manual repro: `..` traversal, POSIX absolute (`/etc/...`),
Windows-backslash absolute (`\windows\...`), and mid-path `..`
(`foo/../../bar`) all rejected with clear `ValueError`s.
- [x] Existing `tests/unit_test/fuel/utils/zip_utils_test.py` (16 tests)
pass unchanged.
- [x] black / isort / flake8 clean.1 parent 959d92c commit 77b5934
1 file changed
Lines changed: 48 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
| 17 | + | |
17 | 18 | | |
18 | | - | |
| 19 | + | |
19 | 20 | | |
20 | 21 | | |
21 | 22 | | |
| |||
140 | 141 | | |
141 | 142 | | |
142 | 143 | | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
143 | 180 | | |
144 | 181 | | |
145 | 182 | | |
| |||
148 | 185 | | |
149 | 186 | | |
150 | 187 | | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
151 | 193 | | |
152 | 194 | | |
153 | 195 | | |
| |||
158 | 200 | | |
159 | 201 | | |
160 | 202 | | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
161 | 206 | | |
162 | 207 | | |
163 | 208 | | |
| |||
175 | 220 | | |
176 | 221 | | |
177 | 222 | | |
| 223 | + | |
178 | 224 | | |
179 | 225 | | |
180 | 226 | | |
| |||
192 | 238 | | |
193 | 239 | | |
194 | 240 | | |
| 241 | + | |
195 | 242 | | |
0 commit comments