Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
Brakeman
提交
53bbaf85
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 搜索 >>
提交
53bbaf85
编写于
4月 30, 2015
作者:
J
Justin Collins
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Ignore more Arel calls
Fixes #604
上级
e626fdc3
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
46 addition
and
1 deletion
+46
-1
lib/brakeman/checks/check_sql.rb
lib/brakeman/checks/check_sql.rb
+8
-1
test/apps/rails4/app/models/user.rb
test/apps/rails4/app/models/user.rb
+9
-0
test/tests/rails4.rb
test/tests/rails4.rb
+29
-0
未找到文件。
lib/brakeman/checks/check_sql.rb
浏览文件 @
53bbaf85
...
...
@@ -551,7 +551,7 @@ class Brakeman::CheckSQL < Brakeman::BaseCheck
:sanitize_sql
,
:sanitize_sql_array
,
:sanitize_sql_for_assignment
,
:sanitize_sql_for_conditions
,
:sanitize_sql_hash
,
:sanitize_sql_hash_for_assignment
,
:sanitize_sql_hash_for_conditions
,
:to_sql
,
:sanitize
,
:
exists
,
:
primary_key
,
:table_name_prefix
,
:table_name_suffix
]
:to_sql
,
:sanitize
,
:primary_key
,
:table_name_prefix
,
:table_name_suffix
]
def
safe_value?
exp
return
true
unless
sexp?
exp
...
...
@@ -565,6 +565,7 @@ class Brakeman::CheckSQL < Brakeman::BaseCheck
else
IGNORE_METHODS_IN_SQL
.
include?
exp
.
method
or
quote_call?
exp
or
arel?
exp
or
exp
.
method
.
to_s
.
end_with?
"_id"
end
when
:if
...
...
@@ -588,6 +589,12 @@ class Brakeman::CheckSQL < Brakeman::BaseCheck
end
end
AREL_METHODS
=
[
:not
,
:and
,
:or
,
:exists
,
:join_sources
,
:arel_table
,
:gt
,
:lt
,
:on
,
:eq
,
:eq_any
,
:where
]
def
arel?
exp
call?
exp
and
(
AREL_METHODS
.
include?
exp
.
method
or
arel?
exp
.
target
)
end
#Check call for string building
def
check_call
exp
return
unless
call?
exp
...
...
test/apps/rails4/app/models/user.rb
浏览文件 @
53bbaf85
...
...
@@ -23,4 +23,13 @@ class User < ActiveRecord::Base
end
order
(
ordering
)
# should not warn about `asc` interpolation
}
def
much_arel
# None of these should warn
group_recipient
=
User
.
joins
(
:group
).
where
(
User
.
arel_table
[
:message_id
].
eq
Email
.
arel_table
[
:id
])
group_with_special_property
=
group_recipient
.
where
(
:groups
=>
{
:private
=>
false
,
:special_property
=>
true
})
Email
.
where
(
group_recipient
.
exists
.
not
.
or
(
group_with_special_property
.
exists
))
User
.
select
(
'users.id'
).
joins
(
User
.
joins
(
:deal_purchases
).
join_sources
).
where
(
Email
.
arel_table
[
:created_at
].
gt
(
last_activity
)).
group
(
'users.id'
)
User
.
where
(
User
.
joins
(
:group
).
where
(
User
.
arel_table
[
:message_id
].
eq
arel_table
[
:id
]))
end
end
test/tests/rails4.rb
浏览文件 @
53bbaf85
...
...
@@ -643,6 +643,35 @@ class Rails4Tests < Test::Unit::TestCase
:user_input
=>
s
(
:lvar
,
:locale
)
end
def
test_no_sql_injection_from_arel_methods
assert_no_warning
:type
=>
:warning
,
:warning_code
=>
0
,
:fingerprint
=>
"61d957cdeca70a82f53d7ec72287fc21f67c67c6e8dbc9c3c4cb2d115f3a5602"
,
:warning_type
=>
"SQL Injection"
,
:line
=>
30
,
:message
=>
/^Possible\ SQL\ injection/
,
:confidence
=>
0
,
:relative_path
=>
"app/models/user.rb"
assert_no_warning
:type
=>
:warning
,
:warning_code
=>
0
,
:fingerprint
=>
"46a08db9c5b2739027a34c37cbb79c0813247e5bba856705a56174173e230f4b"
,
:warning_type
=>
"SQL Injection"
,
:line
=>
32
,
:message
=>
/^Possible\ SQL\ injection/
,
:confidence
=>
0
,
:relative_path
=>
"app/models/user.rb"
assert_no_warning
:type
=>
:warning
,
:warning_code
=>
0
,
:fingerprint
=>
"64233e939bcef59cf6100c75cfefaf2968734305d4431622556e2f612b10a912"
,
:warning_type
=>
"SQL Injection"
,
:line
=>
33
,
:message
=>
/^Possible\ SQL\ injection/
,
:confidence
=>
0
,
:relative_path
=>
"app/models/user.rb"
end
def
test_format_validation_model_alias_processing
assert_warning
:type
=>
:model
,
:warning_code
=>
30
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录