Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/68.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails Is rails Desive';s';警报';免受XSS攻击?_Ruby On Rails_Ruby_Devise - Fatal编程技术网

Ruby on rails Is rails Desive';s';警报';免受XSS攻击?

Ruby on rails Is rails Desive';s';警报';免受XSS攻击?,ruby-on-rails,ruby,devise,Ruby On Rails,Ruby,Devise,我已经离开并覆盖了designe的designe\u错误消息返回不同格式的响应,如下所示: 然而,我所做的部分工作是将alert的结果包括在内,如下所示: def devise_error_messages! # if there aren't any errors, just return a blank string return '' if (resource.errors.empty? && !alert) # go through each of the

我已经离开并覆盖了designe的
designe\u错误消息developeHelper
模块中的code>返回不同格式的响应,如下所示:

然而,我所做的部分工作是将
alert
的结果包括在内,如下所示:

def devise_error_messages!

  # if there aren't any errors, just return a blank string
  return '' if (resource.errors.empty? && !alert)

  # go through each of the messages and add a <br> onto the back of it
  messages = resource.errors.full_messages.map { |msg| msg << "<br>" }.join

  # if there are also alerts, add that to the end of messages
  if alert
    messages << alert
  end

  # add div around messages
  messages = "<div class='errorbox'>" << messages << "</div>"

  # return messages in an html safe format
  messages.html_safe

end
def设计错误消息!
#如果没有任何错误,只需返回一个空白字符串
如果(resource.errors.empty?&&!alert),则返回“”
#浏览每条信息,并在其背面添加一个

messages=resource.errors.full_messages.map{| msg | msg除非您正在修改设备的消息以添加用户提供的内容,或者使用用户提供的内容指定自定义flash消息,否则无需担心


Devise的所有flash消息都存储在
config/locales/designe.en.yml

中,但这并不完全是一个答案,因为Sevensacat回答说它应该是安全的,尽管我环顾了一下,发现这非常相关,希望它能帮助有类似问题的人

如果我对此非常迂腐,我可以像这样把
alert
放在
h()
里面:

if alert
  messages << h(alert)
end
if警报

警报
从何而来的消息?Desive使用
flash[:alert]
flash[:notice]
发送警告,并且它可以作为
警报
通知
引用。安装Desive gem时,它给出的一个说明是“确保在app/views/layouts/application.html.erb中有flash消息。例如:

“除此之外,不完全确定它来自何处,但它可以工作。谢谢,不过,如果服务器的创建者编写了足够具体的程序,那么在某个时候,
中的
资源
“1错误”会禁止保存此%{resource}吗?”
可能被滥用?我知道用户在我的应用程序中可以做什么不会有问题,不过更多的是出于一般兴趣。
resource
是您的设计模型(例如用户)的名称,所以它不会真的有问题。不过,有时您可能希望将自己的HTML放在flash消息中。