[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 ...
随机推荐
- C语言历史与C++的区别
前期演变: C语言的前身是1967年由Martin Richards为开发操作系统和编译器而提出的两种高级程序设计语言BCPL和B.BCPL.Ken Thompson在BCPL的基础上,提出了新的功能 ...
- linux学习之grep
grep 可进行查找内容 如 cat logs/anyproxy.log | grep "2020080321000049" 还可以通过-v 反向过滤 如 tail -f log ...
- Unity 导出设置iOS 项目
别人的代码 xcode打包部分设置的脚本如下 public class XcodeSetting : MonoBehaviour { private static List<Menu> m ...
- NOIP2012普及组
T2]寻宝 读懂题目!! 是逆时针,第几个有钥匙的房间,还有能够直接上楼的是作为第一个有钥匙的房间,而不是就从这里直接上楼了 #include<iostream> #include< ...
- Windows10常用快捷键总结
--Windows10常用快捷键总结 1. Window键: 打开或关闭|开始菜单 2. Win + A 打开操作中心 3. Win + D 显示桌面 4. Win + E 打开计算机文件管理器 5. ...
- js数组原型方法
今天学习了一下js数组原型的操作方法,小结一下学习地址https://www.cnblogs.com/obel/p/7016414.html 1.join() join(separator): 将数组 ...
- Hyper-V 直连主机USB设备
因为授权问题不让用 Vmware 了.所以换成微软自带的 Hyper V 但是碰到一个很头痛的问题,就是外部设备没法像 Vmware 那样直接连接到虚拟机里面,很多第三方设备没法调试了. 找了很久终于 ...
- ERR Client sent AUTH,but no password is set
问题产生原因: 就是Redis服务器没有设置密码,但客户端向其发送了AUTH(authentication,身份验证)请求携带着密码,导致报错. 既然是没有设置密码导致的报错,那我们就把Redis服务 ...
- java map重写 转大写、转驼峰
/** * @author admin * @Description * 转大写 */ public class HashMapUpper<V> extends HashMap<St ...
- JavaScript 字符串和正则相关的方法
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...