Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

maximum request lengths in node.js

Tags:

node.js

For security, I'd like to set a maximum request length in my node.js application. (There are many security vulnerabilities which take advantage of web servers allowing unlimited request lengths).

Is this possible? Is there one already?

like image 206
Aaron Yodaiken Avatar asked Jan 01 '12 22:01

Aaron Yodaiken


1 Answers

I'm guessing you are referring to the data a client can send you through POST. If you are using Express, you can use the limit middleware to achieve this: http://senchalabs.github.com/connect/middleware-limit.html

A short version of what's done there is:

req.on('data', function(chunk){
  received += chunk.length;
  if (received > bytes) req.destroy();
});
like image 52
alessioalex Avatar answered Oct 08 '22 10:10

alessioalex