CSRF修复节点JS在页面级

问题描述 投票:0回答:1

我看着在节点JS Git hub example CSRF执行,并想知道这是一个应用水平。如果我想它适用于应用中的一个或两个页面。我没有在网上找到任何例子。我知道,在asp.net你可以做到这一点,但不知道如何同样可以在节点JS来实现。

在引导到溶液中的任何帮助感激。

html node.js csrf-protection csrf-token
1个回答
0
投票

添加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只有这条路,而不是其他。您还可以使用正则表达式作为express docs解释相匹配的路由。

© www.soinside.com 2019 - 2024. All rights reserved.