Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feature] Add configuration to csrf to be able to change default /csrfTo... #2367

Merged
merged 12 commits into from
Mar 17, 2015
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions lib/hooks/csrf/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,17 @@ module.exports = function(sails) {
grantTokenViaAjax: true,
protectionEnabled: true,
origin: '-',
routesDisabled: '-'
routesDisabled: '-',
route: '/csrfToken'
};
}
else if (sails.config.csrf === false) {
sails.config.csrf = {
grantTokenViaAjax: false,
protectionEnabled: false,
origin: '-',
routesDisabled: '-'
routesDisabled: '-',
route: '/csrfToken'
};
}
// If user provides ANY object (including empty object), enable all default
Expand All @@ -47,11 +49,15 @@ module.exports = function(sails) {
grantTokenViaAjax: true,
protectionEnabled: true,
origin: '-',
routesDisabled: '-'
routesDisabled: '-',
route: '/csrfToken'
});
}
// Create a route path for getting _csrf parameter
var csrfRoute = {};
csrfRoute[sails.config.csrf.route] = {target: csrfToken, cors: {origin: sails.config.csrf.origin, credentials:true}};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you make this line more readable please (indent)?

// Add the csrfToken directly to the config'd routes, so that the CORS hook can process it
sails.config.routes["/csrfToken"] = {target: csrfToken, cors: {origin: sails.config.csrf.origin, credentials:true}};
sails.config.routes = sails.util.extend(csrfRoute, sails.config.routes);
},

initialize: function(cb) {
Expand Down Expand Up @@ -107,7 +113,7 @@ module.exports = function(sails) {
});

sails.on('router:after', function() {
sails.router.bind('/csrfToken', csrfToken, 'get', {cors: {origin: sails.config.csrf.origin, credentials: true}});
sails.router.bind(sails.config.csrf.route, csrfToken, 'get', {cors: {origin: sails.config.csrf.origin, credentials: true}});
});

cb();
Expand Down