5

我在我的应用程序中使用了刹车手来生成扫描报告。它以高置信度生成了许多跨站点脚本安全警告。其中之一是:

Unescaped parameter value rendered inline near line 47: render(text => "Unexpected EventType #{params["EventType"]}", { :status => 406 })
app/controllers/event_controller.rb.

在下面显示的控制器方法中,第一行显示上述警告。

我在链接中看到但无法修复。请帮忙。这是控制器代码:

  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
4

1 回答 1

10

使用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'])}"
于 2016-08-01T15:04:06.433 回答