在 IIS 中增加相关安全 HTTP 头信息配置


参考:https://www.cnblogs.com/oneapm/p/5168793.html

更多参考:http://www.ruanyifeng.com/blog/2016/09/csp.html

在相应站点的 web.config 中增加以下配置即可,相关头内容的用途说明可参考以上文章或自行搜索。

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <!-- 
            移除 HTTP 头信息,需要安装:https://github.com/Dionach/StripHeaders
            若安装后没有效果,请执行:
            C:\Windows\System32\inetsrv\appcmd.exe install module /name:StripHeadersModule /image:%windir%\system32\inetsrv\stripheaders.dll /add:true /lock:true
            执行后重启 IIS 即可。
        -->
        <stripHeaders>
          <header name="Server" />
          <header name="X-Powered-By" />
          <header name="X-Aspnet-Version" />
        </stripHeaders>
        <!-- 增加为了安全的 HTTP 头信息 -->
        <httpProtocol>
            <customHeaders>
                <remove name="X-Powered-By" />
                <add name="Content-Security-Policy" value="frame-ancestors 'self'; default-src 'self' 'unsafe-inline' 'unsafe-eval' blob: data:" />
                <add name="X-Frame-Options" value="SAMEORIGIN" />
                <add name="X-XSS-Protection" value="1" />
                <add name="X-Content-Type-Options" value="nosniff" />
                <add name="X-Permitted-Cross-Domain-Policies" value="master-only" />
                <add name="X-Download-Options" value="noopen" />
                <add name="Referrer-Policy" value="origin-when-cross-origin" />
            </customHeaders>
        </httpProtocol>
    </system.webServer>
</configuration>

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM