Try   HackMD

HTTP Headers - 筆記

tags: HTTP headers session authentication web security

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →
本站筆記已同步更新到我的個人網站囉! 歡迎參觀與閱讀,體驗不同的視覺感受!

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →
什麼是HTTP Headers

無論是瀏覽器發送的request或伺服器回傳的response中,都包含headers,其中記錄該request或response的相關的相關資訊。這邊要談的是伺服器回傳response中的headers,其中包含日期、檔案大小及類型等基本資訊,以及安全性資訊如該網站使用的政策、通訊政策、或限制瀏覽器是否可以在其他網站的iframe中渲染當前網頁等。這些安全性相關的headers同時保護應用程式與使用者的安全,避免XSS等攻擊,同時提升了該網站的可信度,提升其在SEO中的排名

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

Google Translate的Response Headers

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →
常見的安全性Headers

HTTP Strict-Transportation-Security (HSTS)

這個header讓伺服器告訴瀏覽器必須使用HTTPS協定進行連線,確保用戶端與伺服器端的傳輸安全。
範例如下:
Strict-Transport-Security: max-age=31536000; includeSubDomains

  • max-age:單位是秒,瀏覽器在接下來的這個期間(31536000秒,也就是一年)內,都會使用HTTPS
  • includeSubDomains:告訴瀏覽器這個網站以及他的子網域都是HTTPS-Only。

更多詳情參考MDN文件

Content-Security-Policy (CSP)

用來限制瀏覽器可以從哪裡載入資源,也就是列出一個白名單,放進所有可以載入資源的網域,避免XSS攻擊。
範例如下:
Content-Security-Policy: script-src 'self'

  • script-src:限制可以載入JavaScript資源的地方
  • self:代表瀏覽器只能從當前的網域載入JavaScript

更多詳情參考MDN文件

X-Frame-Options (XFO)

這個header可以防止當前的頁面被嵌入另一個網站HTML的iframe中,尤其是釣魚網站,攻擊者將被害網頁放入iframe,使用CSS隱藏iframe,並讓使用者在不知情的情況下點擊並發送request到被害網站,這種攻擊稱為Clickjacking
範例如下:

  • X-Frame-Options: DENY 網頁無法被放在任何地方的iframe
  • X-Frame-Options: SAMEORIGIN 網頁僅能放在同一個網域的iframe中
  • X-Frame-Options: ALLOW-FROM https://example.com 網頁內容僅能被放在https://example.com的iframe中

更多詳請參考MDN文件

小結

上面簡介了幾種常見的安全性相關HTTP headers,headers的種類還有很多,例如X-Content-Type-OptionsReferrer-Policy等,在MDN文件OWASP Cheat Sheet中有更詳細的介紹,也可以透過Security Headers查詢特定網站的安全性headers。


參考資料

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →
 本站內容僅為個人學習記錄,如有錯誤歡迎留言告知、交流討論!