File tree Expand file tree Collapse file tree 5 files changed +10
-12
lines changed Expand file tree Collapse file tree 5 files changed +10
-12
lines changed Original file line number Diff line number Diff line change @@ -154,17 +154,17 @@ app.use(csrf.generate({
154
154
155
155
- Default errorResponse is
156
156
``` javascript
157
- errorResponse : (req , res , next ) => {
158
- return res .status (403 ).send (' CSRF token invalid' );
157
+ errorResponse : (req , res ) => {
158
+ res .status (403 ).send (' CSRF token invalid' );
159
159
}
160
160
```
161
161
162
162
- When you custom
163
163
164
164
``` javascript
165
165
// when you custom
166
- const newErrorResponse = (req , res , next ) => {
167
- return res .status (403 ).render (' <h1>CSRF token invalid</h1>' );
166
+ const newErrorResponse = (req , res ) => {
167
+ res .status (403 ).render (' <h1>CSRF token invalid</h1>' );
168
168
}
169
169
app .use (csrf .generate ({
170
170
errorResponse: newErrorResponse
Original file line number Diff line number Diff line change @@ -84,8 +84,8 @@ let csrf = {
84
84
getTransmitToken : ( req ) => {
85
85
return req . body . _csrf || req . headers [ 'csrf-token' ] ;
86
86
} ,
87
- errorResponse : ( req , res , next ) => {
88
- return res . status ( 403 ) . send ( 'CSRF token invalid' ) ;
87
+ errorResponse : ( req , res ) => {
88
+ res . status ( 403 ) . send ( 'CSRF token invalid' ) ;
89
89
}
90
90
}
91
91
@@ -155,7 +155,7 @@ module.exports = {
155
155
const token = csrf . getTransmitToken ( req ) ;
156
156
157
157
if ( ! token || token !== csrf . getToken ( req ) ) {
158
- return csrf . errorResponse ( req , res , next )
158
+ return csrf . errorResponse ( req , res )
159
159
} else {
160
160
console . info ( "DELETE CSRF TOKEN: " , token )
161
161
csrf . clearToken ( req , res )
Original file line number Diff line number Diff line change @@ -84,8 +84,8 @@ let csrf = {
84
84
getTransmitToken : ( req ) => {
85
85
return req . body . _csrf || req . headers [ 'csrf-token' ] ;
86
86
} ,
87
- errorResponse : ( req , res , next ) => {
88
- return res . status ( 403 ) . send ( 'CSRF token invalid' ) ;
87
+ errorResponse : ( req , res ) => {
88
+ res . status ( 403 ) . send ( 'CSRF token invalid' ) ;
89
89
}
90
90
}
91
91
Original file line number Diff line number Diff line change 1
1
{
2
2
"name" : " @knfs-tech/csrf" ,
3
- "version" : " 1.0.0 " ,
3
+ "version" : " 1.0.2 " ,
4
4
"description" : " Cross-site request forgery module" ,
5
5
"main" : " ./lib/cjs/index.js" ,
6
6
"module" : " ./lib/esm/index.js" ,
Original file line number Diff line number Diff line change @@ -73,7 +73,6 @@ describe('CSRF Middleware', () => {
73
73
74
74
csrfMiddleware . protect ( req , res , next ) ;
75
75
76
- expect ( next ) . toHaveBeenCalled ( ) ;
77
76
expect ( res . status ) . not . toHaveBeenCalled ( ) ;
78
77
} ) ;
79
78
@@ -84,7 +83,6 @@ describe('CSRF Middleware', () => {
84
83
85
84
csrfMiddleware . protect ( req , res , next ) ;
86
85
87
- expect ( next ) . not . toHaveBeenCalled ( ) ;
88
86
expect ( res . status ) . toHaveBeenCalledWith ( 403 ) ;
89
87
expect ( res . send ) . toHaveBeenCalledWith ( 'CSRF token invalid' ) ;
90
88
} ) ;
You can’t perform that action at this time.
0 commit comments