-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix potential ReDOS-Attack-Vector in Headerparser #72
Conversation
benchmarks before:
benchmarks after:
no performance degredation. |
posColon === -1 || | ||
posColon === 0 | ||
) { | ||
return |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldn't we throw an error instead? is this even valid payload?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Current behavior is skipping the header, if it is invalid. I would not want to change that, as I am not sure what side effects this could have. Maybe there is some reason that we just ignore it.
Or somebody is using for years busboy in his legacy product with a self written client. Then he wants to update his product to make it more resilient and then we throw errors resulting in a bigger man power investment as now the program breaks for something which was always handled gracefully. This could result in keeping the old busboy in the product with the argument, that the security fix is not worth the time to bugfix the legacy product.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would be helpful to at least log an error then. silent ignoring may be confusing and hard to debug
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have no logging functionality in busboy :/
Also before there was no logging of the invalid header.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should add some. not in this pr, though
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for the mercy :)
@kibertoad |
@Uzlopak I think this ties in to having strict mode discussed in another PR. If we go in that direction, enabling strict mode should probably emit an error in this case as well. |
I can understand that, but I would actually recommend to merge this anyway as this fixes a potential security issue and does not modify in any way the original busboy behaviour. We can still throw/emit an Error when we decide to implement a strict Mode. |
tl;dr;
An attacker could send a payload with large headers, which contain no colon, repeatedly, resulting in a REDoS-Attack.
The Regex for handling headerpairs is prone to catastrophic backtracking.
This is even more critical, as busboys default limit for multipart headers is 80kby and that if a header is not valid, the counter for headers is not increasing. Meaning, that the attacker could send a big payload of multipart formdata, were each multipart contains 80kby of invalid headerdata resulting in a DoS-Attack.
To avoid this, we just check if the line contains a colon and if so ensure that it is not at the first position. If not we exit early. If not we can savely use the Regex for the header as before.
Checklist
npm run test
andnpm run benchmark
and the Code of conduct