我最近对我的应用程序运行了Brakeman gem,其中一个警告是关于我的控制器中的重定向行:
Confidence: High
Warning type: Redirect
Message: Possible unprotected redirect near line xx
在我的控制器的那一行中,我的重定向通知消息包括用户上传的对象的名称:
def update
parent_klass = params[:parent_type].constantize
@entity = parent_klass.find params[:parent_id]
authorize! :update, @entity
entity_param_key = params[:parent_type].downcase.to_sym
@entity.update_attributes params[entity_param_key]
cache_path = begin
if parent_klass == Clinic
clinic_path(@entity)
else
specialist_path(@entity)
end
end
expire_fragment cache_path
redirect_to @entity, :notice => "Successfully updated #{@entity.name}."
end
在这个控制器中,@entity.name
是一个由用户定义的表单值,这意味着理论上有人可以尝试将恶意代码放入该字段。但是我不确定使用该参数生成通知是否存在安全风险。
Flash 通知消息在视图中显示如下(在 HAML 中):
#body.container
.row
#content.span12
#container
- flash.each do |type, msg|
.alert.alert-success= msg
= yield
此控制器模式是否存在安全风险,如果是,我如何在保持自定义通知消息的同时防止它成为安全风险?