Commit 1310c9f
authored
* fix(uploads): allowlist Content-Type on serve paths to prevent stored-XSS (#3729)
Defense-in-depth backstop: the download handler now validates the stored
content-type against SAFE_MIME (get) / SAFE_IMAGE_MIME (getSharp) before
echoing it, falling back to application/octet-stream / image/jpeg respectively.
Adds Content-Disposition: attachment on the private download path.
Covers both req.upload.contentType and req.upload.metadata.contentType.
15 new unit tests assert safe MIMEs pass through and dangerous ones are
downgraded.
* fix(uploads): normalize MIME before allowlist check + harden pipe mocks + expand getSharp coverage
- Add normalizeMime() helper: lowercase + strip ; params
- Apply normalizeMime() in both get and getSharp before allowlist lookup
- Add @returns JSDoc to getSharp per repo guideline
- Fix stream.pipe mock in makeStream() to return dest (chained pipe support)
- Fix sharp().pipe mock to return dest (stream.pipe(transform).pipe(res) chain)
- Remove per-test stream.pipe overrides (centralized in makeStream)
- Add getSharp tests: metadata.contentType safe/dangerous, missing fallback,
uppercase MIME, MIME-with-params normalization
- Add get tests: uppercase MIME, MIME-with-params normalization
Addresses all Copilot review threads on PR #3732.
1 parent b08e9a3 commit 1310c9f
2 files changed
Lines changed: 392 additions & 2 deletions
File tree
- modules/uploads
- controllers
- tests
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
12 | 33 | | |
13 | 34 | | |
14 | 35 | | |
| |||
21 | 42 | | |
22 | 43 | | |
23 | 44 | | |
24 | | - | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
25 | 48 | | |
| 49 | + | |
26 | 50 | | |
27 | 51 | | |
28 | 52 | | |
| |||
34 | 58 | | |
35 | 59 | | |
36 | 60 | | |
| 61 | + | |
37 | 62 | | |
38 | 63 | | |
39 | 64 | | |
| |||
42 | 67 | | |
43 | 68 | | |
44 | 69 | | |
45 | | - | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
46 | 73 | | |
47 | 74 | | |
48 | 75 | | |
| |||
0 commit comments