使用attr_accessible和attr_protected修复安全漏洞有哪些风险?

问题描述:

我有一个安全漏洞,建议使用attr_protected调用修复为attr_accessible使用attr_accessible和attr_protected修复安全漏洞有哪些风险?

我在尝试了解进行此更改的风险级别?这被认为是一个重大的变化?

attr_accessible的变化会更安全(不低于),因为你是从

一切访问移动默认和这些的保护

一切由保护默认和这些是可访问

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


因此,例如,与属性: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 
+0

好了,只是为了验证,是一个轨道新手,如果我有以下设置,假设出属性ID,电子邮件,电话号码,zip_code和first_name。要改变它:attr_accessible:id,:email会是:attr_protected:phone_number,:zip_code,:first_name是的?没有?也许? – user1703974 2013-02-27 00:28:52

+0

您是否更改为attr_protected?我认为这是相反的方式? – 2013-02-27 03:41:51

+0

这是!对不起,我甚至会迷惑自己。例如,现在,我的代码是attr_accessible:id,:email。 – user1703974 2013-02-27 15:57:49