Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
Brakeman
提交
2d2a9772
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 搜索 >>
提交
2d2a9772
编写于
8月 19, 2013
作者:
J
Justin Collins
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Do not warn on "dangerous" attributes using roles
fixes #372
上级
6bd236d6
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
24 addition
and
3 deletion
+24
-3
lib/brakeman/checks/check_model_attr_accessible.rb
lib/brakeman/checks/check_model_attr_accessible.rb
+9
-3
lib/brakeman/processors/model_processor.rb
lib/brakeman/processors/model_processor.rb
+3
-0
test/apps/rails3.1/app/models/user.rb
test/apps/rails3.1/app/models/user.rb
+2
-0
test/tests/rails31.rb
test/tests/rails31.rb
+10
-0
未找到文件。
lib/brakeman/checks/check_model_attr_accessible.rb
浏览文件 @
2d2a9772
...
...
@@ -20,8 +20,9 @@ class Brakeman::CheckModelAttrAccessible < Brakeman::BaseCheck
def
run_check
check_models
do
|
name
,
model
|
accessible_attrs
=
model
[
:attr_accessible
]
accessible_attrs
.
each
do
|
attribute
|
model
[
:attr_accessible
].
each
do
|
attribute
|
next
if
role_limited?
model
,
attribute
SUSP_ATTRS
.
each
do
|
susp_attr
,
confidence
|
if
susp_attr
.
is_a?
(
Regexp
)
and
susp_attr
=~
attribute
.
to_s
or
susp_attr
==
attribute
warn
:model
=>
name
,
...
...
@@ -37,6 +38,12 @@ class Brakeman::CheckModelAttrAccessible < Brakeman::BaseCheck
end
end
def
role_limited?
model
,
attribute
role_accessible
=
model
[
:options
][
:role_accessible
]
return
if
role_accessible
.
nil?
role_accessible
.
include?
attribute
end
def
check_models
tracker
.
models
.
each
do
|
name
,
model
|
if
!
model
[
:attr_accessible
].
nil?
...
...
@@ -44,5 +51,4 @@ class Brakeman::CheckModelAttrAccessible < Brakeman::BaseCheck
end
end
end
end
lib/brakeman/processors/model_processor.rb
浏览文件 @
2d2a9772
...
...
@@ -85,6 +85,9 @@ class Brakeman::ModelProcessor < Brakeman::BaseProcessor
exp
.
each_arg
do
|
e
|
if
node_type?
e
,
:lit
args
<<
e
.
value
elsif
hash
?
e
@model
[
:options
][:
role_accessible
]
||=
[]
@model
[
:options
][
:role_accessible
].
concat
args
end
end
...
...
test/apps/rails3.1/app/models/user.rb
浏览文件 @
2d2a9772
...
...
@@ -25,4 +25,6 @@ class User < ActiveRecord::Base
scope
:all
belongs_to
:account
attr_accessible
:admin
,
:as
=>
:admin
end
test/tests/rails31.rb
浏览文件 @
2d2a9772
...
...
@@ -1033,4 +1033,14 @@ class Rails31Tests < Test::Unit::TestCase
:confidence
=>
1
,
:relative_path
=>
"app/controllers/other_controller.rb"
end
def
test_attr_accessible_with_role
assert_no_warning
:type
=>
:model
,
:warning_code
=>
17
,
:fingerprint
=>
"77c353ad8e5fc9880775ed436bbfa37b005b43aa2978186de92b6916f46fac39"
,
:warning_type
=>
"Mass Assignment"
,
:message
=>
/^Potentially\ dangerous\ attribute\ admin\ av/
,
:confidence
=>
0
,
:relative_path
=>
"app/models/user.rb"
end
end
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录