Skip to content

Commit 694d981

Browse files
authored
Merge pull request #196 from rails/flavorjones-fix-frozen-allowed-tags
fix: PermitScrubber accepts frozen tags
2 parents 9d5b398 + 9a1e376 commit 694d981

File tree

3 files changed

+20
-5
lines changed

3 files changed

+20
-5
lines changed

CHANGELOG.md

+13
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
## next / unreleased
2+
3+
* `PermitScrubber` fully supports frozen "allowed tags".
4+
5+
v1.6.1 introduced safety checks that may remove unsafe tags from the allowed list, which
6+
introduced a regression for applications passing a frozen array of allowed tags. Tags and
7+
attributes are now properly copied when they are passed to the scrubber.
8+
9+
Fixes #195.
10+
11+
*Mike Dalessio*
12+
13+
114
## 1.6.1 / 2024-12-02
215

316
This is a performance and security release which addresses several possible XSS vulnerabilities.

lib/rails/html/scrubbers.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,11 @@ def initialize(prune: false)
5656
end
5757

5858
def tags=(tags)
59-
@tags = validate!(tags, :tags)
59+
@tags = validate!(tags.dup, :tags)
6060
end
6161

6262
def attributes=(attributes)
63-
@attributes = validate!(attributes, :attributes)
63+
@attributes = validate!(attributes.dup, :attributes)
6464
end
6565

6666
def scrub(node)

test/sanitizer_test.rb

+5-3
Original file line numberDiff line numberDiff line change
@@ -1099,7 +1099,7 @@ def test_should_sanitize_across_newlines
10991099
def test_should_prune_mglyph
11001100
# https://hackerone.com/reports/2519936
11011101
input = "<math><mtext><table><mglyph><style><img src=: onerror=alert(1)>"
1102-
tags = %w(math mtext table mglyph style)
1102+
tags = %w(math mtext table mglyph style).freeze
11031103

11041104
actual = nil
11051105
assert_output(nil, /WARNING: 'mglyph' tags cannot be allowed by the PermitScrubber/) do
@@ -1119,7 +1119,7 @@ def test_should_prune_mglyph
11191119
def test_should_prune_malignmark
11201120
# https://hackerone.com/reports/2519936
11211121
input = "<math><mtext><table><malignmark><style><img src=: onerror=alert(1)>"
1122-
tags = %w(math mtext table malignmark style)
1122+
tags = %w(math mtext table malignmark style).freeze
11231123

11241124
actual = nil
11251125
assert_output(nil, /WARNING: 'malignmark' tags cannot be allowed by the PermitScrubber/) do
@@ -1138,7 +1138,9 @@ def test_should_prune_malignmark
11381138

11391139
def test_should_prune_noscript
11401140
# https://hackerone.com/reports/2509647
1141-
input, tags = "<div><noscript><p id='</noscript><script>alert(1)</script>'></noscript>", ["p", "div", "noscript"]
1141+
input = "<div><noscript><p id='</noscript><script>alert(1)</script>'></noscript>"
1142+
tags = ["p", "div", "noscript"].freeze
1143+
11421144
actual = nil
11431145
assert_output(nil, /WARNING: 'noscript' tags cannot be allowed by the PermitScrubber/) do
11441146
actual = safe_list_sanitize(input, tags: tags, attributes: %w(id))

0 commit comments

Comments
 (0)