2018-10-10 18:03:03 -04:00
|
|
|
|
---
|
|
|
|
|
id: 587d8247367417b2b2512c38
|
2021-07-15 13:04:11 +05:30
|
|
|
|
title: 使用 helmet.frameguard() 降低点击劫持的风险
|
2018-10-10 18:03:03 -04:00
|
|
|
|
challengeType: 2
|
2020-09-17 03:53:22 -07:00
|
|
|
|
forumTopicId: 301582
|
2021-01-13 03:31:00 +01:00
|
|
|
|
dashedName: mitigate-the-risk-of-clickjacking-with-helmet-frameguard
|
2018-10-10 18:03:03 -04:00
|
|
|
|
---
|
|
|
|
|
|
2020-12-16 00:37:30 -07:00
|
|
|
|
# --description--
|
2018-10-10 18:03:03 -04:00
|
|
|
|
|
2021-07-15 13:04:11 +05:30
|
|
|
|
请注意,本项目在 [这个 Repl.it 项目](https://replit.com/github/freeCodeCamp/boilerplate-infosec) 的基础上进行开发。 你也可以从 [GitHub](https://github.com/freeCodeCamp/boilerplate-infosec/) 上克隆。
|
2018-10-10 18:03:03 -04:00
|
|
|
|
|
2021-07-15 13:04:11 +05:30
|
|
|
|
你的网页可能在未经你同意的情况下被放在 `<frame>` 或 `<iframe>` 中。 这可能会导致点击劫持攻击等情况。 点击劫持是一种欺骗用户的技术,使其与用户认为不同的页面进行互动。 这可以通过使用 iframe 的方式,在一个恶意的环境中执行你的页面而获得。 在这种情况下,黑客可以在你的页面上设置一个隐藏层。 隐藏的按钮可以被用来运行坏的脚本。 该中间件设置 X-Frame-Options 头。 它限制了谁可以把你的网站放在一个框架里。 它有三种模式:DENY、SAMEORIGIN 和 ALLOW-FROM。
|
2021-02-06 04:42:36 +00:00
|
|
|
|
|
2021-07-15 13:04:11 +05:30
|
|
|
|
我们不需要让我们的应用程序可以被嵌入。
|
2018-10-10 18:03:03 -04:00
|
|
|
|
|
2020-12-16 00:37:30 -07:00
|
|
|
|
# --instructions--
|
2018-10-10 18:03:03 -04:00
|
|
|
|
|
2021-07-15 13:04:11 +05:30
|
|
|
|
使用 `helmet.frameguard()` 时应传递配置对象 `{action: 'deny'}`。
|
2018-10-10 18:03:03 -04:00
|
|
|
|
|
2020-12-16 00:37:30 -07:00
|
|
|
|
# --hints--
|
2018-10-10 18:03:03 -04:00
|
|
|
|
|
2021-07-15 13:04:11 +05:30
|
|
|
|
应正确加载 helmet.frameguard() 中间件
|
2018-10-10 18:03:03 -04:00
|
|
|
|
|
2020-12-16 00:37:30 -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);
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
```
|
2018-10-10 18:03:03 -04:00
|
|
|
|
|
2021-07-15 13:04:11 +05:30
|
|
|
|
helmet.frameguard() 'action' 应该设置为 “DENY”
|
2018-10-10 18:03:03 -04:00
|
|
|
|
|
|
|
|
|
```js
|
2020-12-16 00:37:30 -07:00
|
|
|
|
(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);
|
|
|
|
|
}
|
|
|
|
|
);
|
2018-10-10 18:03:03 -04:00
|
|
|
|
```
|
2020-08-13 17:24:35 +02:00
|
|
|
|
|
2020-12-16 00:37:30 -07:00
|
|
|
|
# --solutions--
|
|
|
|
|
|
2021-01-13 03:31:00 +01:00
|
|
|
|
```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.
|
|
|
|
|
*/
|
|
|
|
|
```
|