在 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>

 

posted @ 2021-12-03 14:12  不是豆豆  阅读(1002)  评论(0编辑  收藏  举报
友情链接:迷途