[prev in list] [next in list] [prev in thread] [next in thread]
List: oss-security
Subject: [oss-security] [CVE-2015-7580] Possible XSS vulnerability in rails-html-sanitizer
From: Aaron Patterson <tenderlove () ruby-lang ! org>
Date: 2016-01-25 19:38:45
Message-ID: 20160125193845.GH14069 () TC ! local
[Download RAW message or body]
[Attachment #2 (multipart/mixed)]
Possible XSS vulnerability in rails-html-sanitizer
There is a possible XSS vulnerability in the white list sanitizer in the
rails-html-sanitizer gem. This vulnerability has been assigned the CVE
identifier CVE-2015-7580.
Versions Affected: All.
Not affected: None.
Fixed Versions: v1.0.3
Impact
------
Carefully crafted strings can cause user input to bypass the sanitization in
the white list sanitizer which will can lead to an XSS attack.
Vulnerable code will look something like this:
<%= sanitize user_input, tags: %w(em) %>
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
-----------
Putting the following monkey patch in an initializer can help to mitigate the
issue:
```
class Rails::Html::PermitScrubber
alias :old_scrub :scrub
alias :old_skip_node? :skip_node?
def scrub(node)
if node.cdata?
text = node.document.create_text_node node.text
node.replace text
return CONTINUE
end
old_scrub node
end
def skip_node?(node); node.text?; 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.
* 1-0-whitelist_sanitizer_xss.patch - Patch for 1.0 series
Credits
-------
Thanks to Arnaud Germis, Nate Clark, and John Colvin for reporting this issue.
--
Aaron Patterson
http://tenderlovemaking.com/
["1-0-whitelist_sanitizer_xss.patch" (text/plain)]
From 8c4c58f4e671a2f9f0e1477e47ff943a3b824799 Mon Sep 17 00:00:00 2001
From: Aaron Patterson <aaron.patterson@gmail.com>
Date: Thu, 29 Oct 2015 12:06:26 -0700
Subject: [PATCH] convert CDATA nodes to TEXT nodes to avoid XSS issues
CDATA nodes will not be html escaped. Users shouldn't be submitting
CDATA nodes in the first place, so we should convert them to text nodes
before escaping
CVE-2015-7580
---
lib/rails/html/scrubbers.rb | 7 ++++++-
test/sanitizer_test.rb | 10 ++++++++++
2 files changed, 16 insertions(+), 1 deletion(-)
diff --git a/lib/rails/html/scrubbers.rb b/lib/rails/html/scrubbers.rb
index 1384a2f..6d82a20 100644
--- a/lib/rails/html/scrubbers.rb
+++ b/lib/rails/html/scrubbers.rb
@@ -60,6 +60,11 @@ module Rails
end
def scrub(node)
+ if node.cdata?
+ text = node.document.create_text_node node.text
+ node.replace text
+ return CONTINUE
+ end
return CONTINUE if skip_node?(node)
unless keep_node?(node)
@@ -76,7 +81,7 @@ module Rails
end
def skip_node?(node)
- node.text? || node.cdata?
+ node.text?
end
def scrub_attribute?(name)
diff --git a/test/sanitizer_test.rb b/test/sanitizer_test.rb
index 06d70e4..3bfc7cb 100644
--- a/test/sanitizer_test.rb
+++ b/test/sanitizer_test.rb
@@ -11,6 +11,16 @@ class SanitizersTest < Minitest::Test
end
end
+ def test_sanitize_nested_script
+ sanitizer = Rails::Html::WhiteListSanitizer.new
+ assert_equal '<script>alert("XSS");</script>', \
sanitizer.sanitize('<script><script></script>alert("XSS");<script><</script>/</script><script>script></script>', \
tags: %w(em)) + end
+
+ def test_sanitize_nested_script_in_style
+ sanitizer = Rails::Html::WhiteListSanitizer.new
+ assert_equal '<script>alert("XSS");</script>', \
sanitizer.sanitize('<style><script></style>alert("XSS");<style><</style>/</style><style>script></style>', \
tags: %w(em)) + end
+
class XpathRemovalTestSanitizer < Rails::Html::Sanitizer
def sanitize(html, options = {})
fragment = Loofah.fragment(html)
--
2.2.1
[Attachment #6 (application/pgp-signature)]
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic