Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
Brakeman
提交
64cfeaa0
B
Brakeman
项目概览
李少辉-开发者
/
Brakeman
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
B
Brakeman
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
64cfeaa0
编写于
2月 03, 2014
作者:
J
Justin Collins
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Ignore sanitized SQL in string building
上级
0c37f7de
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
63 addition
and
5 deletion
+63
-5
lib/brakeman/checks/check_sql.rb
lib/brakeman/checks/check_sql.rb
+31
-5
test/apps/rails2/app/models/user.rb
test/apps/rails2/app/models/user.rb
+8
-0
test/tests/rails2.rb
test/tests/rails2.rb
+24
-0
未找到文件。
lib/brakeman/checks/check_sql.rb
浏览文件 @
64cfeaa0
...
@@ -458,13 +458,39 @@ class Brakeman::CheckSQL < Brakeman::BaseCheck
...
@@ -458,13 +458,39 @@ class Brakeman::CheckSQL < Brakeman::BaseCheck
target
=
exp
.
target
target
=
exp
.
target
method
=
exp
.
method
method
=
exp
.
method
if
string?
target
or
string?
exp
.
first_arg
return
exp
if
STRING_METHODS
.
include?
method
if
STRING_METHODS
.
include?
method
elsif
STRING_METHODS
.
include?
method
and
call?
target
if
string?
target
return
unsafe_sql?
target
check_string_arg
exp
.
first_arg
elsif
string?
exp
.
first_arg
check_string_arg
target
elsif
call?
target
check_for_string_building
target
end
else
nil
end
end
end
nil
def
check_string_arg
exp
if
safe_value?
exp
nil
elsif
string_building?
exp
check_for_string_building
exp
elsif
node_type?
exp
,
:string_interp
,
:dstr
check_string_interp
exp
else
exp
end
end
def
string_building?
exp
return
false
unless
call?
exp
and
STRING_METHODS
.
include?
exp
.
method
string?
exp
.
target
or
string?
exp
.
first_arg
or
string_building?
exp
.
target
or
string_building?
exp
.
first_arg
end
end
IGNORE_METHODS_IN_SQL
=
Set
[
:id
,
:merge_conditions
,
:table_name
,
:to_i
,
:to_f
,
IGNORE_METHODS_IN_SQL
=
Set
[
:id
,
:merge_conditions
,
:table_name
,
:to_i
,
:to_f
,
...
...
test/apps/rails2/app/models/user.rb
浏览文件 @
64cfeaa0
...
@@ -30,4 +30,12 @@ class User < ActiveRecord::Base
...
@@ -30,4 +30,12 @@ class User < ActiveRecord::Base
WHERE
WHERE
t.something = '
#{
value
}
')
)
t.something = '
#{
value
}
')
)
end
end
def
self
.
test_sanitized_sql
input
self
.
connection
.
select_all
(
"select * from cool_table where stuff = "
+
self
.
sanitize_sql
(
input
))
end
def
more_sanitized_sql
self
.
connection
.
execute
(
"DELETE FROM cool_table WHERE cool_id="
+
quote_value
(
self
.
cool_id
)
+
" AND my_id="
+
quote_value
(
self
.
id
))
end
end
end
test/tests/rails2.rb
浏览文件 @
64cfeaa0
...
@@ -308,6 +308,30 @@ class Rails2Tests < Test::Unit::TestCase
...
@@ -308,6 +308,30 @@ class Rails2Tests < Test::Unit::TestCase
:relative_path
=>
"app/controllers/home_controller.rb"
:relative_path
=>
"app/controllers/home_controller.rb"
end
end
def
test_sql_injection_false_positive_quote_value
assert_no_warning
:type
=>
:warning
,
:warning_code
=>
0
,
:fingerprint
=>
"6ea8fe3abe8eac86e5ecb790b53fb064b1152b2574b14d9354a40d07269a952e"
,
:warning_type
=>
"SQL Injection"
,
:line
=>
30
,
:message
=>
/^Possible\ SQL\ injection/
,
:confidence
=>
1
,
:relative_path
=>
"app/models/user.rb"
,
:user_input
=>
s
(
:call
,
s
(
:call
,
s
(
:str
,
"DELETE FROM cool_table WHERE cool_id="
),
:
+
,
s
(
:call
,
nil
,
:quote_value
,
s
(
:call
,
s
(
:self
),
:cool_id
))),
:
+
,
s
(
:str
,
" AND my_id="
))
end
def
test_sql_injection_sanitize_sql
assert_no_warning
:type
=>
:warning
,
:warning_code
=>
0
,
:fingerprint
=>
"7481ff666ae949b8442400cf516615ce8b04b87f7e11e33e29d4ad1303d24dd0"
,
:warning_type
=>
"SQL Injection"
,
:line
=>
26
,
:message
=>
/^Possible\ SQL\ injection/
,
:confidence
=>
1
,
:relative_path
=>
"app/models/user.rb"
,
:user_input
=>
s
(
:call
,
s
(
:str
,
"select * from cool_table where stuff = "
),
:
+
,
s
(
:call
,
s
(
:self
),
:sanitize_sql
,
s
(
:lvar
,
:input
)))
end
def
test_csrf_protection
def
test_csrf_protection
assert_warning
:type
=>
:controller
,
assert_warning
:type
=>
:controller
,
:warning_type
=>
"Cross-Site Request Forgery"
,
:warning_type
=>
"Cross-Site Request Forgery"
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录