2021-05-05 10:13:49 -07:00
|
|
|
|
---
|
|
|
|
|
id: 587d8247367417b2b2512c38
|
2021-07-16 11:03:16 +05:30
|
|
|
|
title: 使用 helmet.frameguard() 降低點擊劫持的風險
|
2021-05-05 10:13:49 -07:00
|
|
|
|
challengeType: 2
|
|
|
|
|
forumTopicId: 301582
|
|
|
|
|
dashedName: mitigate-the-risk-of-clickjacking-with-helmet-frameguard
|
|
|
|
|
---
|
|
|
|
|
|
|
|
|
|
# --description--
|
|
|
|
|
|
2021-07-16 11:03:16 +05:30
|
|
|
|
請注意,本項目在 [這個 Repl.it 項目](https://replit.com/github/freeCodeCamp/boilerplate-infosec) 的基礎上進行開發。 你也可以從 [GitHub](https://github.com/freeCodeCamp/boilerplate-infosec/) 上克隆。
|
2021-05-05 10:13:49 -07:00
|
|
|
|
|
2021-07-16 11:03:16 +05:30
|
|
|
|
你的網頁可能在未經你同意的情況下被放在 `<frame>` 或 `<iframe>` 中。 這可能會導致點擊劫持攻擊等情況。 點擊劫持是一種欺騙用戶的技術,使其與用戶認爲不同的頁面進行互動。 這可以通過使用 iframe 的方式,在一個惡意的環境中執行你的頁面而獲得。 在這種情況下,黑客可以在你的頁面上設置一個隱藏層。 隱藏的按鈕可以被用來運行壞的腳本。 該中間件設置 X-Frame-Options 頭。 它限制了誰可以把你的網站放在一個框架裏。 它有三種模式:DENY、SAMEORIGIN 和 ALLOW-FROM。
|
2021-05-05 10:13:49 -07:00
|
|
|
|
|
2021-07-16 11:03:16 +05:30
|
|
|
|
我們不需要讓我們的應用程序可以被嵌入。
|
2021-05-05 10:13:49 -07:00
|
|
|
|
|
|
|
|
|
# --instructions--
|
|
|
|
|
|
2021-07-16 11:03:16 +05:30
|
|
|
|
使用 `helmet.frameguard()` 時應傳遞配置對象 `{action: 'deny'}`。
|
2021-05-05 10:13:49 -07:00
|
|
|
|
|
|
|
|
|
# --hints--
|
|
|
|
|
|
2021-07-16 11:03:16 +05:30
|
|
|
|
應正確加載 helmet.frameguard() 中間件
|
2021-05-05 10:13:49 -07:00
|
|
|
|
|
|
|
|
|
```js
|
|
|
|
|
(getUserInput) =>
|
|
|
|
|
$.get(getUserInput('url') + '/_api/app-info').then(
|
|
|
|
|
(data) => {
|
|
|
|
|
assert.include(
|
|
|
|
|
data.appStack,
|
|
|
|
|
'frameguard',
|
|
|
|
|
'helmet.frameguard() middleware is not mounted correctly'
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
(xhr) => {
|
|
|
|
|
throw new Error(xhr.responseText);
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
```
|
|
|
|
|
|
2021-07-16 11:03:16 +05:30
|
|
|
|
helmet.frameguard() 'action' 應該設置爲 “DENY”
|
2021-05-05 10:13:49 -07:00
|
|
|
|
|
|
|
|
|
```js
|
|
|
|
|
(getUserInput) =>
|
|
|
|
|
$.get(getUserInput('url') + '/_api/app-info').then(
|
|
|
|
|
(data) => {
|
|
|
|
|
assert.property(data.headers, 'x-frame-options');
|
|
|
|
|
assert.equal(data.headers['x-frame-options'], 'DENY');
|
|
|
|
|
},
|
|
|
|
|
(xhr) => {
|
|
|
|
|
throw new Error(xhr.responseText);
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
# --solutions--
|
|
|
|
|
|
|
|
|
|
```js
|
|
|
|
|
/**
|
|
|
|
|
Backend challenges don't need solutions,
|
|
|
|
|
because they would need to be tested against a full working project.
|
|
|
|
|
Please check our contributing guidelines to learn more.
|
|
|
|
|
*/
|
|
|
|
|
```
|