[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 ...
随机推荐
- VMWare安装CentOS 7系统 & 操作系统优化
1.准备工作 (1)VMWare 14:https://download3.vmware.com/software/wkst/file/VMware-workstation-full-14.1.1-7 ...
- 三、JMeter实战-快速上手JMeter
1.JMeter基本操作 线JMeter最基本的操作有三个步骤: 先添加一个线程组. 添加HTTP请求. 添加查看结果树. 1.1.添加线程组 在测试计划下新建一个线程组 1.2.添加HTTP请求 在 ...
- 第12组 Beta冲刺 (4/5)
1.1基本情况 ·队名:美少女战士 ·组长博客:https://www.cnblogs.com/yaningscnblogs/p/14016973.html ·作业博客:https://edu.cnb ...
- django_模板层的变量和标签
一.模板层的变量 1.能传递到模板层的数据类型:str(字符串).list(数组).dict(字典).obj(类实例化的对象).fun(函数)等. 2.在模板中使用变量的方法: (1)字符串:{{ 变 ...
- 用for打印九九乘法表
package com.jiemo.struct;public class ForShabi4 { public static void main(String[] args) { //1.先打印第一 ...
- C语言和C++的区别与联系(详细)
文章转自:https://blog.csdn.net/cherrydreamsover/article/details/81835976 在学习了C语言和C++之后,这两者之间的区别我们需要仔细的捋一 ...
- Eclipse's Patching Codes Automatically
如何把等号左边的赋值等式补齐? 想把queryRunner.query(conn, sql,new BeanListHandler<>(type), params); 的等号左边代码(返回 ...
- 红米k40稳定版本刷开发版开启DC调光记录
刷个开发版还要申请资格.要么去淘宝买资格的账号,要么用其他方法: 包21.4.15,直接有有防闪烁功能下载地址:https://bigota.d.miui.com/21.4.15/miui_ALIOT ...
- vue几种插槽的使用方法
参考文档:https://blog.csdn.net/weixin_49217200/article/details/118496525 参考文档:https://blog.csdn.net/ct52 ...
- maven插件汇总
编译Java源码,一般只需设置编译的jdk版本 <plugin> <groupId>org.apache.maven.plugins</groupId> <a ...