Close two paths that reach services past their intended gate - #3512
Open
chenBright wants to merge 1 commit into
Open
Close two paths that reach services past their intended gate#3512chenBright wants to merge 1 commit into
chenBright wants to merge 1 commit into
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR hardens bRPC’s HTTP dispatch and HTTP/2 header parsing to prevent “padded path” variants (with empty segments like //) and invalid HTTP/2 :path values from reaching services (notably builtin services) past intended proxy/ACL gates.
Changes:
- Reject HTTP paths containing empty segments (
//) by default inFindMethodPropertyByURI, with a new opt-out flag-http_allow_empty_path_segmentsto preserve legacy behavior. - Enforce RFC 9113
:pathvalidation in HTTP/2 header consumption: non-empty and starting with/unless exactly*. - Update/add unit tests to cover the new rejection behavior and the opt-out flag behavior.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
src/brpc/policy/http_rpc_protocol.cpp |
Adds -http_allow_empty_path_segments and rejects // paths by default in method resolution. |
src/brpc/policy/http2_rpc_protocol.cpp |
Rejects invalid HTTP/2 :path values (empty or not starting with /, except *). |
test/brpc_server_unittest.cpp |
Updates server-side HTTP routing tests and adds a scoped flag helper for legacy behavior. |
test/brpc_http_message_unittest.cpp |
Updates FindMethodPropertyByURI tests and adds coverage for rejecting empty path segments + flag override. |
test/brpc_http_rpc_protocol_unittest.cpp |
Adds HTTP/2 unit test verifying :path validation behavior. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
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.
What problem does this PR solve?
Issue Number: resolve
Problem Summary:
Paths that differ only in empty segments dispatched identically.
FindMethodPropertyByURIImplsplitsthe path with a
StringSplitterthat skips empty fields, so//flags,/flags//and/flags//portall resolvedto the same method as
/flags. RFC 3986 treats//fooand/fooas distinct paths, so a front proxy whoseACL matches the collapsed form does not match the padded one and passes it through —
//flags?setvalue=reaches a builtin service that
/flagscannot. Normalizing the path server-side would not help, because theproxy has already forwarded the padded literal; only rejecting it removes the differential.
The same audit found that HTTP/2 never validated
:path. RFC 9113 8.3.1 requires it to be non-empty and,apart from the asterisk-form used by
OPTIONS, to begin with/.What is changed and the side effects?
Changed:
FindMethodPropertyByURIrejects any path containing//. The check lives inthe funnel rather than in
FindMethodPropertyByURIImpl, so it also covers theglobal restful map, which does its own
NormalizeSlashes.H2StreamContext::ConsumeHeadersrejects a:paththat is empty or does notbegin with
/, unless it is exactly*.Side effects:
Performance effects:
Breaking backward compatibility:
Check List: