【发布时间】:2019-02-07 08:34:57
【问题描述】:
我查看了 node js Git hub example 中的 csrf 实现,想知道这是针对应用程序级别的。如果我想在应用程序的一两个页面上应用它怎么办。我在网上没有找到任何示例。我知道在 asp.net 中你可以做到,但不确定如何在 Node JS 中实现。
非常感谢任何帮助指导解决方案。
【问题讨论】:
标签: html node.js csrf-protection csrf-token
我查看了 node js Git hub example 中的 csrf 实现,想知道这是针对应用程序级别的。如果我想在应用程序的一两个页面上应用它怎么办。我在网上没有找到任何示例。我知道在 asp.net 中你可以做到,但不确定如何在 Node JS 中实现。
非常感谢任何帮助指导解决方案。
【问题讨论】:
标签: html node.js csrf-protection csrf-token
在要保护的路由上添加 csruf 中间件。就像 Github 链接中的example 所示:
app.get('/route/to/protect', csrfProtection, function (req, res) {
// pass the csrfToken to the view
res.render('send', { csrfToken: req.csrfToken() })
})
这将允许 csrf 仅用于这条路线,而不是其他路线。您还可以使用 Regex 来匹配路由,如 express docs 中所述。
【讨论】: