[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 ...
随机推荐
- centos7.6镜像
centos7.6镜像 https://archive.kernel.org/centos-vault/7.6.1810/isos/x86_64/
- PVE设置定时关闭、启动虚拟机
shell中输入命令: crontab -e 进入对应cron 添加命令: 例如: 00 2 * * * pvesh create /nodes/pve/qemu/102/status/stop 00 ...
- Offer 提速:如何写出有亮点的简历
先来个灵魂拷问: 你与他人相比,有什么能形成明显区分度的优势条件? 这里有两个层面的问题,一是 如何识别出你的优势条件,毕竟大多数人大多数时候可能都是在做业务,临到写简历的时候要求总结日常工作中跟别人 ...
- JAVA 、Http协议:
JAVA如何配置服务器: Http协议: 1.什么是Http协议 HTTP,超文本传输协议(HyperText Transfer Protocol)是互联网上应用最为广泛的 一种网络协议.所有的W ...
- 弹框tabel树
<template> <div> <el-dialog :title="title" :visible.sync="dialogVisibl ...
- 十大经典排序之堆排序(C++实现)
堆排序 通过将无序表转化为堆,可以直接找到表中最大值或者最小值,然后将其提取出来,令剩余的记录再重建一个堆, 取出次大值或者次小值,如此反复执行就可以得到一个有序序列,此过程为堆排序. 思路: 1.创 ...
- html页面间传递参数
$.query.get("id") jquery.params.js代码 /** * jQuery.query - Query String Modification and Cr ...
- vue使用keepalive缓存上级页面
参考: vue单页应用前进刷新后退不刷新方案探讨 vue,vue-router实现浏览器返回不刷新页面 vue 怎么处理当this.$router.go(-1)时,判断返回指定页面设置指定页面的kee ...
- Flink学习系列——简介
Flink起源 德国柏林 Flink的目标 低延迟 高吞吐 较高的准确性(乱序数据的处理) 良好的容错性(容错性差的表现:一个节点挂了,全部回滚重新做计算,这对实时性要求高的场景非常致命)
- MapReduce实践
1. 词频统计任务要求 首先,在Linux系统本地创建两个文件,即文件wordfile1.txt和wordfile2.txt.在实际应用中,这两个文件可能会非常大,会被分布存储到多个节点上.但是,为了 ...