

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# 在 iFrame 中嵌入 Amazon DCV Web 瀏覽器用戶端
<a name="embed-in-iframe"></a>

根據預設，為了防止點擊劫持攻擊，Amazon DCV 不允許 Web 瀏覽器用戶端內嵌在 iFrame 中。不過，您可以覆寫此預設行為，以允許 Web 瀏覽器用戶端在 iFrame 內執行。

如需防止點擊劫持攻擊的詳細資訊，請參閱[內容安全政策備忘單](https://cheatsheetseries.owasp.org/cheatsheets/Content_Security_Policy_Cheat_Sheet.html#Preventing_Clickjacking)。

若要允許 Web 瀏覽器在 iFrame 內執行，您必須設定 Amazon DCV 伺服器，將下列額外的 HTTP 回應標頭傳送至 Web 瀏覽器用戶端：
+ `web-x-frame-options`
+ `web-extra-http-headers`

我們建議您新增兩個標頭，以確保 Web 瀏覽器之間的最佳相容性。

**注意**  
如果透過 Amazon DCV Connection Gateway 連線，則需要在閘道組態中定義 x 影格選項。這是使用閘道組態 [`[web-resources]`區段](https://docs.aws.amazon.com/dcv/latest/gw-admin/config-reference.html#config-web-resources)中的 `local-resources-http-headers` 參數來完成。

------
#### [ Windows server ]

1. 開啟 Windows 登錄編輯器並導覽至 **HKEY\$1USERS\$1S-1-5-18\$1Software\$1GSettings\$1com\$1nicesoftware\$1dcv\$1connectivity\$1 **金鑰。

1. 開啟 **web-x-frame-options** 參數。針對**值資料**，輸入 `"ALLOW-FROM https://server_hostname"`。
**注意**  
如果 參數不存在，請建立新的字串參數並命名為 `web-x-frame-options`。

1. 開啟 **web-extra-http-headers** 參數。針對**值資料**，輸入 `[("Content-Security-Policy", "frame-ancestors https://server_hostname")]`。
**注意**  
如果 參數不存在，請建立新的字串參數並將其命名為 `web-extra-http-headers`。

1. 關閉 Windows 登錄編輯程式。

1. [停止](manage-stop.md)並[重新啟動](manage-start.md) Amazon DCV 伺服器。

------
#### [ Linux server ]

1. 使用您偏好的文字編輯器開啟 `/etc/dcv/dcv.conf`。

1. 在 `[connectivity]`區段中，執行下列動作：
   + 針對 `web-x-frame-options`，請輸入 `"ALLOW-FROM https://server_hostname"`。
   + 針對 `web-extra-http-headers`，請輸入 `[("Content-Security-Policy", "frame-ancestors https://server_hostname")]`。

   例如：

   ```
   [connectivity]
   web-x-frame-options="ALLOW-FROM https://my-dcv-server.com"
   web-extra-http-headers=[("Content-Security-Policy", "frame-ancestors https://my-dcv-server.com")]
   ```

1. 儲存並關閉檔案。

1. [停止](manage-stop.md)並[重新啟動](manage-start.md) Amazon DCV 伺服器。

------

根據預設，大多數瀏覽器會阻止存取某些功能，例如麥克風存取和全螢幕存取。若要允許存取這些功能，請修改網頁上的 iFrame 元素。例如，若要允許存取麥克風和全螢幕模式，請修改 iFrame 元素，如下所示：

```
<iframe src="..." allow="microphone; fullscreen"></iframe>
```