X-Frame-Options我們在安全檢測的時候經常會爆出輕微漏洞的安全提示,很多文章做了相關的解決方法介紹,當然361模板也不例外,我們在前面也做過《360安全檢測提示"X-Frame-Options頭未設置"的解決方法》和《IIS7.5下如何修復X-Frame-Options頭未設置的漏洞》2篇相關的文章介紹,但是部分朋友反饋說自己操作無效,咨詢361模板知否有其他的方式方法來解決這個問題。
361模板在網上收集整理了一些內容,加上自己的測試,一篇《通過web.config設置X-Frame-Options方法實踐》文章分享給大家。
<?xml version="1.0" encoding="UTF-8"?><configuration><connectionStrings> <add name="ApplicationServices" connectionString="data source=./SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|/aspnetdb.mdf;User Instance=true" providerName="System.Data.SqlClient" /></connectionStrings><system.web><compilation debug="true" targetFramework="4.0" /><authentication mode="Forms"> <forms loginUrl="~/Account/Login.aspx" timeout="2880" /></authentication></system.web><system.webServer><httpProtocol> <customHeaders> <add name="X-Frame-Options" value="SAMEORIGIN" /> </customHeaders></httpProtocol></system.webServer></configuration>
仔細查看上面的代碼,需要注意:
<httpProtocol>...</httpProtocol> 整塊代碼一定要放到 <system.webServer>...</system.webServer> 里面。
尤其要注意的是
有朋友測試發下,web.config 設置 X-Frame-Options 無效!!
究其原因如下
如果遇到 web.config 設置 X-Frame-Options 無效的情況,請確認自己已經重啟了IIS。如果不行,試試下面的代碼:
<system.webServer> <httpProtocol> <customHeaders> <add name="Content-Security-Policy" value="default-src: https:; frame-ancestors 'self' X-Frame-Options: SAMEORIGIN" /> </customHeaders> </httpProtocol></system.webServer>
上述代碼分析:
您的 web.config 條目需要在 Content-Security-Policy (內容安全策略)下才能使用之前沒有折舊的編碼。
value ="default-src: https:"內容安全策略下的值對您的網站是唯一的。
重要的內容是 'value =“default-src: https:' 后面的內容,但最重要的是包含在內容安全策略中。
如果不明白說講述的內容,建議直接忽略,能用得起來就行,至于含義能理解就理解,理解不了也無所謂。
以上就是通過web.config設置X-Frame-Options方法實踐的全部內容,希望對大家的學習和解決疑問有所幫助,也希望大家多多支持武林網。新聞熱點
疑難解答