sni*_*tko 18 google-chrome ruby-on-rails ruby-on-rails-4
谷歌浏览器中有一种奇怪的行为,这个问题也有描述:rails重定向到'data:,'
当创建新资源并且我的控制器重定向到show动作时,chrome会'data:,'
在地址栏中启动加载空白页面.提出上述问题的作者的答复如下:
这是一项安全功能,新页面的HTML内容与Chrome阻止的提交表单的HTML内容相匹配.
但是没有解释如何修复它.该行为仅存在于Chrome浏览器中.
tal*_*ski 10
我一直在谷歌搜索它,发现在Rails 4.0中使用iframe编辑帖子导致重定向到"data:"
Rails 4现在为所有请求设置X-XSS-Protection标头,因此iframe在表单提交后启动了Chrome中的XSS保护.(https://github.com/elektronaut/sugar/issues/41#issuecomment-25987368)
解决方案,将其添加到您的控制器:
before_filter :disable_xss_protection
protected
def disable_xss_protection
# Disabling this is probably not a good idea,
# but the header causes Chrome to choke when being
# redirected back after a submit and the page contains an iframe.
response.headers['X-XSS-Protection'] = "0"
end
Run Code Online (Sandbox Code Playgroud)
好吧,我想我知道这是什么。您可以在 data: 协议中指定图像和文本,我相信 Chrome 会看到转义的 HTML 并认为它是数据。由于未指定 mime 类型,因此它将冒号后的 mime 类型留空,只打印逗号。
http://guides.rubyonrails.org/security.html#redirection
Rails 4 自动转义 HTML,因此如果您尝试渲染 HTML,则必须指示不转义它。查看渲染选项:
http://guides.rubyonrails.org/security.html#redirection
您可以使用raw()
它来呈现直接 HTML。
http://www.webbydude.com/posts/9-the-h-helper-in-rails-3
归档时间: |
|
查看次数: |
1465 次 |
最近记录: |