Skip to content
XSS Disclosed report Intermediate

[Rails42] We can inject HTML tags when server is using strip_tags method

The strip_tags method in Rails unescaped already-escaped HTML entities, so an attacker could inject HTML tags that would be rendered as active content if the output was later marked as safe. This could lead to cross-site scripting (XSS) when combined with raw or html_safe.

arthurnn Follow

Originally disclosed on HackerOne

  • Triaged in 28 hours
  • Fixed in 6 months
  • Disclosed after 7 months

Summary by the program

XSS vulnerability in rails-html-sanitizer

There is a XSS vulnerability in Rails::Html::FullSanitizer used by Action View's strip_tags. This vulnerability has been assigned the CVE identifier CVE-2015-7579.

Versions Affected: 1.0.2 Not affected: 1.0.0, 1.0.1 Fixed Versions: 1.0.3

Impact

Due to the way that Rails::Html::FullSanitizer is implemented, if an attacker passes an already escaped HTML entity to the input of Action View's strip_tags these entities will be unescaped what may cause a XSS attack if used in combination with raw or html_safe.

For example:

strip_tags("<script>alert('XSS')</script>")

Would generate:

<script>alert('XSS')</script>

After the fix it will generate:

&lt;script&gt;alert('XSS')&lt;/script&gt;

All users running an affected release should either upgrade or use one of the workarounds immediately.

Releases

The FIXED releases are available at the normal locations.

Workarounds

If you can't upgrade, please use the following monkey patch in an initializer that is loaded before your application:

$ cat config/initializers/strip_tags_fix.rb
class ActionView::Base
  def strip_tags(html)
    self.class.full_sanitizer.sanitize(html)
  end
end

Patches

To aid users who aren't able to upgrade immediately we have provided patches for the two supported release series. They are in git-am format and consist of a single changeset.

  • Do-not-unescape-already-escaped-HTML-entities.patch

Credits

Thank you to Arthur Neves from GitHub and Spyros Livathinos from Zendesk for reporting the problem and working with us to fix it.

The original report as published on HackerOne, by arthurnn. 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 sanitizer unescaped HTML entities before stripping tags, so escaped input became active HTML.

Impact

An attacker could inject HTML tags that, if the output is used with raw or html_safe, may lead to cross-site scripting.

What the attacker needed

Application uses strip_tags on user input; output is used with raw or html_safe

The fix

The vulnerability was fixed in rails-html-sanitizer version 1.0.3, and a monkey patch is available for those who cannot upgrade.

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.

When a web application shows user input, it usually escapes special characters like < and > so they appear as text, not code. The strip_tags method in Rails is supposed to remove HTML tags, but it mistakenly turned escaped characters back into real tags. If the application then marked that output as safe, the injected tags could run malicious scripts in a visitor'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.