Error - csurf with multer
See original GitHub issueHello, im using csrf module (csurf) but when im uploading…
Error: invalid csrf token
at verifytoken (D:\nodejs\node_modules\csurf\index.js:234:13)
at csrf (D:\nodejs\node_modules\csurf\index.js:94:7)
at Layer.handle [as handle_request] (D:\nodejs\node_modules\express\lib\router\layer.js:76:5)
at trim_prefix (D:\nodejs\node_modules\express\lib\router\index.js:263:13)
at D:\nodejs\node_modules\express\lib\router\index.js:230:9
at Function.proto.process_params (D:\nodejs\node_modules\express\lib\router\index.js:305:12)
at D:\nodejs\node_modules\express\lib\router\index.js:221:12
at Function.match_layer (D:\nodejs\node_modules\express\lib\router\index.js:288:3)
at next (D:\nodejs\node_modules\express\lib\router\index.js:182:10)
at methodOverride (D:\nodejs\node_modules\method-override\index.js:77:5)`
var product=config.upload;
uri.route('/up').get(function (req,res,next) {
res.render('upload',{
csrf : req.csrfToken()
});
res.end();
}).post(product,function (req,res,next) {
console.log('IN POST (/upload)');
console.log(req.body)
var filesUploaded = 0;
if ( Object.keys(req.files).length === 0 ) {
console.log('no files uploaded');
} else {
console.log(req.files)
var files = req.files.file1;
if (!util.isArray(req.files.file1)) {
files = [ req.files.file1 ];
}
filesUploaded = files.length;
}
res.json({ message: 'Finished! Uploaded ' + filesUploaded + ' files. Route is /upload' });
});
🔨
Issue Analytics
- State:
- Created 9 years ago
- Comments:8 (1 by maintainers)
Top Results From Across the Web
CSRF and Multer - Invalid CSRF Token Error - Stack Overflow
I have run into an issue with my multipart form when I added support for CSRF tokens to keep submissions secure. I have...
Read more >Upload Single or Multiple Files with CSRF Protection - YouTube
Welcome to another video in this Node JS, Express Series and in this video we are going to talk about multer. A library...
Read more >[Solved]-Graphql Invalid CSRF Token-node.js - appsloveworld
Csurf invalid csrf token Express / nodejs · Node Express and csurf - 403 ... CSRF and Multer - Invalid CSRF Token Error...
Read more >cannot read properties of undefined (reading 'path') multer ...
I have encountered the same problem. But then I change the multer version back to 0.1.8 . Everything works fine. You may need...
Read more >Express csurf middleware - Express 中文文档
Note: This page was generated from the csurf README. ... npm install csurf ... When the CSRF token validation fails, an error is...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Fine, found the solution:
Make sure that multer is added before the csurf middleware, like so:
As far as I can tell it really should work then.