Files
freeCodeCamp/curriculum/challenges/chinese/09-information-security/information-security-with-helmetjs/configure-helmet-using-the-parent-helmet-middleware.md
2021-07-15 13:04:11 +05:30

1.4 KiB

id, title, challengeType, forumTopicId, dashedName
id title challengeType forumTopicId dashedName
587d8249367417b2b2512c40 使用 helmet() 中间件来配置 Helmet 2 301575 configure-helmet-using-the-parent-helmet-middleware

--description--

请注意,本项目在这个 Repl.it 项目的基础上进行开发。你也可以从 GitHub 上克隆。

app.use(helmet()) 将自动包括上面介绍的所有中间件,除了 noCache()contentSecurityPolicy(),但如果有必要,这些可以被启用。 你也可以使用配置对象,单独禁用或配置任何其他中间件。

例如:

app.use(helmet({
  frameguard: {         // configure
    action: 'deny'
  },
  contentSecurityPolicy: {    // enable and configure
    directives: {
      defaultSrc: ["'self'"],
      styleSrc: ['style.com'],
    }
  },
  dnsPrefetchControl: false     // disable
}))

为了教学目的和便于测试,我们分别介绍了每个中间件。 使用“父”helmet() 中间件很容易在真实项目中实现。

--hints--

没有测试 - 这是一个描述性的挑战

assert(true);

--solutions--

/**
  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.
*/