🔒️(backend) force SVG attachments to download to prevent stored XSS - #2582
🔒️(backend) force SVG attachments to download to prevent stored XSS#2582bunlongheng wants to merge 1 commit into
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: ASSERTIVE Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
WalkthroughThe unsafe document MIME-type configuration now includes Estimated code review effort: 1 (Trivial) | ~2 minutes Mergeability Score: ⚪ Minimal · up to SVG attachments will be forced to download instead of rendering inline; no actionable merge-blocking risk remains at the current head after normal checks and review. Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
I've already come across this, but i think this claim is wrong:
You can check the nginx config here: https://github.com/suitenumerique/docs/blob/main/docker/files/etc/nginx/conf.d/default.conf So all scripting falls back to 'none'. The XSS can't be triggered, and your POC isn't reproducible. |
|
You're right, @maboukerfa - thank you for the correction. I missed the If it's still useful, here is the case for the one-line change as defense-in-depth rather than a vulnerability fix:
Happy to update the PR description to reposition it as hardening (and drop the incorrect POC), or close it if you feel the proxy-layer guarantee is sufficient. Either way, thanks for taking the time to verify instead of just merging - that's exactly the kind of review that makes this project solid. |
Summary
Add
image/svg+xmltoDOCUMENT_UNSAFE_MIME_TYPESso uploaded SVG attachments are flaggedis_unsafe=trueand served withContent-Disposition: attachment(forced download), consistent with the existing handling of other active-content types (HTML, PHP, etc.) in that list.Context (updated after review)
The original description claimed a reproducible stored XSS. That was wrong - as @maboukerfa pointed out, all 3 reference deployment paths apply
Content-Security-Policy: default-src 'none'to/media/at the proxy layer (dev nginx config, production nginx template, and the Helm chart'singressMediaannotation), which blocks script execution in inline-served SVGs. The severity claim is withdrawn.Why the change may still be worth it (defense-in-depth)
nginx.ingress.kubernetes.io/configuration-snippet, and ingress-nginx ships withallow-snippet-annotations: falseby default since v1.9, so on a cluster with default admission settings the annotation is not applied. Other ingress classes (Traefik, ALB, etc.) ignore it entirely.DOCUMENT_UNSAFE_MIME_TYPESalready enforces the same policy for other active-content types at the application layer regardless of proxy config. This change makes SVG consistent with that policy, so the app stays safe even when a deployment's proxy layer differs from the reference configs.Behaviour change
SVG uploads are stored with the
-unsafesuffix and download instead of rendering inline. Raster images (png, jpeg, gif, webp) are unaffected.