node.js - Use csrf only for defined routes in restify -
i have restify application (simple api). use csurf library preventing csrf requests.
but need don't use csrf validation on several routes.
first idea, think - create array routes don't need use csrf , validate current route.
var routesnocsrf = ['/api/route1', '/api/route2']; if (routesnocsrf.indexof(currentroute) === -1) { server.use(csrf({ cookie: true, ignoremethods: ['head', 'options'] })); }
but on step didn't have access currentroute
second - divide 1 api 2 different apis - , first use csrf validation second - not. in case - create 2 different servers, listen 2 different ports.
but using 1 app. possible ?
there complete example ignoring routes on csurf github page.
Comments
Post a Comment