我使用制动器在我的应用程序中生成扫描报告。它以高可信度生成了许多Cross Site Scripting安全警告。 其中一个是:
在第47行附近内联呈现的非转义参数值:render(text =>“Unexpected EventType#{params [”EventType“]}”,{:status => 406}) 应用程序/控制器/ event_controller.rb。 在下面显示的控制器方法中,第1行显示上述警告。
我在link看过但无法修复。请帮忙。 这是控制器代码:
def purchase
render :status => 406, :text => "Unexpected EventType #{params['EventType']}" and return unless params['EventType'] == 'purchased'
@account = Account.new
render :status => 406, :text => "Could not find Plan #{params['Plan']}" and return unless @account.plan = @plan = SubscriptionPlan.find_by_name(params['Plan'])
end
答案 0 :(得分:6)
使用render :text => ...
时,Rails仍将输出呈现为HTML(内容类型为text/html
)。由于您的代码将用户输入(params['EventType']
)直接放在输出中,因此这是一个典型的跨站点脚本漏洞。
您有两种选择。请改用render :plain
(将使用内容类型text/plain
而非HTML呈现):
render :status => 406, :plain => "Unexpected EventType #{params['EventType']}"
或转义用户输入:
render :status => 406, :text => "Unexpected EventType #{ERB::Util.html_escape(params['EventType'])}"