Aaron Yodaiken
Aaron Yodaiken

Reputation: 19551

maximum request lengths in 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?

Upvotes: 6

Views: 3523

Answers (1)

alessioalex
alessioalex

Reputation: 63653

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();
});

Upvotes: 1

Related Questions