-
Notifications
You must be signed in to change notification settings - Fork 30.6k
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
Type confusion bug in HTTP parser #12178
Comments
A sureshot bug - consistently failing with the above code, with this callstack:
|
While the direct usage of undocumented capability of process.binding is questionable, the concern over the exposure is ratified in terms of need for sanitizing publicly reachable code. This patch solves the issue, not sure whether this is the best one or not: diff --git a/src/node_http_parser.cc b/src/node_http_parser.cc
index f757cd6..593fa1e 100644
--- a/src/node_http_parser.cc
+++ b/src/node_http_parser.cc
@@ -472,6 +472,14 @@ class Parser : public AsyncWrap {
static void Consume(const FunctionCallbackInfo<Value>& args) {
Parser* parser;
ASSIGN_OR_RETURN_UNWRAP(&parser, args.Holder());
+
+ // Check the argument type
+ if (!args[0]->IsObject()) {
+ parser->env()->isolate()->ThrowException(Exception::TypeError(
+ String::NewFromUtf8(parser->env()->isolate(), "Object conversion of argument failed.")));
+ return;
+ }
+
Local<External> stream_obj = args[0].As<External>();
StreamBase* stream = static_cast<StreamBase*>(stream_obj->Value());
CHECK_NE(stream, nullptr);
|
Thanks for looking at this! I think you actually want |
@deian - thanks - agree that it should be IsExternal. Will see if I can pull up a PR on this, stay tuned. |
Unchecked argument conversion in Parser::Consume crashes node in an slightly undesirable manner - 'unreachable code' in parser. Make sure we validate the incoming type at the earliest point. Refs: nodejs#12178
Unchecked argument conversion in Parser::Consume crashes node in an slightly undesirable manner - 'unreachable code' in parser. Make sure we validate the incoming type at the earliest point. PR-URL: #12288 Fixes: #12178 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Alexey Orlenko <eaglexrlnk@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: Refael Ackermann <refack@gmail.com>
Unchecked argument conversion in Parser::Consume crashes node in an slightly undesirable manner - 'unreachable code' in parser. Make sure we validate the incoming type at the earliest point. PR-URL: #12288 Fixes: #12178 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Alexey Orlenko <eaglexrlnk@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: Refael Ackermann <refack@gmail.com>
We found unchecked type cast in the HTTP parser code. This one is in https://github.com/nodejs/node/blob/master/src/node_http_parser.cc#L496
Here is the 3 line exploit:
Can also just modifying the example on the nodejs.org site to trigger bug with public API:
The text was updated successfully, but these errors were encountered: