Repository navigation
🐛 fix: smuggling and header hygiene coverage for proxy relays #19228
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
9a67d04
🐛 fix: smuggling and header hygiene coverage for proxy relays
hivecommons-hive[bot] 656fdd9
[scanner] fix: correct te_space_before_colon smuggling table expectation
hivecommons-hive[bot] 0f8b62e
🐛 fix: te-space-before-colon smuggling case accepts a refused forward
hivecommons-hive[bot] 2443937
Merge branch 'v5' into scanner/fix-19223
hivecommons-hive[bot] 93d8796
Merge branch 'v5' into scanner/fix-19223
hivecommons-hive[bot] b600dc4
Merge branch 'v5' into scanner/fix-19223
hivecommons-hive[bot] a92b9e5
Merge branch 'v5' into scanner/fix-19223
hivecommons-hive[bot] b46bfd9
Merge branch 'v5' into scanner/fix-19223
hivecommons-hive[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| - **Proxy: inspected relays refuse a request that names another host or carries a dot segment** ([#19223](https://github.com/hivecommons/hive/issues/19223)). Inside a MITM'd session, a Host header or absolute-form URL naming a host other than the CONNECT target is now refused with a 400 and the connection closed, as the sandbox read relay already did; the rule engine and credential were chosen for the CONNECT host. A `.` or `..` path segment, in any percent-encoded spelling, is refused on the inspected relay (400) and the sandbox read relay (403), since the gates match the literal path while an upstream that resolves dot segments acts on a different one. New table tests pin that CL+TE, duplicate or malformed Content-Length, unknown Transfer-Encoding, folded headers and bare LF never reach the upstream with ambiguous framing on `proxyHTTPHost`, `forwardPlainDirect` and the sandbox read relay. |
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| package proxy | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "net" | ||
| "net/http" | ||
| "net/url" | ||
| "strings" | ||
| ) | ||
|
|
||
| // Request-target hygiene for the parsed agent relays (#19223, egress audit | ||
| // section 4). | ||
| // | ||
| // Framing ambiguity (CL+TE, duplicate or malformed Content-Length, unknown | ||
| // Transfer-Encoding, folded headers, bare LF) is settled by net/http before a | ||
| // request reaches any gate: ReadRequest refuses what it cannot frame and | ||
| // req.Write regenerates one framing for the next hop, so the gates and the | ||
| // upstream always agree on where a request ends. relay_smuggling_test.go pins | ||
| // that, per relay. | ||
| // | ||
| // What net/http does NOT settle is which resource a request names, and two | ||
| // spellings let the gates and the upstream disagree: | ||
| // | ||
| // - A Host header or absolute-form URL naming a host other than the one the | ||
| // TLS session was forged for. The rule engine (GitHub vs Linear) and the | ||
| // credential were chosen for the CONNECT host; a request naming another | ||
| // host must not ride that decision. | ||
| // - A dot segment ("." or "..", in any percent-encoded spelling) in the path. | ||
| // The gates match the literal path, but an upstream that resolves dot | ||
| // segments acts on a different one: /repos/allowed/r/../../paused/r/merge | ||
| // is gated as allowed/r and merged as paused/r. No legitimate client sends | ||
| // one, so it is refused rather than resolved. | ||
| // | ||
| // Both refusals are fail-closed: a target that cannot be decoded is refused. | ||
|
|
||
| // relayPathHasDotSegment reports whether an escaped request path contains a | ||
| // "." or ".." segment in any percent-encoded spelling, or a segment that | ||
| // cannot be decoded at all. | ||
| func relayPathHasDotSegment(escapedPath string) bool { | ||
| for _, seg := range strings.Split(escapedPath, "/") { | ||
| decoded, err := url.PathUnescape(seg) | ||
| if err != nil { | ||
| return true | ||
| } | ||
| // A decoded segment can still carry an encoded slash ("..%2F"): split | ||
| // again so each piece the upstream might see is checked. | ||
| for _, piece := range strings.Split(decoded, "/") { | ||
| if piece == "." || piece == ".." { | ||
| return true | ||
| } | ||
| } | ||
| } | ||
| return false | ||
| } | ||
|
|
||
| // relayRequestTargetRefusal reports why a request parsed off a terminated TLS | ||
| // session for host must not be forwarded. An empty host is the GitHub-implied | ||
| // proxyHTTP form, which names no CONNECT target to compare against, so only | ||
| // the path check applies there. | ||
| func relayRequestTargetRefusal(req *http.Request, host string) (string, bool) { | ||
| if req.URL == nil { | ||
| return "the request target could not be parsed", true | ||
| } | ||
| if host != "" && !sandboxReadRequestTargetsHost(req, host) { | ||
| return "the request names a different host than the CONNECT target", true | ||
| } | ||
| if relayPathHasDotSegment(req.URL.EscapedPath()) { | ||
| return "the request path contains a dot segment", true | ||
| } | ||
| return "", false | ||
| } | ||
|
|
||
| // writeRelayBadRequest answers a refused request target. The connection is | ||
| // closed after it, so nothing pipelined behind the request is read. | ||
| func writeRelayBadRequest(w net.Conn, reason string) error { | ||
| body := "blocked by hive: " + reason + "\n" | ||
| _, err := fmt.Fprintf(w, "HTTP/1.1 400 Bad Request\r\nContent-Type: text/plain; charset=utf-8\r\nX-Hive-Proxy-Blocked: true\r\nContent-Length: %d\r\nConnection: close\r\n\r\n%s", len(body), body) | ||
| return err | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Header comment is truncated mid-sentence ("so the gates and the" / "that, per relay."). Please reword; comment-only.