Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
Brakeman
提交
b490eca4
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,体验更适合开发者的 AI 搜索 >>
提交
b490eca4
编写于
7月 22, 2014
作者:
J
Justin
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #528 from presidentbeef/fix_sqli_detection_in_nested_string_building
Fix SQLi detection in deeply nested string building
上级
ac2e6f06
48880a5e
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
50 addition
and
13 deletion
+50
-13
lib/brakeman/checks/check_sql.rb
lib/brakeman/checks/check_sql.rb
+21
-12
test/apps/rails4/app/models/account.rb
test/apps/rails4/app/models/account.rb
+16
-0
test/tests/rails4.rb
test/tests/rails4.rb
+13
-1
未找到文件。
lib/brakeman/checks/check_sql.rb
浏览文件 @
b490eca4
...
...
@@ -496,23 +496,32 @@ class Brakeman::CheckSQL < Brakeman::BaseCheck
arg
=
exp
.
first_arg
if
STRING_METHODS
.
include?
method
if
string?
target
check_string_arg
arg
elsif
string?
arg
check_string_arg
target
elsif
call?
target
check_for_string_building
target
elsif
node_type?
target
,
:string_interp
,
:dstr
or
node_type?
arg
,
:string_interp
,
:dstr
check_string_arg
target
and
check_string_arg
arg
end
check_str_target_or_arg
(
target
,
arg
)
or
check_interp_target_or_arg
(
target
,
arg
)
or
check_for_string_building
(
target
)
or
check_for_string_building
(
arg
)
else
nil
end
end
def
check_str_target_or_arg
target
,
arg
if
string?
target
check_string_arg
arg
elsif
string?
arg
check_string_arg
target
end
end
def
check_interp_target_or_arg
target
,
arg
if
node_type?
target
,
:string_interp
,
:dstr
or
node_type?
arg
,
:string_interp
,
:dstr
check_string_arg
target
and
check_string_arg
arg
end
end
def
check_string_arg
exp
if
safe_value?
exp
nil
...
...
test/apps/rails4/app/models/account.rb
浏览文件 @
b490eca4
...
...
@@ -17,4 +17,20 @@ class Account < ActiveRecord::Base
connection
.
select_one
"SELECT * FROM somewhere WHERE x=
#{
connection
.
quote
(
params
[
:x
])
}
"
connection
.
execute
"DELETE FROM stuff WHERE id=
#{
self
.
id
}
"
end
def
lots_of_string_building_sql
sql
=
'SELECT count(*) as account_count, '
+
'FROM account_links stuff_links '
+
"WHERE account_links.stuff_id =
#{
@stuff
.
id
}
"
if
params
[
:more_ids
]
sql
+=
" AND stuff IN "
+
"(SELECT something_id "
+
"FROM some_join_thing "
+
"WHERE something_id IN (
#{
params
[
:more_ids
].
join
(
','
)
}
))"
end
sql
+=
"GROUP BY title, id "
Account
.
connection
.
select_all
(
sql
)
end
end
test/tests/rails4.rb
浏览文件 @
b490eca4
...
...
@@ -15,7 +15,7 @@ class Rails4Tests < Test::Unit::TestCase
:controller
=>
0
,
:model
=>
1
,
:template
=>
2
,
:generic
=>
3
1
:generic
=>
3
2
}
end
...
...
@@ -440,6 +440,18 @@ class Rails4Tests < Test::Unit::TestCase
:user_input
=>
nil
end
def
test_sql_injection_in_chained_string_building
assert_warning
:type
=>
:warning
,
:warning_code
=>
0
,
:fingerprint
=>
"6109b24aecaa204463bcebeb594becfe06d5f3c40cfe092b54a4c5146273e134"
,
:warning_type
=>
"SQL Injection"
,
:line
=>
34
,
:message
=>
/^Possible\ SQL\ injection/
,
:confidence
=>
0
,
:relative_path
=>
"app/models/account.rb"
,
:user_input
=>
s
(
:call
,
s
(
:call
,
s
(
:params
),
:[]
,
s
(
:lit
,
:more_ids
)),
:join
,
s
(
:str
,
","
))
end
def
test_sql_injection_CVE_2013_6417
assert_warning
:type
=>
:warning
,
:warning_code
=>
69
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录