Skip to content

Commit fc70ce0

Browse files
indutnyrichardlau
authored andcommitted
http: unset F_CHUNKED on new Transfer-Encoding
Duplicate `Transfer-Encoding` header should be a treated as a single, but with original header values concatenated with a comma separator. In the light of this, even if the past `Transfer-Encoding` ended with `chunked`, we should be not let the `F_CHUNKED` to leak into the next header, because mere presence of another header indicates that `chunked` is not the last transfer-encoding token. CVE-ID: CVE-2020-8287 PR-URL: nodejs-private/node-private#235 Reviewed-By: Fedor Indutny <[email protected]>
1 parent 323a6f1 commit fc70ce0

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

deps/http_parser/http_parser.c

+7
Original file line numberDiff line numberDiff line change
@@ -1344,6 +1344,13 @@ size_t http_parser_execute (http_parser *parser,
13441344
} else if (parser->index == sizeof(TRANSFER_ENCODING)-2) {
13451345
parser->header_state = h_transfer_encoding;
13461346
parser->uses_transfer_encoding = 1;
1347+
1348+
/* Multiple `Transfer-Encoding` headers should be treated as
1349+
* one, but with values separate by a comma.
1350+
*
1351+
* See: https://tools.ietf.org/html/rfc7230#section-3.2.2
1352+
*/
1353+
parser->flags &= ~F_CHUNKED;
13471354
}
13481355
break;
13491356

deps/http_parser/test.c

+26
Original file line numberDiff line numberDiff line change
@@ -2154,6 +2154,32 @@ const struct message responses[] =
21542154
,.body= "2\r\nOK\r\n0\r\n\r\n"
21552155
,.num_chunks_complete= 0
21562156
}
2157+
#define HTTP_200_DUPLICATE_TE_NOT_LAST_CHUNKED 30
2158+
, {.name= "HTTP 200 response with `chunked` and duplicate Transfer-Encoding"
2159+
,.type= HTTP_RESPONSE
2160+
,.raw= "HTTP/1.1 200 OK\r\n"
2161+
"Transfer-Encoding: chunked\r\n"
2162+
"Transfer-Encoding: identity\r\n"
2163+
"\r\n"
2164+
"2\r\n"
2165+
"OK\r\n"
2166+
"0\r\n"
2167+
"\r\n"
2168+
,.should_keep_alive= FALSE
2169+
,.message_complete_on_eof= TRUE
2170+
,.http_major= 1
2171+
,.http_minor= 1
2172+
,.status_code= 200
2173+
,.response_status= "OK"
2174+
,.content_length= -1
2175+
,.num_headers= 2
2176+
,.headers=
2177+
{ { "Transfer-Encoding", "chunked" }
2178+
, { "Transfer-Encoding", "identity" }
2179+
}
2180+
,.body= "2\r\nOK\r\n0\r\n\r\n"
2181+
,.num_chunks_complete= 0
2182+
}
21572183
};
21582184

21592185
/* strnlen() is a POSIX.2008 addition. Can't rely on it being available so

0 commit comments

Comments
 (0)