提交 e92bf6d5 编写于 作者: J Justin

Merge pull request #675 from presidentbeef/html_safe_is_like_raw

Treat String#html_safe the same as raw()
...@@ -57,8 +57,12 @@ class Brakeman::CheckCrossSiteScripting < Brakeman::BaseCheck ...@@ -57,8 +57,12 @@ class Brakeman::CheckCrossSiteScripting < Brakeman::BaseCheck
if exp.node_type == :output if exp.node_type == :output
out = exp.value out = exp.value
elsif exp.node_type == :escaped_output and raw_call? exp elsif exp.node_type == :escaped_output
out = exp.value.first_arg if raw_call? exp
out = exp.value.first_arg
elsif html_safe_call? exp
out = exp.value.target
end
end end
return if call? out and ignore_call? out.target, out.method return if call? out and ignore_call? out.target, out.method
...@@ -143,8 +147,12 @@ class Brakeman::CheckCrossSiteScripting < Brakeman::BaseCheck ...@@ -143,8 +147,12 @@ class Brakeman::CheckCrossSiteScripting < Brakeman::BaseCheck
#Otherwise, ignore #Otherwise, ignore
def process_escaped_output exp def process_escaped_output exp
unless check_for_immediate_xss exp unless check_for_immediate_xss exp
if raw_call? exp and not duplicate? exp if not duplicate? exp
process exp.value.first_arg if raw_call? exp
process exp.value.first_arg
elsif html_safe_call? exp
process exp.value.target
end
end end
end end
exp exp
...@@ -327,6 +335,10 @@ class Brakeman::CheckCrossSiteScripting < Brakeman::BaseCheck ...@@ -327,6 +335,10 @@ class Brakeman::CheckCrossSiteScripting < Brakeman::BaseCheck
exp.value.node_type == :call and exp.value.method == :raw exp.value.node_type == :call and exp.value.method == :raw
end end
def html_safe_call? exp
exp.value.node_type == :call and exp.value.method == :html_safe
end
def ignore_call? target, method def ignore_call? target, method
ignored_method?(target, method) or ignored_method?(target, method) or
safe_input_attribute?(target, method) or safe_input_attribute?(target, method) or
......
...@@ -13,7 +13,7 @@ class Rails4Tests < Test::Unit::TestCase ...@@ -13,7 +13,7 @@ class Rails4Tests < Test::Unit::TestCase
@expected ||= { @expected ||= {
:controller => 0, :controller => 0,
:model => 2, :model => 2,
:template => 6, :template => 7,
:generic => 61 :generic => 61
} }
end end
...@@ -572,6 +572,18 @@ class Rails4Tests < Test::Unit::TestCase ...@@ -572,6 +572,18 @@ class Rails4Tests < Test::Unit::TestCase
:user_input => nil :user_input => nil
end end
def test_cross_site_scripting_with_html_safe
assert_warning :type => :template,
:warning_code => 2,
:fingerprint => "b04cfd8d120b773a3e9f70af8762f7efa7c5ca5c7f83136131d6cc75259cd429",
:warning_type => "Cross Site Scripting",
:line => 1,
:message => /^Unescaped\ parameter\ value/,
:confidence => 0,
:relative_path => "app/views/another/html_safe_is_not.html.erb",
:user_input => nil
end
def test_xss_haml_line_number def test_xss_haml_line_number
assert_warning :type => :template, assert_warning :type => :template,
:warning_code => 2, :warning_code => 2,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册