ActionView sanitize helper bypass with 'style' and 'svg' tags
The Rails HTML sanitizer failed to properly sanitise input when both an SVG (or MathML) tag and a style tag were on the allowlist, so crafted markup could slip through. An attacker could then get script to run in a victim's browser, a cross-site scripting issue.
- Fixed in 26 days
- Paid in 26 days
- Disclosed after 26 days
Summary by the program
##Summary
There is a possible XSS vulnerability with certain configurations of Rails::HTML::Sanitizer 1.6.0 when used with Rails >= 7.1.0.
Versions affected: 1.6.0 Not affected: < 1.6.0 Fixed versions: 1.6.1
Advisory: https://github.com/rails/rails-html-sanitizer/security/advisories/GHSA-2x5m-9ch4-qgrr
The report
Rails-html-sanitizer, which Rails AtionView also uses fails to sanitize input when svg and style OR math and style are allowed
An example would be as follows;
<%= sanitize @comment.body, tags: ["math", "style"] %>
<%# or %>
<%= sanitize @comment.body, tags: ["svg", "style"] %>
You could see other patterns/places where this is used in the security advisory. View #2503220 for details.
Impact
Sanitizer bypass that leads to XSS on applications built with it. It also affects applications using Rails Action View's sanitize helper: https://api.rubyonrails.org/v7.2/classes/ActionView/Helpers/SanitizeHelper.html
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 allowlist logic mishandled the combination of SVG or MathML elements together with style elements, leaving a way to smuggle executable markup past filtering.
Impact
A sanitiser bypass that could lead to cross-site scripting on applications using the affected configuration, including those using Rails Action View's sanitize helper.
What the attacker needed
App allows svg or math plus style tags; attacker can submit content that is sanitised
The fix
It was fixed in version 1.6.1 of the sanitiser.
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, if a developer allowed both an SVG (or MathML) tag and a style tag, the sanitiser let something harmful through. That means an attacker could get their own code to run in another user'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.