[英]Csrf fix in node js at page level
I looked at csrf implementation in node js Git hub example and was wondering this is for a application level. 我在node js Git集线器示例中查看了csrf实现,并想知道这是针对应用程序级别的。 What if I want to apply it on one or two pages in the application.
如果我想将其应用到应用程序中的一两个页面上,该怎么办。 I did not find any example on the web.
我在网上找不到任何示例。 I know that in asp.net you can do it but not sure how the same can be achieved in Node JS.
我知道您可以在asp.net中做到这一点,但不确定在Node JS中如何实现相同的目的。
Any help in guiding to a solution is greatly appreciated. 非常感谢您提供指导解决方案的帮助。
Add the csruf middleware on the routes which you want to protect. 在要保护的路由上添加csruf中间件。 Like the example in the Github link shows:
就像Github链接中的示例所示:
app.get('/route/to/protect', csrfProtection, function (req, res) {
// pass the csrfToken to the view
res.render('send', { csrfToken: req.csrfToken() })
})
This will allow csrf only for this route and not others. 这将只允许csrf用于此路由,而不允许其他路由。 You can also use Regex to match routes as explained in the express docs .
您还可以使用Regex来匹配路由,如express docs中所述 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.