Content Security Policy介绍
Content Security Policy
https://content-security-policy.com/
The new
Content-Security-PolicyHTTP response header helps you reduce XSS risks on modern browsers by declaring what dynamic resources are allowed to load via a HTTP Header.
现代浏览器提供的防止XSS攻击的手段。服务器设置此响应头,规定本网站中的网页内容, 执行的内容访问的安全策略。
Directive(指令)
The
Content-Security-Policyheader value is made up of one or more directives (defined below), multiple directives are separated with a semicolon;This documentation is provided based on the Content Security Policy 1.0 W3C Candidate Recommendation
此响应头部值,由一个或者更多的指令构成, 如果是多个指令, 则指令之间以分好隔开。 符合 W3C候选标准。
default-src 'self' cdn.example.com The default-src is the default policy for loading content such as JavaScript, Images, CSS, Font's, AJAX requests, Frames, HTML5 Media. See the Source List Reference for possible values.
规定默认源访问控制策略, 如果是self, 则表示可以引用自己网站的资源, 还可添加指定的其它网站域名。
script-src 'self' js.example.com Defines valid sources of JavaScript.
脚本源访问控制。
<script type="text/javascript" src="xxx"/>
style-src 'self' css.example.com Defines valid sources of stylesheets.
样式资源访问控制。
<link href="//sta.36krcnd.com/36krx2016-front/static/common-ab805c33f6f206dcc85e.css" rel="stylesheet">
img-src 'self' img.example.com Defines valid sources of images.
图片资源访问控制。
<img src="">
connect-src 'self' Applies to XMLHttpRequest (AJAX), WebSocket or EventSource. If not allowed the browser emulates a 400 HTTP status code.
ajax websocket eventsource 访问源控制。
font-src font.example.com Defines valid sources of fonts.
字体资源访问控制。
object-src 'self' Defines valid sources of plugins, eg <object>, <embed> or <applet>.
嵌入式对象资源访问控制。
media-src media.example.com Defines valid sources of audio and video, eg HTML5 <audio>, <video> elements.
媒体源访问控制。
frame-src 'self' Defines valid sources for loading frames. child-src is preferred over this deprecated directive.
框架源访问控制。
child-src 'self' Defines valid sources for web workers and nested browsing contexts loaded using elements such as <frame> and <iframe>
代替frame-src, 确定页面中框架源访问控制。
form-action 'self' Defines valid sources that can be used as a HTML <form> action.
允许表单提交的目标定义。
frame-ancestors 'none' Defines valid sources for embedding the resource using <frame> <iframe> <object> <embed> <applet>. Setting this directive to 'none' should be roughly equivalent to X-Frame-Options: DENY
是否允许本页面被其它页面嵌入的控制。
Source List(源头内容列表)
All of the directives that end with
-srcsupport similar values known as a source list. Multiple source list values can be space separated with the exception of'none'which should be the only value..
以src结尾的指令支持类似的值, 这些值列举如下。 多源头列表值,使用空格分开, 如果只有一个值“none”,则其实唯一的值,不能去其它值并存。
Source Value Example Description
* img-src * Wildcard, allows any URL except data: blob: filesystem: schemes.
允许任何URL,但是不允许 data blob filesystem 方案。
'none' object-src 'none' Prevents loading resources from any source.
不允许从任何源头下载资源。
'self' script-src 'self' Allows loading resources from the same origin (same scheme, host and port).
遵守同源策略。
data: img-src 'self' data: Allows loading resources via the data scheme (eg Base64 encoded images).
允许以data方案加载资源。
domain.example.com img-src domain.example.com Allows loading resources from the specified domain name.
允许从指定域名下载资源。
*.example.com img-src *.example.com Allows loading resources from any subdomain under example.com.
允许加载任何子域名和资源。
https://cdn.com img-src https://cdn.com Allows loading resources only over HTTPS matching the given domain.
允许以https方式加载指定域名的资源。
https: img-src https: Allows loading resources only over HTTPS on any domain.
只允许以https方式加载。
'unsafe-inline' script-src 'unsafe-inline' Allows use of inline source elements such as style attribute, onclick, or script tag bodies (depends on the context of the source it is applied to)
允许使用行内源元素,这里将这些元素定义为 unsafe。
'unsafe-eval' script-src 'unsafe-eval' Allows unsafe dynamic code evaluation such as JavaScript eval()
允许使用不安全的eval接口。
Content Security Policy介绍的更多相关文章
- Content Security Policy (CSP) 介绍
当我不经意间在 Twitter 页面 view source 后,发现了惊喜. <!DOCTYPE html> <html lang="en"> <h ...
- 网页安全政策"(Content Security Policy,缩写 CSP)
作者:阿里聚安全链接:https://www.zhihu.com/question/21979782/answer/122682029来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商业转载 ...
- Content Security Policy的学习理解
以下内容转载自 http://www.cnblogs.com/alisecurity/p/5924023.html 跨域脚本攻击 XSS 是最常见.危害最大的网页安全漏洞. 为了防止它们,要采取很多编 ...
- Content Security Policy (CSP)内容安全策略总结
跨域脚本攻击 XSS 是最常见.危害最大的网页安全漏洞. 为了防止它们,要采取很多编程措施,非常麻烦.很多人提出,能不能根本上解决问题,浏览器自动禁止外部注入恶意脚本?这就是"网页安全政策& ...
- Content Security Policy减少劫持
Content Security Policy减少劫持 什么是CSP? CSP是由单词 Content Security Policy 的首单词组成,是HTML5带给我们的一套全新主动防御的体系,旨在 ...
- Content Security Policy 入门教程
阮一峰文章:Content Security Policy 入门教程
- 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 ...
- options.html:1 Refused to load the script 'xxxx' because it violates the following Content Security Policy directive: "script-src 'self' blob: filesystem: chrome-extension-resource:".
/********************************************************************************* * options.html:1 ...
- Content Security Policy (CSP)内容安全策略
CSP简介 Content Security Policy(CSP),内容(网页)安全策略,为了缓解潜在的跨站脚本问题(XSS攻击),浏览器的扩展程序系统引入了内容安全策略(CSP)这个概念. CSP ...
随机推荐
- 764. Largest Plus Sign
题目大意: 就是一个由1和0组成的正方形矩阵,求里面最大的加号的大小,这个大小就是长度. 什么鬼啊,本来想自己想的,结果看了半天没看懂具体什么意思,然后查了下题解,希望有人说一下意思,结果一上来就是思 ...
- CANOE入门(二)
CAPL就是Communication Application Programming Laguage的缩写,CAPL类似于C语言的语法,因此所有的语法请参考C语言教程,这里不在这里进行详述,关于C语 ...
- 单片机的编程语言和开发环境 LET′S TRY“嵌入式编程”: 3 of 6
单片机的编程语言和开发环境 LET′S TRY“嵌入式编程”: 3 of 6 本连载讲解作为嵌入式系统开发技术人员所必需具备的基础知识.这些基础知识是硬件和软件技术人员都应该掌握的共通技术知识. 在“ ...
- IO 流读取文件时候出现乱码 文件编码格式问题 怎么转换解决方法
在使用下面这个写法时候UTF-8文件编码 在读取时候出现乱码问题. File myFile=new File("文件路径"); BufferedReader in = new Bu ...
- Django 数据库常见操作
首先要配置数据映射具体在这个连接里 https://www.cnblogs.com/Niuxingyu/p/10296143.html Django 建立数据库模型 #导包导入django数据库类 f ...
- django引入模板时,部分css文件渲染不成功失灵引入不成功
今天碰到了一件怪事,下载好的模板,在webstorm中就好好地,但是一引入到pycharm的django项目中就各种失灵,位置错乱. 检查一番,发现该设置的都设置对了啊,而且js文件和css文件还有一 ...
- JS实现选择排序
function selectSort(arr){ var len=arr.length; var temp; for(var i=0;i<len-1;i++){ for(var j=i+1;j ...
- java的零拷贝机制
转:https://blog.csdn.net/zhouhao88410234/article/details/77574689?fps=1&locationNum=9 为何要懂零拷贝原理?因 ...
- STM32F4 ------ RTC
如果只执行 HAL_RTC_GetTime(),读取完后时间不再跑 HAL_RTC_GetTime() 和 HAL_RTC_GetDate()
- Ajxa用在哪些方面(六)
Ajax只有在适当的地方才会用到,也即需要在后台进行大量数据处理(充当消息通知机制),需要频繁的定时或不定时从服务器中读取数据的时候.1.比如我们常接触电子邮件系统中,因为电子邮件系统一般都由电子邮件 ...