在 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