Namespace
Methods
- A
- S
- T
-
- test_allow_colons_in_path_component,
- test_sanitize_form,
- test_sanitize_image_src,
- test_sanitize_javascript_href,
- test_sanitize_js_handlers,
- test_sanitize_plaintext,
- test_sanitize_script,
- test_should_accept_good_protocols,
- test_should_accept_good_protocols_ignoring_case,
- test_should_allow_anchors,
- test_should_allow_custom_tags,
- test_should_allow_custom_tags_with_attributes,
- test_should_allow_custom_tags_with_custom_attributes,
- test_should_allow_only_custom_tags,
- test_should_block_script_tag,
- test_should_flag_bad_protocols,
- test_should_handle_blank_text,
- test_should_handle_non_html,
- test_should_not_fall_for_ridiculous_hack,
- test_should_not_mangle_urls_with_ampersand,
- test_should_reject_hex_codes_in_protocol,
- test_should_sanitize_across_newlines,
- test_should_sanitize_attributes,
- test_should_sanitize_cdata_section,
- test_should_sanitize_div_background_image_unicode_encoded,
- test_should_sanitize_div_style_expression,
- test_should_sanitize_half_open_scripts,
- test_should_sanitize_illegal_style_properties,
- test_should_sanitize_img_dynsrc_lowsrc,
- test_should_sanitize_img_vbscript,
- test_should_sanitize_invalid_script_tag,
- test_should_sanitize_invalid_tag_names,
- test_should_sanitize_invalid_tag_names_in_single_tags,
- test_should_sanitize_neverending_attribute,
- test_should_sanitize_non_alpha_and_non_digit_characters_in_tags,
- test_should_sanitize_script_tag_with_multiple_open_brackets,
- test_should_sanitize_tag_broken_up_by_null,
- test_should_sanitize_unclosed_script,
- test_should_sanitize_unterminated_cdata_section,
- test_should_sanitize_with_trailing_space,
- test_should_sanitize_xul_style_attributes,
- test_strip_links,
- test_strip_tags,
- test_strip_tags_with_quote,
- test_x03a
Attributes
| [RW] | logger |
Instance Public methods
setup()
Link
test_allow_colons_in_path_component()
Link
RFC 3986, sec 4.2
test_sanitize_form()
Link
test_sanitize_image_src()
Link
# File actionpack/test/template/html-scanner/sanitizer_test.rb, line 70 def test_sanitize_image_src raw = %Q{src="javascript:bang" <img src="javascript:bang" width="5">foo</img>, <span src="javascript:bang">bar</span>} assert_sanitized raw, %Q{src="javascript:bang" <img width="5">foo</img>, <span>bar</span>} end
test_sanitize_javascript_href()
Link
# File actionpack/test/template/html-scanner/sanitizer_test.rb, line 65 def test_sanitize_javascript_href raw = %Q{href="javascript:bang" <a href="javascript:bang" name="hello">foo</a>, <span href="javascript:bang">bar</span>} assert_sanitized raw, %Q{href="javascript:bang" <a name="hello">foo</a>, <span>bar</span>} end
test_sanitize_js_handlers()
Link
TODO: Clean up
# File actionpack/test/template/html-scanner/sanitizer_test.rb, line 60 def test_sanitize_js_handlers raw = %Q{onthis="do that" <a href="#" onclick="hello" name="foo" onbogus="remove me">hello</a>} assert_sanitized raw, %Q{onthis="do that" <a name="foo" href="#">hello</a>} end
test_sanitize_plaintext()
Link
test_sanitize_script()
Link
test_should_accept_good_protocols()
Link
# File actionpack/test/template/html-scanner/sanitizer_test.rb, line 149 def test_should_accept_good_protocols sanitizer = HTML::WhiteListSanitizer.new HTML::WhiteListSanitizer.allowed_protocols.each do |proto| assert !sanitizer.send(:contains_bad_protocols?, 'src', "#{proto}://good") end end
test_should_accept_good_protocols_ignoring_case()
Link
# File actionpack/test/template/html-scanner/sanitizer_test.rb, line 142 def test_should_accept_good_protocols_ignoring_case sanitizer = HTML::WhiteListSanitizer.new HTML::WhiteListSanitizer.allowed_protocols.each do |proto| assert !sanitizer.send(:contains_bad_protocols?, 'src', "#{proto.capitalize}://good") end end
test_should_allow_anchors()
Link
test_should_block_script_tag()
Link
test_should_flag_bad_protocols()
Link
# File actionpack/test/template/html-scanner/sanitizer_test.rb, line 135 def test_should_flag_bad_protocols sanitizer = HTML::WhiteListSanitizer.new %w(about chrome data disk hcp help javascript livescript lynxcgi lynxexec ms-help ms-its mhtml mocha opera res resource shell vbscript view-source vnd.ms.radio wysiwyg).each do |proto| assert sanitizer.send(:contains_bad_protocols?, 'src', "#{proto}://bad") end end
test_should_handle_blank_text()
Link
test_should_handle_non_html()
Link
test_should_not_fall_for_ridiculous_hack()
Link
test_should_not_mangle_urls_with_ampersand()
Link
test_should_reject_hex_codes_in_protocol()
Link
# File actionpack/test/template/html-scanner/sanitizer_test.rb, line 156 def test_should_reject_hex_codes_in_protocol assert_sanitized %Q(<a href="%6A%61%76%61%73%63%72%69%70%74%3A%61%6C%65%72%74%28%22%58%53%53%22%29">1</a>), "<a>1</a>" assert @sanitizer.send(:contains_bad_protocols?, 'src', "%6A%61%76%61%73%63%72%69%70%74%3A%61%6C%65%72%74%28%22%58%53%53%22%29") end
test_should_sanitize_across_newlines()
Link
test_should_sanitize_attributes()
Link
TODO: Clean up
test_should_sanitize_cdata_section()
Link
test_should_sanitize_div_background_image_unicode_encoded()
Link
# File actionpack/test/template/html-scanner/sanitizer_test.rb, line 250 def test_should_sanitize_div_background_image_unicode_encoded raw = %Q(background-image:\0075\0072\006C\0028'\006a\0061\0076\0061\0073\0063\0072\0069\0070\0074\003a\0061\006c\0065\0072\0074\0028.1027\0058.1053\0053\0027\0029'\0029) assert_equal '', sanitize_css(raw) end
test_should_sanitize_div_style_expression()
Link
test_should_sanitize_half_open_scripts()
Link
test_should_sanitize_illegal_style_properties()
Link
# File actionpack/test/template/html-scanner/sanitizer_test.rb, line 217 def test_should_sanitize_illegal_style_properties raw = %Q(display:block; position:absolute; left:0; top:0; width:100%; height:100%; z-index:1; background-color:black; background-image:url(http://www.ragingplatypus.com/i/cam-full.jpg); background-x:center; background-y:center; background-repeat:repeat;) expected = %Q(display: block; width: 100%; height: 100%; background-color: black; background-image: ; background-x: center; background-y: center;) assert_equal expected, sanitize_css(raw) end
test_should_sanitize_img_dynsrc_lowsrc()
Link
test_should_sanitize_img_vbscript()
Link
test_should_sanitize_invalid_script_tag()
Link
test_should_sanitize_invalid_tag_names()
Link
test_should_sanitize_neverending_attribute()
Link
test_should_sanitize_script_tag_with_multiple_open_brackets()
Link
# File actionpack/test/template/html-scanner/sanitizer_test.rb, line 194 def test_should_sanitize_script_tag_with_multiple_open_brackets assert_sanitized %Q(<<SCRIPT>alert("XSS");//<</SCRIPT>), "<" assert_sanitized %Q(<iframe src=http://ha.ckers.org/scriptlet.html\n<a), %Q(<a) end
test_should_sanitize_tag_broken_up_by_null()
Link
test_should_sanitize_unclosed_script()
Link
test_should_sanitize_unterminated_cdata_section()
Link
test_should_sanitize_with_trailing_space()
Link
test_should_sanitize_xul_style_attributes()
Link
test_strip_links()
Link
# File actionpack/test/template/html-scanner/sanitizer_test.rb, line 33 def test_strip_links sanitizer = HTML::LinkSanitizer.new assert_equal "Dont touch me", sanitizer.sanitize("Dont touch me") assert_equal "on my mind\nall day long", sanitizer.sanitize("<a href='almost'>on my mind</a>\n<A href='almost'>all day long</A>") assert_equal "0wn3d", sanitizer.sanitize("<a href='http://www.rubyonrails.com/'><a href='http://www.rubyonrails.com/' onlclick='steal()'>0wn3d</a></a>") assert_equal "Magic", sanitizer.sanitize("<a href='http://www.rubyonrails.com/'>Mag<a href='http://www.ruby-lang.org/'>ic") assert_equal "FrrFox", sanitizer.sanitize("<href onlclick='steal()'>FrrFox</a></href>") assert_equal "My mind\nall <b>day</b> long", sanitizer.sanitize("<a href='almost'>My mind</a>\n<A href='almost'>all <b>day</b> long</A>") assert_equal "all <b>day</b> long", sanitizer.sanitize("<<a>a href='hello'>all <b>day</b> long<</A>/a>") assert_equal "<a<a", sanitizer.sanitize("<a<a") end
test_x03a()
Link
# File actionpack/test/template/html-scanner/sanitizer_test.rb, line 285 def test_x03a assert_sanitized %Q(<a href="javascript:alert('XSS');">), "<a>" assert_sanitized %Q(<a href="javascript:alert('XSS');">), "<a>" assert_sanitized %Q(<a href="http://legit">), %Q(<a href="http://legit">) assert_sanitized %Q(<a href="javascript:alert('XSS');">), "<a>" assert_sanitized %Q(<a href="javascript:alert('XSS');">), "<a>" assert_sanitized %Q(<a href="http://legit">), %Q(<a href="http://legit">) end
Instance Protected methods
assert_sanitized(input, expected = nil)
Link
# File actionpack/test/template/html-scanner/sanitizer_test.rb, line 295 def assert_sanitized(input, expected = nil) @sanitizer ||= HTML::WhiteListSanitizer.new if input assert_dom_equal expected || input, @sanitizer.sanitize(input) else assert_nil @sanitizer.sanitize(input) end end