Skip to content

validate request pseudo-header values in DefaultH2RequestConverter - #1550

Open
rootvector2 wants to merge 1 commit into
apache:masterfrom
rootvector2:h2-pseudo-header-grammar
Open

rootvector2 wants to merge 1 commit into
apache:masterfrom
rootvector2:h2-pseudo-header-grammar

Conversation

@rootvector2

@rootvector2 rootvector2 commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

DefaultH2RequestConverter#convert accepts any :method or :scheme that passes the generic field-value check, so :method: GET /admin HTTP/1.1 reaches the handler and is re-serialized by BasicLineFormatter as GET /admin HTTP/1.1 /public HTTP/1.1 on an HTTP/1.1 downgrade (request-line injection, which the HTTP/1.1 front end cannot produce because BasicLineParser splits on whitespace); found by reading the converter against RFC 9113 section 8.3.1 and reproduced with the converter and formatter, so validate :method as an RFC 9110 token and :scheme against the RFC 3986 scheme grammar in the converter, failing the stream with PROTOCOL_ERROR per section 8.1.1, with regression tests.

@ok2c

ok2c commented Dec 2, 2026

Copy link
Copy Markdown
Member

@rootvector2 Please rebase off the latest master

@rootvector2
rootvector2 force-pushed the h2-pseudo-header-grammar branch from 8ad85ad to c3a1105 Compare December 3, 2026 07:31
@rootvector2

Copy link
Copy Markdown
Contributor Author

Rebased onto current master. The branch had been cut from the ForwardedRequest work, which is why the diff was dragging in ForwardedRequest and ZoneIdSupport hunks; it's now just the four httpcore5-h2 files. TestDefaultH2RequestConverter and TestFieldValidationSupport pass and checkstyle is clean on JDK 17.

@arturobernalg arturobernalg left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The :path check only blocks SP/HTAB. RFC 9112 §3 explicitly lists VT (0x0B) and FF (0x0C) as whitespace lenient recipients may split the request-line on, with a smuggling warning. A :path of "/public\u000bHTTP/1.1" still gets through today. Same gap likely applies to :authority, untouched here.

Reject all CTLs (ch <= 0x20 || ch >= 0x7f), not just SP/HTAB, and add a test for it.

@rootvector2
rootvector2 force-pushed the h2-pseudo-header-grammar branch from c3a1105 to 98abb9c Compare December 4, 2026 11:29
@ok2c ok2c added the 5.5.x 5.5 release series label Dec 4, 2026
@ok2c ok2c added this to the 5.5.1 milestone Dec 4, 2026
@ok2c
ok2c requested a review from arturobernalg December 5, 2026 08:29
}

public static boolean isTokenCharValid(final char ch) {
return ch > 0x20 && ch < 0x7f && TOKEN_DELIMITERS.indexOf(ch) < 0;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rootvector2 We should be using BitSet with valid chars for this and other tests to make it less expensive. See Tokenizer or URIBuilder as an example.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. isTokenCharValid and isSchemeValid now do a BitSet lookup against static TOKEN_CHARS (tchar per RFC 9110) and SCHEME_CHARS sets built in a static initializer, same shape as PercentCodec. The indexOf scan and the range chain are gone; tests and checkstyle still pass on JDK 17.

@rootvector2
rootvector2 force-pushed the h2-pseudo-header-grammar branch from 98abb9c to 60e3ff4 Compare December 6, 2026 07:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

5.5.x 5.5 release series

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants