ActionView sanitize helper bypass leading to XSS using SVG tag.
The Rails sanitize helper could be bypassed when the svg and use tags were explicitly allowed, because a use element could reference a base64-encoded SVG containing an event handler. An attacker could then run script in the victim's browser and act as that user.
Originally disclosed on HackerOne
- Triaged in 2 months
- Fixed in 3 months
- Disclosed after 10 months
In the specific configuration, it was possible to bypass HTML sanitization by using the use tag of the SVG element.
In the index.html.erb:
<%= sanitize "<svg><use href=\"data:image/svg+xml;base64,PHN2ZyBpZD0neCcgeG1sbnM9J2h0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnJyB4bWxuczp4bGluaz0naHR0cDovL3d3dy53My5vcmcvMTk5OS94bGluaycgd2lkdGg9JzEzMzcnIGhlaWdodD0nMTMzNyc+CjxpbWFnZSBocmVmPSIxIiBvbmVycm9yPSJhbGVydCh3aW5kb3cub3JpZ2luKSIgLz4KPC9zdmc+#x\"/></svg>", tags: %w(svg use) %>
use tag allows to embed another base64 encoded SVG containing target XSS payload, base64 after decoding:
<svg id='x' xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink' width='1337' height='1337'>
<image href="1" onerror="alert(window.origin)" />
</svg>
SVG and use tags had to be allowed either in global configuration config.action_view.sanitized_allowed_tags = ['svg', 'use']
or inline with tags argument of the helper.
Impact
XSS could lead to data theft through the attacker’s ability to manipulate data through their access to the application, and their ability to interact with other users, including performing other malicious attacks, which would appear to originate from a legitimate user. These malicious actions could also result in reputational damage for the business through the impact on customers’ trust.
Attachments

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 sanitiser's allow-list permitted the SVG use element, which can reference an external or embedded SVG whose event handlers are not sanitised.
Impact
Script could run in the victim's browser, letting the attacker act as that user, steal data and perform further attacks that appear to come from a legitimate account.
What the attacker needed
Svg and use tags allowed in sanitiser config; attacker-controlled content rendered via sanitize
How it was found
- Allow the svg and use tags, either globally or through the helper's tags argument.
- Pass markup containing an svg use element that references a base64-encoded SVG.
- The embedded SVG carries an image with an error handler that runs script.
- The script executes in the victim's browser origin.
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 sanitiser is meant to strip dangerous markup from user content before a page shows it. Here the site had chosen to allow SVG image tags, and one of those tags can pull in another image whose error handler runs JavaScript. That script runs in the victim's session, so it can read or change data as if it were them.
What is XSS?
Script an attacker supplies runs in another user's browser, on the target's origin, with that user's session.