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

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

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

<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="default-src 'self' 'unsafe-inline' 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" />
            </customHeaders>
        </httpProtocol>
    </system.webServer>
</configuration>

输了你,赢了世界又如何...
原文地址:https://www.cnblogs.com/xwgli/p/15637736.html