Skip to content

Commit

Permalink
BUG/MEDIUM: h1: Don't support LF only to mark the end of a chunk size
Browse files Browse the repository at this point in the history
It is similar to the previous fix but for the chunk size parsing. But this
one is more annoying because a poorly coded application in front of haproxy
may ignore the last digit before the LF thinking it should be a CR. In this
case it may be out of sync with HAProxy and that could be exploited to
perform some sort or request smuggling attack.

While it seems unlikely, it is safer to forbid LF with CR at the end of a
chunk size.

This patch must be backported to 2.9 and probably to all stable versions
because there is no reason to still support LF without CR in this case.
  • Loading branch information
capflam committed Jan 30, 2024
1 parent 7b737da commit 4837e99
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 14 deletions.
14 changes: 6 additions & 8 deletions include/haproxy/h1.h
Original file line number Diff line number Diff line change
Expand Up @@ -303,14 +303,12 @@ static inline int h1_parse_chunk_size(const struct buffer *buf, int start, int s
* for the end of chunk size.
*/
while (1) {
if (likely(HTTP_IS_CRLF(*ptr))) {
/* we now have a CR or an LF at ptr */
if (likely(*ptr == '\r')) {
if (++ptr >= end)
ptr = b_orig(buf);
if (--stop == 0)
return 0;
}
if (likely(*ptr == '\r')) {
/* we now have a CR, it must be followed by a LF */
if (++ptr >= end)
ptr = b_orig(buf);
if (--stop == 0)
return 0;

if (*ptr != '\n')
goto error;
Expand Down
7 changes: 1 addition & 6 deletions src/h1_htx.c
Original file line number Diff line number Diff line change
Expand Up @@ -693,11 +693,6 @@ static size_t h1_parse_full_contig_chunks(struct h1m *h1m, struct htx **dsthtx,
++ridx;
break;
}
else if (end[ridx] == '\n') {
/* Parse LF only, nothing more to do */
++ridx;
break;
}
else if (likely(end[ridx] == ';')) {
/* chunk extension, ends at next CRLF */
if (!++ridx)
Expand All @@ -710,7 +705,7 @@ static size_t h1_parse_full_contig_chunks(struct h1m *h1m, struct htx **dsthtx,
continue;
}
else {
/* all other characters are unexpected */
/* all other characters are unexpected, especially LF alone */
goto parsing_error;
}
}
Expand Down

0 comments on commit 4837e99

Please sign in to comment.