[WEB]对于"Refused to execute script from 'http://xx.xx.xx/yy/zz.js' because its MIME type ('') is not executable, and strict MIME type checking is enabled."问题的解决办法
1 文由
阶段一:对WEB服务器HTTP通信的header设置了安全头(X-Content-Options:nosniff)
两个月前协助交付侧大哥处理、修复一个三级等保项目的第三方安全公司释出的安全漏洞,其中有1个低危漏洞(如下图示)涉及到对HTTP的header设置安全头(X-Frame-Options / X-XSS-Protection / X-Content-Options)。

[漏洞报告]
远程网络应用程序未设置X-Content-Options响应头。
X-Content-Options是Microsoft提出的一种缓解MIME类型攻击的方式,并且已经在Chrome和Safari中实现。
HTTP相应头X-Content-Options:nosniff
[解决思路]
按照风险报告上的建议在nginx返回头中增加了:X-Content-Type-Options:nosniff
针对这一漏洞的对应header的安全头的配置,在Tomcat服务器和Nginx服务器上如何实现,已在博主两个月前的这篇博文可见:

[/usr/local/nginx/conf/nginx.conf]
http {
...
add_header X-Frame-Options "SAMEORIGIN"; #或 add_header X-Frame-Options SAMEORIGIN;
add_header X-XSS-Protection "1; mode=block";
add_header X-Content-Type-Options "nosniff";
...
}
阶段二:web服务报错"Refused to execute script from 'http://xx.xx.xx/yy/zz.js' because its MIME type ('') is not executable, and strict MIME type checking is enabled."
万万没想到的是,今天交付侧大哥跟我说这项目中某个web服务用不了了,这个web服务通过js的ajax请求发出的动态式加载的静态文件加载不出来了。经过一番排查,发现浏览器报了这个错:



2 原因分析
那么,是什么原因导致的捏?(你 dong 滴)
咱们先翻译翻译下面这段报错信息:
Refused to execute script from 'http://xx.xx.xx/yy/zz.js' because its MIME type ('') is not executable, and strict MIME type checking is enabled.
javascript请求的内容返回的MIME类型为'',不是可执行的文件,目前已启用了严格的MIME类型检查。(故而,该文件加载失败)
好啦,这下其实咱们也能猜出个三七二十一了。
nginx WEB服务器配置了(X-Content-Type-Options: nosniff),其禁用了通信终端对WEB服务器端所支持的MIME(Multipurpose Internet Mail Extensions,多用途互联网邮件扩展类型)的嗅探。
同时,也导致了自动识别MIME类型被关闭了,无法自动识别文件类型。
进而导致:前端使用ajax动态加载js/css文件到html网页中时,header返回的content-type为''类型,与文件类型本身(application/javascript; text/css)不匹配,被禁止加载。
3 解决方案
方案1: 取消 X-Content-Options:nosniff 配置
- 【nginx】

- 【Tomcat】
<filter>
<filter-name>httpHeaderSecurity</filter-name>
<filter-class>org.apache.catalina.filters.HttpHeaderSecurityFilter</filter-class>
<async-supported>true</async-supported>
<init-param>
<param-name>blockContentTypeSniffingEnabled</param-name> //配置行1
<param-value>false</param-value> //配置行2
</init-param>
</filter>
方案2:给HTTP通信中的html/js/css等文件的响应头header中主动添加文件类型
[Java]
HTTPServletResponse.setContentType(String mimetype); //"text/html;charset=UTF-8"
HTTPServletResponse.addHeader(String name;String value); //"content-type", "text/javascript; charset=uft-8"
HTTPServletResponse.response.setHeader(String name;String value); //"content-type", "text/javascript; charset=uft-8"
[PHP]
header("content-type:text/javascript; charset=uft-8");
X 推进与参考文献
- 对于“Refused to execute script from ” because its MIME type (‘text/html’) is not executable, and strict MIME type checking is enabled.”问题的解决办法 - luoxiao123
- 对于错误“Refused to execute script from '...' because its MIME type ('') is not executable, and strict MIME type checking is enabled.”的处理 - 博客园
- because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled. - 博客园
[WEB]对于"Refused to execute script from 'http://xx.xx.xx/yy/zz.js' because its MIME type ('') is not executable, and strict MIME type checking is enabled."问题的解决办法的更多相关文章
- 对于错误“Refused to execute script from '...' because its MIME type ('') is not executable, and strict MIME type checking is enabled.”的处理。
今天在是用公司的报表插件Stimulsoft时发现的问题.之前可以正常使用,突然不能加载了.查看发现得到这个错误. 查看请求头 可以看到,请求正常响应,但是发现 Content-Type是空的,但是引 ...
- Refused to execute script from '...' because its MIME type ('') is not executable, and strict MIME type checking is enabled.
写在前面 部署项目到weblogic上启动首页访问空白, 浏览器控制台报如题错误. web.xml中把响应头添加防止攻击的报文过滤器禁用就行了(仅仅是为了启动), 以下为转载内容, 可以根据需要自行测 ...
- Refused to execute script from '....js' because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled.md
目录 问题描述 解决过程 总结 问题描述 在整合 Spring Boot.Spring Security.Thymeleaf 的练习中,对页面进行调试时,发现如下错误提示: Refused to ex ...
- 当web.config文件放置在共享目录下(UNC),启动IIS会提示有错误信息500.19,伴随有错误代码0x80070003和错误代码0x80070005的解决办法
最近遇到一个很有意思的使用环境,操作人员将所有的网站应用内容投放到共享存储里面,并且使用微软的SMB协议将其以CIFS的方式共享出来,使用Windows Server 2008 R2的IIS将其连接起 ...
- 'DataVisualization' does not exist in the namespace 'System.Web.UI'一例解决办法
之前项目是vs2010 aspx项目,用vs2017打开后,非运行状态下有一行错误:CS0234 C# The type or namespace name 'DataVisualization' d ...
- Eclipse中发布Maven管理的Web项目时找不到类的问题根源和解决办法(转)
转自:http://blog.csdn.net/lvguanming/article/details/37812579?locationNum=12 写在前面的话 现在是越来越太原讨厌Eclipse这 ...
- [Matlab] Attempt to execute SCRIPT *** as a function
Attempt to execute SCRIPT *** as a function 问题: 在运行MATLAB程序的时候,出现如题的报错. 原因: 在系统中,现有的.m文件有的与***函数重名,所 ...
- Refused to execute inline event handler because it violates the following Content Security Policy directive: "xxx". Either the 'unsafe-inline' keyword, a hash ('sha256-...'), or a nonce ('nonce-...')
/********************************************************************************* * Refused to exec ...
- matlab: Attempt to execute SCRIPT *** as a function 错误
编写matlab程序时,出现了“Attempt to execute SCRIPT mean as a function”,其实这是“Attempt to execute SCRIPT *** as ...
- 【解决】MacOS下 Python3.7 使用 pyinstaller 打包后执行报错 Failed to execute script pyi_rth__tkinter
Fix tcl/tk libs inclusion in tkinter with Python3.7 under MacOS 使用 Pyinstaller 打包时候报错 3027 ERROR: Tc ...
随机推荐
- JAVA基础Day3-用户交互Scanner/顺序结构/选择结构/循环结构
一.用户交互Scanner JAVA提供了一个工具类,可以用来获取用户的输入. java.util.Scanner是Java5的新特征,可以通过Scanner类来获取用户的输入. 基本语法: Scan ...
- js 将多层json对象 转化为一层json
const parse = data => { const uid = `uid_${Date.now()}`; const process = (input, prefix = '', jso ...
- 第五章 散列表(哈希表)(hash表)
散列表 特点 键和值一一对应 可以快速找到对应值,不需要进行查找 运用场景 模拟映射关系 防止重复 缓存记住数据,以免服务器再通过处理来生成它们 例如: 电话簿 用缓存记录url和对应的静态页面,存在 ...
- Integer类自动拆箱,装箱解析
1.自动拆箱 例1: int i1 = 10; Integer i2 = new Integer(10); System.out.println(i1 == i2); 这个结果是true i1为基本数 ...
- .net Core5.0使用IdentityServer4 进行权限控制
.net Core5.0使用IdentityServer4 进行权限控制 IdentityServer4 ASP.NET Core的一个包含OpenID Connect和OAuth 2.0协议的框架 ...
- gongwen
gongwen 学号 姓名 工作占比 20201307 梁辰鱼 20% 20201323 谭顺心 17% 20201222 龚 杰 16.5% 20201325 夏俊睿 16% 20201317 鲁永 ...
- spring事件发布与监听
一.组成部分 spring的事件监听有三个部分组成,事件(ApplicationEvent).监听器(ApplicationListener)和事件发布操作. 二.具体实现 事件 事件对象就是一个简单 ...
- 记录linux上无法和本地传输文件
在学习docker搭建nacos的过程中,涉及到上传本地文件,但是包括从xshell直接拖拽还是xftp上传,都是失败, 最后百度查找多种不同的结果,最后实验下来是文件夹没有权限的问题. 解决步骤如下 ...
- 解决ssh $host jps bash: jps: command not found 问题
问题描述 使用 ssh $host jps 命令报错,连本机也会有这样的情况,但是分开使用并没有问题,即ssh $host下执行jps命令并不会报错. 原因 因为ssh远程连接到服务器的环境变量中不包 ...
- MOBIUS: Towards the Next Generation of Query-Ad Matching in Baidu's Sponsored Search——百度下一代搜索广告系统
简介 传统的广告最终的呈现需要经过召回与排序两个阶段,百度的搜索架构则采用三层漏斗状,如图1所示.最上面的一层用于筛选出和用户查询最相关的一部分广告,将整个候选广告集从亿级降到千级:下面两层是排序阶段 ...