首页
导航
博客
电子书
算法
众创
代码
随贴
关于我们
您好,欢迎来到码863代码分享网! 请
[登录]
/
[注册]
搜 索
标题:
*
140
字
TAG标签:
(用空格隔开)
30
字
恢复历史版本:
请选择分类
html
python
javascript
php
sql
c
c++
c#
java
plain
所有人可见
仅自己可见
编辑器:UEditor
编辑器:TinyMCE
编辑器:Editor.md
HTML转MD
HTML转MD2
<p><span style="white-space:pre"> </span>if(IS_SSL) header('Strict-Transport-Security: max-age=31536000');</p><p><span style="white-space:pre"> </span>header('X-Frame-Options: SAMEORIGIN');</p><p><span style="white-space:pre"> </span>header('X-XSS-Protection: 1; mode=block');</p><p><span style="white-space:pre"> </span>header('X-Content-Type-Options: nosniff');</p><p><br/></p><p style="margin-top: 8px; margin-bottom: 8px; padding: 0px 0px 8px; font-family: Arial; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255); line-height: 21.6px;"><em><strong>1.CONTENT-SECURITY-POLICY(内容安全策略)</strong></em></p><p style="margin-top: 8px; margin-bottom: 8px; padding: 0px 0px 8px; font-family: Arial; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255); line-height: 21.6px;"><strong>为什么使用:</strong><br/>怎么尽可能不遭受XSS攻击呢?众所周知,XSS攻击是指恶意攻击者往Web页面里插入恶意html代码,当用户浏览该页时,嵌入其中Web里的html代码会被执行,从而达到恶意攻击用户的特殊目的。<br/>那么如果有人在你的网页写了如下代码<script>alert(1);</script>浏览器能不能直接拒绝执行呢?<br/>为了应对这些问题我们就需要在头部添加<strong>CONTENT-SECURITY-POLICY</strong></p><p style="margin-top: 8px; margin-bottom: 8px; padding: 0px 0px 8px; font-family: Arial; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255); line-height: 21.6px;"><strong>如何使用</strong>:<br/>将下列编码写入HTTP头部中:<br/>script-src: JavaScript code (biggest reason to use this header)<br/>connect-src: XMLHttpRequest, WebSockets, and EventSource.<br/>font-src: fonts<br/>frame-src: frame ulrs<br/>img-src: images<br/>media-src: audio & video<br/>object-src: Flash (and other plugins)<br/>style-src: CSS</p><p style="margin-top: 8px; margin-bottom: 8px; padding: 0px 0px 8px; font-family: Arial; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255); line-height: 21.6px;">·特别注意:<br/>Content-Security-Policy: script-src ‘self’ https://apis.google.com<br/>这意味着脚本文件只能是来自当前文件或apis.google.com<br/>另一个有用的特性就是你可以自动应用沙盒模式在整个站点。如果你想试一试效果,可以使用:<br/>“Content-Security-Policy-Report-Only”头部;让浏览器返回一个你选的URL。<br/>推荐阅读一下<a target="_blank" title="html5rocks" href="http://www.html5rocks.com/en/tutorials/security/content-security-policy/" style="color: rgb(255, 153, 0); text-decoration-line: none;">HTML5Rocks</a>上的一篇CSP的介绍。</p><p style="margin-top: 8px; margin-bottom: 8px; padding: 0px 0px 8px; font-family: Arial; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255); line-height: 21.6px;"><strong>需要注意的问题:</strong><br/>1.IE只支持沙盘模式而且用的是“X”前缀;而安卓4.4则完全支持<br/>2.它不能在你生成JavaScript动态(实践中并不常见)情况下防止XSS攻击</p><p style="margin-top: 8px; margin-bottom: 8px; padding: 0px 0px 8px; font-family: Arial; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255); line-height: 21.6px;"><a target="_blank" href="http://guobud.qiniudn.com/wp-content/uploads/2014/04/016.jpg" style="color: rgb(255, 153, 0); text-decoration-line: none;"><span style="color: rgb(0, 0, 0);"><img class="alignnone size-full wp-image-318" alt="01" src="/ueditor/php/upload/image/20170916/1505493019857077.jpg" width="600" height="365" style="border: 1px solid rgb(216, 219, 220); max-width: 100%;"/></span></a></p><p style="margin-top: 8px; margin-bottom: 8px; padding: 0px 0px 8px; font-family: Arial; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255); line-height: 21.6px;"><strong>了解更多:</strong></p><p style="margin-top: 8px; margin-bottom: 8px; padding: 0px 0px 8px; font-family: Arial; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255); line-height: 21.6px;"><a target="_blank" href="http://www.html5rocks.com/en/tutorials/security/content-security-policy/" style="color: rgb(255, 153, 0); text-decoration-line: none;">HTML5Rocks</a>有非常好的介绍文章而 <a target="_blank" title="w3c" href="http://www.w3.org/TR/CSP/" style="color: rgb(255, 153, 0); text-decoration-line: none;">W3C</a>规范也是深入学习的不错选择</p><p style="margin-top: 8px; margin-bottom: 8px; padding: 0px 0px 8px; font-family: Arial; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255); line-height: 21.6px;"> </p><p style="margin-top: 8px; margin-bottom: 8px; padding: 0px 0px 8px; font-family: Arial; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255); line-height: 21.6px;"><em><strong>2.X-FRAME-OPTIONS( X框架选项)</strong></em></p><p style="margin-top: 8px; margin-bottom: 8px; padding: 0px 0px 8px; font-family: Arial; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255); line-height: 21.6px;"><strong>为什么要使用:</strong><br/>点击劫持是一种恶意攻击技术,用于跟踪网络用户,获取其私密信息或者通过让用户点击看似正常的网页来远程控制其电脑。点击劫持可以通过嵌入代码或者文本的形式出现,在用户毫不知情的情况下完成攻击,比如点击一个表面显示是“播放”某个视频的按钮,而实际上完成的操作却是将用户的社交网站个人信息改为“公开”状态。<br/>而使用X-FRAME-OPTIONS能够阻止点击劫持的发生。</p><p style="margin-top: 8px; margin-bottom: 8px; padding: 0px 0px 8px; font-family: Arial; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255); line-height: 21.6px;"><strong>如何实现:</strong><br/>在HTTP头部输入:X-Frame-Options: DENY(使浏览器拒绝请求该页数据)<br/>如果设置成’SAMEORIGIN’,则将允许同源数据;<br/>如果设置成‘ALLOW FROM http://url-here.example.com’则将允许设置一个源(IE不支持)</p><p style="margin-top: 8px; margin-bottom: 8px; padding: 0px 0px 8px; font-family: Arial; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255); line-height: 21.6px;"><strong>需要注意的问题:</strong><br/>1.一些浏览器不支持这个header 或者其被整合到Content-Security-Policy 1.1之中<br/><a target="_blank" href="http://guobud.qiniudn.com/wp-content/uploads/2014/04/026.jpg" style="color: rgb(255, 153, 0); text-decoration-line: none;"><img class="alignnone size-full wp-image-317" alt="02" src="/ueditor/php/upload/image/20170916/1505493020382629.jpg" width="600" height="86" style="border: 1px solid rgb(216, 219, 220); max-width: 100%;"/></a></p><p style="margin-top: 8px; margin-bottom: 8px; padding: 0px 0px 8px; font-family: Arial; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255); line-height: 21.6px;"><strong>了解更多:</strong><br/>可访问<a target="_blank" title="Mozilla" href="https://developer.mozilla.org/en-US/docs/HTTP/X-Frame-Options" style="color: rgb(255, 153, 0); text-decoration-line: none;">Mozilla Developer Network</a>关于此问题的文章。<br/><a target="_blank" title="Coding Horror" href="http://www.codinghorror.com/blog/2009/06/we-done-%20been-framed.html" style="color: rgb(255, 153, 0); text-decoration-line: none;">Coding Horror </a>同样有比较不错的文章。</p><p style="margin-top: 8px; margin-bottom: 8px; padding: 0px 0px 8px; font-family: Arial; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255); line-height: 21.6px;"> </p><p style="margin-top: 8px; margin-bottom: 8px; padding: 0px 0px 8px; font-family: Arial; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255); line-height: 21.6px;"><em><strong>3.X-CONTENT-TYPE-OPTIONS (X内容类型选项)</strong></em></p><p style="margin-top: 8px; margin-bottom: 8px; padding: 0px 0px 8px; font-family: Arial; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255); line-height: 21.6px;"><strong>为什么要使用:</strong><br/>允许用户上传文件是一件危险的事情,提供文件上传服务的危险性更大,而且很难做到万无一失。即使内容是通过MIME嗅探获取,要让浏览器进行二次内容类型猜测服务也不是一件容易的事情。而为了确保用户上传文件时的安全性就需要用到X-CONTENT-TYPE-OPTIONS</p><p style="margin-top: 8px; margin-bottom: 8px; padding: 0px 0px 8px; font-family: Arial; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255); line-height: 21.6px;"><strong>如何使用:</strong><br/>X-CONTENT-TYPE-OPTIONS 值为:‘nosniff’为正确。其作用是允许用户更有效的告知浏览器,用户确定其想做的事情。(GitHub 就是使用这种方法来保护用户)</p><p style="margin-top: 8px; margin-bottom: 8px; padding: 0px 0px 8px; font-family: Arial; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255); line-height: 21.6px;"><strong>需要注意的问题:</strong><br/>这个头部只只适用于IE和Chrome,不过根据你的用户,你还是可以保护65%的用户的。</p><p style="margin-top: 8px; margin-bottom: 8px; padding: 0px 0px 8px; font-family: Arial; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255); line-height: 21.6px;"><a target="_blank" href="http://guobud.qiniudn.com/wp-content/uploads/2014/04/036.jpg" style="color: rgb(255, 153, 0); text-decoration-line: none;"><span style="color: rgb(0, 0, 0);"><img class="alignnone size-full wp-image-319" alt="03" src="/ueditor/php/upload/image/20170916/1505493020837455.jpg" width="600" height="85" style="border: 1px solid rgb(216, 219, 220); max-width: 100%;"/></span></a></p><p style="margin-top: 8px; margin-bottom: 8px; padding: 0px 0px 8px; font-family: Arial; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255); line-height: 21.6px;"><strong>了解更多:</strong><br/>FOX IT上有一篇关于MIME嗅探的优秀文章:<a target="_blank" href="http://blog.fox-it.com/2012/05/08/mime-sniffing-feature-or-%20vulnerability/" style="color: rgb(255, 153, 0); text-decoration-line: none;"> MIME 嗅探: 特性还是漏洞? </a><br/>IT Security Stackexchange上也有个专题:<a target="_blank" href="http://security.stackexchange.com/questions/12896/does-x-content-type-%20options-really-prevent-content-sniffing-attacks" style="color: rgb(255, 153, 0); text-decoration-line: none;">X-Content-Type-Options真能防止内容嗅探攻击吗?</a></p><p style="margin-top: 8px; margin-bottom: 8px; padding: 0px 0px 8px; font-family: Arial; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255); line-height: 21.6px;"> </p><p style="margin-top: 8px; margin-bottom: 8px; padding: 0px 0px 8px; font-family: Arial; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255); line-height: 21.6px;"><strong>4.Strict-Transport-Security (交换安全措施)</strong></p><p style="margin-top: 8px; margin-bottom: 8px; padding: 0px 0px 8px; font-family: Arial; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255); line-height: 21.6px;"><strong>为什么使用:</strong><br/>使用HTTPS可以为我们提供相对安全的环境。然而问题是:当我输入”onlinebanking.example.com” 到我的地址栏,浏<br/>览器会默认使用HTTP协议,只有当服务器重定向时才会提供安全HTTPS来建立连接。而重定向的过程中,黑客能够进行中间人攻击。<br/>为解决这个问题,Strict-Transport-Security头部应运而生。</p><p style="margin-top: 8px; margin-bottom: 8px; padding: 0px 0px 8px; font-family: Arial; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255); line-height: 21.6px;"><strong>如何使用:</strong><br/>HTTP的Strict-Transport-Security (HSTS)头部会强制浏览器使用HTTPS进行链接.比如:<br/>你输入 https://hsts.example.com,而它会返回:Strict-Transport-Security: max-age=31536000; includeSubDomains<br/>而输入http://hsts.example.com,浏览器也会自动链接https://hsts.example.com<br/>只要HSTS头部一直有效,浏览器就会默认这么做。在一般情况下,在最后一次接收到包含HSTS头的HTTP回复后1年之内都保持有效。</p><p style="margin-top: 8px; margin-bottom: 8px; padding: 0px 0px 8px; font-family: Arial; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255); line-height: 21.6px;"><strong>需要注意的问题:</strong></p><p style="margin-top: 8px; margin-bottom: 8px; padding: 0px 0px 8px; font-family: Arial; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255); line-height: 21.6px;">仅适用于Chrome和Firefox,但它已经成为官方的IETF标准,相信IE浏览器不久也将支持这个头部。</p><p style="margin-top: 8px; margin-bottom: 8px; padding: 0px 0px 8px; font-family: Arial; font-size: 14px; white-space: normal; background-color: rgb(255, 255, 255); line-height: 21.6px;"><a target="_blank" href="http://guobud.qiniudn.com/wp-content/uploads/2014/04/046.jpg" style="color: rgb(255, 153, 0); text-decoration-line: none;"><span style="color: rgb(0, 0, 0);"><img class="alignnone size-full wp-image-320" alt="04" src="/ueditor/php/upload/image/20170916/1505493020807931.jpg" width="600" height="246" style="border: 1px solid rgb(216, 219, 220); max-width: 100%;"/></span></a></p><p><br/></p>
CopyRight 2002~2023 精通2100网 联系邮箱:qqtxt@163.com
版权所有:精通2100网
湘ICP备2023018646号-1
MYSQl共执行 4 个查询,用时 0.0021219253540039 秒,PHP脚本用时 0.007193 秒,占用内存 0.582 MB,Gzip 已启用