Web安全 之 X-Frame-Options回應標頭配置

來源:互聯網
上載者:User

標籤:define   clu   plain   div   source   分享   img   and   技術分享   

  最近項目處於測試階段,在安全報告中存在" X-Frame-Options 回應標頭缺失 "問題,顯示可能會造成跨幀指令碼編製攻擊,如:

  

  X-Frame-Options:

  值有三個:

  (1)DENY:表示該頁面不允許在 frame 中展示,即便是在相同網域名稱的頁面中嵌套也不允許。

  (2)SAMEORIGIN:表示該頁面可以在相同網域名稱頁面的 frame 中展示。

  (3)ALLOW-FROM https://example.com/:表示該頁面可以在指定來源的 frame 中展示。

 

配置Apache:

(如果是在本地的話,就是在httpd.conf裡面配置;如果是linux(ubuntu的話)就是在apache2.conf裡面)

找個空的位置加入這行代碼,具體看你是選擇哪種

[plain] view plain copy  print?
  1. <span style="font-size:14px;">Header always append X-Frame-Options SAMEORIGIN</span>  
<span style="font-size:14px;">Header always append X-Frame-Options SAMEORIGIN</span>

 

 

有可能會遇到一種情況,就是我在服務端配置完apache之後,嘗試 Restart Apache 但是報了一個錯誤:

Invalid command ‘Header’, perhaps misspelled or defined by a module not included in the server configuration

header的方法模組沒有安裝,我們需要先自行安裝一下:

print?

  1. <span style="font-size:14px;">add_header X-Frame-Options SAMEORIGIN;</span>  
<span style="font-size:14px;">add_header X-Frame-Options SAMEORIGIN;</span>



 

配置IIS:

配置 IIS 發送 X-Frame-Options 回應標頭,添加下面的配置到 Web.config 檔案中:

 

[plain] view plain copy  print?
  1. <system.webServer>  
  2.   ...  
  3.   
  4.   <httpProtocol>  
  5.     <customHeaders>  
  6.       <add name="X-Frame-Options" value="SAMEORIGIN" />  
  7.     </customHeaders>  
  8.   </httpProtocol>  
  9.   
  10.   ...  
  11. </system.webServer>  
<system.webServer>  ...  <httpProtocol>    <customHeaders>      <add name="X-Frame-Options" value="SAMEORIGIN" />    </customHeaders>  </httpProtocol>  ...</system.webServer>

 

大概配置就是這樣了,之前在尋找配置iframe載入的時候,看到有些文章說iframe載入容易被劫持,當然也有破解的方法,不過沒有詳細地去看,有興趣的朋友可以去瞭解下!

Web安全 之 X-Frame-Options回應標頭配置

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.