Skip to content
XSS Disclosed report Intermediate CVE-2022-22577

Content Security Policy is only active for HTML responses but not for image/svg+xml

Rails only applies its Content Security Policy to responses with an HTML content type, so an SVG served inline as image/svg+xml runs embedded script without the policy. An attacker who can upload such a file and get a victim to open it could execute script in the victim's session.

thorsteneckel Follow

Originally disclosed on HackerOne

  • Fixed in 8 months
  • Disclosed after 23 months

Note: ActiveStorage prevents this by filtering via ActiveStorage.content_types_allowed_inline

Impact

The attacker can trick victim users to execute Java Script in the scope of their active session by uploading the malicious file to the server and sending a link to that file to the victim.

The original report as published on HackerOne, by thorsteneckel. Images and videos are our own copies; raw HTML is shown as text. View it on HackerOne.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

How it worked

Root cause

Likely the CSP middleware in Rails only attaches the policy when the response content type is HTML, leaving other renderable types such as SVG without protection.

Impact

An attacker could trick a victim into running script in the scope of their active session by uploading a malicious file and sending a link to it, though ActiveStorage blocks this by filtering inline content types.

What the attacker needed

Ability to upload an SVG file; victim opens the file link; endpoint serves SVG inline

How it was found

  1. Set up a plain Rails application with a simple route and controller.
  2. Configure a Content Security Policy with default-src 'none' for download or preview endpoints.
  3. Serve a malicious SVG from the controller inline as image/svg+xml.
  4. Observe that the script inside the SVG executes despite the policy.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

A Content Security Policy is a set of browser rules that blocks unwanted scripts on a page. Rails was only sending these rules for normal web pages, not for SVG images, which browsers can treat as pages that run script. So a crafted image could run code in the victim's browser.

What is XSS?

Script an attacker supplies runs in another user's browser, on the target's origin, with that user's session.

More from Ruby on Rails

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Cross-site scripting (XSS)

The lesson behind this report.

Script an attacker supplies runs in another user's browser, on the target's origin, with that user's session.