Skip to content

Commit 3f833f6

Browse files
authored
Merge pull request #116 from rails/115-sanitize-processing-instructions
PermitScrubber does not permit Processing Instructions
2 parents 3b7551c + 2a7d3f2 commit 3f833f6

File tree

4 files changed

+23
-1
lines changed

4 files changed

+23
-1
lines changed

Diff for: .travis.yml

+2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ rvm:
77
- 2.4
88
- 2.5
99
- 2.6
10+
- 2.7
11+
- 3.0
1012
- ruby-head
1113
- jruby
1214
matrix:

Diff for: CHANGELOG.md

+12
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
## next / unreleased
2+
3+
* Processing Instructions are no longer allowed by Rails::Html::PermitScrubber
4+
5+
Previously, a PI with a name (or "target") matching an allowed tag name was not scrubbed. There
6+
are no known security issues associated with these PIs, but similar to comments it's preferred to
7+
omit these nodes when possible from sanitized output.
8+
9+
Fixes #115.
10+
11+
*Mike Dalessio*
12+
113
## 1.3.0
214

315
* Address deprecations in Loofah 2.3.0.

Diff for: lib/rails/html/scrubbers.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def scrub(node)
6868
end
6969
return CONTINUE if skip_node?(node)
7070

71-
unless keep_node?(node)
71+
unless node.element? && keep_node?(node)
7272
return STOP if scrub_node(node) == STOP
7373
end
7474

Diff for: test/sanitizer_test.rb

+8
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,14 @@ def test_uri_escaping_of_name_action_in_a_tag_in_safe_list_sanitizer
521521
assert_equal %{<a action=\"examp&lt;!--%22%20unsafeattr=foo()&gt;--&gt;le.com\">test</a>}, text
522522
end
523523

524+
def test_exclude_node_type_processing_instructions
525+
assert_equal("<div>text</div><b>text</b>", safe_list_sanitize("<div>text</div><?div content><b>text</b>"))
526+
end
527+
528+
def test_exclude_node_type_comment
529+
assert_equal("<div>text</div><b>text</b>", safe_list_sanitize("<div>text</div><!-- comment --><b>text</b>"))
530+
end
531+
524532
protected
525533

526534
def xpath_sanitize(input, options = {})

0 commit comments

Comments
 (0)