Repository navigation
Conversation
Pin the behaviour of the current commons-httpclient 3 based implementation (folding, trimming, duplicates, termination, errors) before replacing it. Signed-off-by: Nico Piel <nico.piel@hotmail.de>
Replace HttpParser.parseHeaders with an equivalent inline parser so the userutil API no longer needs the EOL httpclient 3 jar. Line splitting, folding, trimming, UTF-8 decoding and the error message are unchanged; the parse error is now a java.net.ProtocolException (still an IOException) instead of the httpclient 3 ProtocolException. Signed-off-by: Nico Piel <nico.piel@hotmail.de>
Test Results130 files ± 0 130 suites ±0 3m 58s ⏱️ +47s Results for commit 90c8e09. ± Comparison against base commit 4589238. This pull request removes 2 and adds 23 tests. Note that renamed tests count towards both.♻️ This comment has been updated with latest results. |
mgaffigan
left a comment
There was a problem hiding this comment.
We should not be implementing an HTTP parser. This is how you get more request smuggling vulnerabilities.
Change to some existing parser we're already using. That may break some corner case where a client is sending nonstandard requests - but such things are not reasonably avoidable.
Signed-off-by: Nico Piel <nico.piel@hotmail.de>
|
Agreed. |
mgaffigan
left a comment
There was a problem hiding this comment.
Looks better - can we deprecate this method? Seems like it should not be used - doesn't handle repeated headers - and how is someone getting a set of http headers as a string?
What
HTTPUtil.parseHeadersno longer uses commons-httpclient 3'sHttpParser. It now delegates to httpcore 4.4'sAbstractMessageParser.parseHeaders(httpcore is already on the server classpath), instead of using a custom parser.Why
This is one step toward dropping commons-httpclient 3.0.1. Following review, it uses an existing, maintained parser rather than hand-written parsing code.
Behaviour changes against httpclient 3
HTTPUtilis user-script API, so these are worth a line in the release notes. Well-formed headers (Name: valuelines separated by CRLF or LF, ending at a blank line or EOF) parse the same as before. These corner cases change:org.apache.commons.httpclient.ProtocolException(anIOException),Unable to parse header: <line>org.apache.http.ProtocolException(not anIOException),Invalid header: <line>:v)""orphan)\t)\r\r\n)Invalid header: [0x10])X:thenb)" b""b"a,b,\tc)"a b c""a b c"(only leading whitespace of each fold is dropped)\u000ba\u0001)String.trim)Reviewer notes
str.getBytes()still uses the platform charset and the bytes are decoded as UTF-8, as before.-1), matching the old unlimited behaviour.🤖 Generated with Claude Code