From 218934fa2ed1c702a6d3923d2aa2cc6b43c48684 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:43:23 -0500 Subject: initial commit --- .../web/http/headers/x-frame-options/index.html | 146 +++++++++++++++++++++ 1 file changed, 146 insertions(+) create mode 100644 files/zh-tw/web/http/headers/x-frame-options/index.html (limited to 'files/zh-tw/web/http/headers/x-frame-options') diff --git a/files/zh-tw/web/http/headers/x-frame-options/index.html b/files/zh-tw/web/http/headers/x-frame-options/index.html new file mode 100644 index 0000000000..b19ddffe26 --- /dev/null +++ b/files/zh-tw/web/http/headers/x-frame-options/index.html @@ -0,0 +1,146 @@ +--- +title: X-Frame-Options 回應標頭 +slug: Web/HTTP/Headers/X-Frame-Options +translation_of: Web/HTTP/Headers/X-Frame-Options +--- +

{{ gecko_minversion_header("2.0") }}

+ +
+
Note: CSP Level 2 的 frame-ancestors 指令標準雖然已經取代了非標準的 X-Frame-Options,而自 {{Gecko("4.0")}} 起也開始支援  frame-ancestors 指令,但因為並非所有瀏覽器都支援 frame-ancestors,所以 支援度較廣的 X-Frame-Options 還是可以和  CSP 一起採用。
+
+ +

X-Frame-Options HTTP 回應標頭 (header) 用來指示文件是否能夠載入 {{ HTMLElement("frame") }}, {{ HTMLElement("iframe") }} 以及 {{ HTMLElement("object") }},網站可以利用 X-Frame-Options 來確保本身內容不會遭惡意嵌入道其他網站、避免 clickjacking 攻擊

+ +

使用 X-Frame-Options

+ +

共有三種值:

+ +
+
DENY
+
表示文件無論如何都不能被嵌入到 frame 中,即使是自家網站也不行。
+
SAMEORIGIN
+
唯有當符合同源政策下,才能被嵌入到 frame 中。
+
ALLOW-FROM uri
+
唯有列表許可的 URI 才能嵌入到 frame 中。
+
+ +

設定 Apache

+ +

請加入以下指令到網站組態設定檔

+ +
Header always append X-Frame-Options SAMEORIGIN
+
+ +

設定 nginx

+ +

請加入以下指令到 http, server 或 location 組態設定檔:

+ +
add_header X-Frame-Options SAMEORIGIN;
+
+ +

設定 IIS

+ +

請加入以下指令到網站的 Web.config 檔:

+ +
<system.webServer>
+  ...
+
+  <httpProtocol>
+    <customHeaders>
+      <add name="X-Frame-Options" value="SAMEORIGIN" />
+    </customHeaders>
+  </httpProtocol>
+
+  ...
+</system.webServer>
+
+ +

設定 HAProxy

+ +

請加入以下指令到 frontend, listen, 或 backend 組態設定檔:

+ +
rspadd X-Frame-Options:\ SAMEORIGIN
+
+ +
+

Note:  設定 Meta tag 是無效的,像是 <meta http-equiv="X-Frame-Options" content="deny"> 便沒有任何效果,只有透過設定 HTTP header 才有效果,請勿採用。

+
+ +

 

+ +

結論

+ +

當載入一個 X-Frame-Options 不允許的網站到 iframe 中, Firefox 會顯示about:blank 的空白頁面,甚至某些狀況還會顯示錯誤訊息。

+ +

瀏覽器相容性

+ +

{{ CompatibilityTable() }}

+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + +
FeatureChromeFirefox (Gecko)Internet ExplorerOperaSafari
Basic support{{ CompatChrome(4.1.249.1042) }}{{ CompatGeckoDesktop(1.9.2.9) }}{{ CompatIE(8.0) }}{{ CompatOpera(10.5) }}{{ CompatSafari(4.0) }}
ALLOW-FROM support{{ CompatNo() }}{{ CompatGeckoDesktop(18.0) }} {{ bug(690168) }}{{ CompatIE("8.0?") }}{{ CompatUnknown() }}{{ CompatNo() }} {{webkitbug(94836)}}
+
+ +
+ + + + + + + + + + + + + + + + + + + + + +
FeatureAndroidChrome for AndroidFirefox Mobile (Gecko)IE MobileOpera MobileSafari Mobile
Basic support{{ CompatUnknown() }}{{ CompatUnknown() }}{{ CompatUnknown() }}{{ CompatUnknown() }}{{ CompatUnknown() }}{{ CompatUnknown() }}
+
+ +

 

+ +

延伸閱讀

+ + + +

{{ languages( { "ja": "ja/The_X-FRAME-OPTIONS_response_header"} ) }}

-- cgit v1.2.3-54-g00ecf