如何以正确的方式处理Chrome X-XSS-Protection

How to deal with Chrome X-XSS-Protection in a right way?

本文关键字:方式 处理 Chrome X-XSS-Protection      更新时间:2023-09-26

我在Chrome中运行我的应用程序,它有一个错误:

Refused to execute script from 'http://example.com/info?no=31&magic=1184' because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled. 

从这个主题中,我知道应该设置http标头X-XSS-Protection:0

拒绝执行JavaScript脚本。在请求中找到脚本的源代码

我使用RoR将其设置为:

def info
  response.headers['X-XSS-Protection'] = '0'
  # Other logic
end

但结果是,http头仍然是:

X-XSS-Protection:1; mode=block
X-XSS-Protection:0

当我在Firefox中尝试它时,http头是:

X-XSS-Protection    0, 1; mode=block

并且可以完美地奔跑。

为什么它有1; mode=block?如何移除?

这与XSS保护无关。您需要更改上的内容类型HTTP标头http://example.com/info?no=31&magic=1184从text/html到text/javascript。