0

我正在尝试在我的反应应用程序生产服务器上设置头盔安全性。但每当我尝试点击 URL 时。我收到一条错误消息Refused to execute script from 'http://localhost:3000/static/js/app.378bd8b8eee930fb268c.js' because its MIME type ('application/gzip') is not executable, and strict MIME type checking is enabled.

在此处输入图像描述

对于我正在使用的压缩构建compression-webpack-plugin

当我删除helmet. 头盔插件设置:

{"xssFilter": {"setOnOldIE": true}}
4

1 回答 1

1

tl; dr:/static/js/app.378bd8b8eee930fb268c.js正在发送 a Content-Typeofapplication/gzip但它应该是application/javascript.


头盔的作者在这里。这是因为X-Content-Type-Options标题自动设置为nosniff. 这告诉浏览器不要推断文件的类型,并信任Content-Type服务器设置的。

正如您在屏幕截图中看到的那样,有/static/js/app.378bd8b8eee930fb268c.js一个Content-Type. application/gzip浏览器拒绝将其解释为 JavaScript,因为它Content-Type不是——那是在application/javascript起作用的X-Content-Type-Options标头。

您可以通过修复它来解决您的问题——让您的 JavaScript文件Content-Typeapplication/javascript.application/gzip

于 2020-03-19T14:45:50.893 回答