Repository navigation
Reject invalid :method and :path in HTTP/2 requests - #747
Merged
Merged
Conversation
HTTP/1 rejects a request line whose method is not a token or whose request-target contains control bytes or whitespace (mtrudel#713). HTTP/2 took :method as is and checked :path only for a leading / or *. The field-value check already rejects control bytes and DEL in both, but it allows internal SP and HTAB and says nothing about token syntax, so a :method of "", "GE T" or "GET/1" or a :path of "/a b" reached the Plug.Conn. RFC9113§8.3.1 requires a valid value for each, so reject a :method that is not a token (RFC9110§9.1) and a :path containing SP or HTAB with a stream PROTOCOL_ERROR. The :path check is the HTTP/1 request line check, now shared through Bandit.Headers along with the tchar guard, so non-ASCII bytes are still accepted by both.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
HTTP/1 rejects a request line whose method is not a token or whose request-target contains control bytes or whitespace (#713). HTTP/2 did not apply the same checks to the
:methodand:pathpseudo-headers::methodwas taken as is and:pathwas checked only for a leading/or*. The field-value check already rejects control bytes and DEL in both, but it allows internal SP and HTAB and does not check token syntax. A:methodof"","GE T"or"GET/1", or a:pathof"/a b", reached thePlug.Connover HTTP/2 while the same bytes get a 400 over HTTP/1.This change rejects, with a stream error of type PROTOCOL_ERROR, a
:methodthat is not a non-empty token (RFC9110§9.1) and a:pathcontaining SP or HTAB (RFC9113§8.3.1). The:pathcheck is the HTTP/1 request-line check from #713. It moves fromBandit.HTTP1.SocketintoBandit.Headersunchanged, together with theis_tcharguard, so both protocols use one definition;field_value_valid?/1is already shared the same way. Non-ASCII bytes in:pathare still accepted, as they are over HTTP/1.Eight tests in a new block in
test/bandit/http2/protocol_test.exs::methodcontaining a space, a tab, a delimiter, a non-ASCII byte, and empty;:pathcontaining a space and a tab; and a positive case forGET,PURGEandM-SEARCHwith percent-encoded and non-ASCII paths. The seven negative cases fail without the change.Verified with
mix format --check-formatted,mix compile --warnings-as-errors,mix credo --strict,mix dialyzer, andmix teston Elixir 1.20.4 / OTP 29 (1082 passed, 1 skipped, 8 excluded; the 3 failures are inHibernationTestand also fail on main under OTP 29). I did not run h2spec locally.