Skip to content

Commit

Permalink
HttpParser detects more bad status #11749
Browse files Browse the repository at this point in the history
Fix #11749 by detecting more bad status codes
  • Loading branch information
gregw committed Oct 24, 2024
1 parent ffdfada commit f16d5d8
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -827,8 +827,8 @@ else if (Violation.CASE_INSENSITIVE_METHOD.isAllowedBy(_complianceMode))
case COLON:
if (!_requestParser)
{
if (t.getType() != HttpTokens.Type.DIGIT)
throw new IllegalCharacterException(_state, t, buffer);
if (t.getType() != HttpTokens.Type.DIGIT || t.getByte() == '0')
throw new BadMessageException("Bad status");
setState(State.STATUS);
setResponseStatus(t.getByte() - '0');
}
Expand Down Expand Up @@ -874,6 +874,8 @@ else if (Violation.CASE_INSENSITIVE_METHOD.isAllowedBy(_complianceMode))
switch (t.getType())
{
case SPACE:
if (_responseStatus < 100)
throw new BadMessageException("Bad status");
setState(State.SPACE2);
break;

Expand All @@ -890,7 +892,7 @@ else if (Violation.CASE_INSENSITIVE_METHOD.isAllowedBy(_complianceMode))
break;

default:
throw new IllegalCharacterException(_state, t, buffer);
throw new BadMessageException("Bad status");
}
break;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1715,6 +1715,22 @@ public void testResponse101WithTransferEncoding(String eoln)
assertTrue(_messageCompleted);
}

@ParameterizedTest
@ValueSource(strings = {"xxx", "0", "00", "50", "050", "0200", "1000", "2xx"})
public void testBadResponseStatus(String status)
{
ByteBuffer buffer = BufferUtil.toBuffer("""
HTTP/1.1 %s %s\r
Content-Length:0\r
\r
""".formatted(status, status), StandardCharsets.ISO_8859_1);

HttpParser.ResponseHandler handler = new Handler();
HttpParser parser = new HttpParser(handler);
parser.parseNext(buffer);
assertThat(_bad, is("Bad status"));
}

@ParameterizedTest
@ValueSource(strings = {"\r\n", "\n"})
public void testResponseReasonIso88591(String eoln)
Expand Down

0 comments on commit f16d5d8

Please sign in to comment.