@@ -28,14 +28,16 @@ module.exports = function(sails) {
28
28
sails . config . csrf = {
29
29
grantTokenViaAjax : true ,
30
30
protectionEnabled : true ,
31
- origin : '-'
31
+ origin : '-' ,
32
+ routesDisabled : '-'
32
33
} ;
33
34
}
34
35
else if ( sails . config . csrf === false ) {
35
36
sails . config . csrf = {
36
37
grantTokenViaAjax : false ,
37
38
protectionEnabled : false ,
38
- origin : '-'
39
+ origin : '-' ,
40
+ routesDisabled : '-'
39
41
} ;
40
42
}
41
43
// If user provides ANY object (including empty object), enable all default
@@ -44,7 +46,8 @@ module.exports = function(sails) {
44
46
_ . defaults ( typeof sails . config . csrf === 'object' ? sails . config . csrf : { } , {
45
47
grantTokenViaAjax : true ,
46
48
protectionEnabled : true ,
47
- origin : '-'
49
+ origin : '-' ,
50
+ routesDisabled : '-'
48
51
} ) ;
49
52
}
50
53
// Add the csrfToken directly to the config'd routes, so that the CORS hook can process it
@@ -63,12 +66,15 @@ module.exports = function(sails) {
63
66
var connect = require ( 'express/node_modules/connect' ) ;
64
67
65
68
return connect . csrf ( ) ( req , res , function ( err ) {
69
+
70
+ var isRouteDisabled = sails . config . csrf . routesDisabled . split ( ',' ) . indexOf ( req . path ) > - 1 ;
71
+
66
72
if ( util . isSameOrigin ( req ) || allowCrossOriginCSRF ) {
67
73
res . locals . _csrf = req . csrfToken ( ) ;
68
74
} else {
69
75
res . locals . _csrf = null ;
70
76
}
71
- if ( err ) {
77
+ if ( err && ! isRouteDisabled ) {
72
78
// Return an Access-Control-Allow-Origin header in case this is a xdomain request
73
79
if ( req . headers . origin ) {
74
80
res . set ( 'Access-Control-Allow-Origin' , req . headers . origin ) ;
@@ -109,4 +115,4 @@ function csrfToken (req, res, next) {
109
115
return res . json ( {
110
116
_csrf : res . locals . _csrf
111
117
} ) ;
112
- }
118
+ }
0 commit comments