2016-08-01 36 views
0

我在我的应用程序中使用了brakeman来生成扫描报告。它以高可信度生成了许多跨站脚本安全警告。 在它们中的一个是:如何修复brakeman生成的rails中的Cross Site Scripting安全警告?

直列邻近线47呈现未逸出参数值:呈现(文本=> “意外的EventType#{PARAMS [” 的EventType “]}”,{:状态=> 406}) 应用/controllers/event_controller.rb。 在下面显示的控制器方法中,第一行显示上述警告。

我在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 

回答

2

当使用render :text => ...滑轨仍然呈现输出作为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'])}"