0

我有一个安全漏洞,建议修复从使用attr_protected调用切换到attr_accessible.

我试图了解进行此更改的风险程度?这是否被认为是一个重大变化?

4

1 回答 1

0

更改为attr_accessible将更安全(而不是更少),因为您正在从

默认情况下可访问的所有内容,并且这些内容受到保护

默认情况下受保护的所有内容,这些都可以访问

主要风险是您将破坏所有现有表单......除非您将属性明确设置为可访问,或明确设置类上的每个受保护属性。


例如,使用属性:id, email, phone number, zip_code and first_name 这两个将导致现有属性的相同行为

# only protect these two attributes, everything else is open season
# a new attribute will start out accessible by default
attr_protected :id, :email

# only these attributes are accessible - everything else is protected
# a new attribute will start out protected by default
attr_accessible :first_name, :zip_code, :phone_number
于 2013-02-26T00:05:17.027 回答