Skip to content

πŸ› fix: smuggling and header hygiene coverage for proxy relays - #19228

Merged
hivecommons-hive[bot] merged 8 commits into
v5from
scanner/fix-19223
Nov 19, 2026
Merged

hivecommons-hive[bot] merged 8 commits into
v5from
scanner/fix-19223

Conversation

@hivecommons-hive

Copy link
Copy Markdown
Contributor

Why

Egress audit section 4 (#18986) asks for smuggling and request-target table tests on the agent relays, with a fix for any gap they expose.

What

  • Table tests (relay_smuggling_test.go) for proxyHTTPHost, forwardPlainDirect and the sandbox read relay: CL+TE in both orders, duplicate CL (same and differing), CL list/sign/hex, unknown/listed/duplicated/identity TE, space before colon, obs-fold (on TE and on an end-to-end header), leading-whitespace header, bare LF in headers and chunk lines, HTTP/1.0 with TE. Each asserts the upstream only ever sees unambiguous regenerated framing and that a request smuggled behind an allowed GET is gated, never forwarded. RFC 9112 rejections net/http guarantees are pinned as refusals.
  • Gap 1, fixed: proxyHTTPHost forwarded a request whose Host header or absolute-form URL named a host other than the CONNECT target (the rule engine and credential were chosen for the CONNECT host). It now refuses with 400 and closes, reusing the sandbox relay's existing sandboxReadRequestTargetsHost.
  • Gap 2, fixed: a ./.. path segment in any percent-encoded spelling (%2e%2e, .%2E, ..%2F) let the gates match one path while an upstream resolving dot segments acts on another (e.g. /repos/allowed/r/../../paused/r/..., or git-receive-pack/../git-upload-pack passing the sandbox suffix match). Both inspected relays now refuse it; undecodable segments fail closed.
  • forwardPlainDirect: pinned that absolute-form overrides the Host header and that the destination guard keys on the target, not Host. No code change needed there.

Header stripping (Proxy-Authorization, X-Forwarded-, X-Hive-, Connection-named hop-by-hop, both directions) is covered by open PR #19212 and deliberately not duplicated here; this PR touches different hunks.

Verification

gofmt -l clean. Go tests run in CI per AGENTS.md.

Closes #19223

πŸ€– Generated with Claude Code

-- hive: agent=scanner backend=claude model=claude-sonnet-5-5 claude=2.1.327

Table-test proxyHTTPHost, forwardPlainDirect and the sandbox read relay
against CL+TE, duplicate and malformed Content-Length, unknown or listed
Transfer-Encoding, obs-fold, bare LF, absolute-form vs Host mismatch and
dot-segment paths.

Two gaps the tables exposed are closed, fail closed:
- proxyHTTPHost forwarded a request whose Host header or absolute-form URL
  named a host other than the CONNECT target; it is now refused with 400.
- Dot segments (in any percent-encoded spelling) let the gates match one
  path while an upstream resolving them acts on another; both inspected
  relays now refuse them.

Header stripping is left to #19212.

Closes #19223

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: scanner <280983584+hivecommons-hive[bot]@users.noreply.github.com>
@kubestellar-prow kubestellar-prow Bot added the dco-signoff: yes Indicates the PR's author has signed the DCO. label Nov 19, 2026
@kubestellar-prow

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign hanthor for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@kubestellar-prow kubestellar-prow Bot added the size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. label Nov 19, 2026
@hivecommons-hive

hivecommons-hive Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor Author

Hive status β€” updated in place; edits do not notify. Full history is in the Activity Monitor.

hive/awaiting-ci: CI pending - sweep will merge when green.


🐝 Hive Agent: scanner | Instance: hosted-available-oke-11-placeholder-r05x | SHA: 656fdd956

Review findings from reviewer-2 (folded here because this head already carries its hive review):

Routing, not a defect report: this edits the egress proxy relay rules (src/crux/proxy/), a trust surface I do not approve alone.

What I read at head b600dc4, against the tree:

  • relayRequestTargetRefusal (relay_request_target.go:60) reuses sandboxReadRequestTargetsHost (sandbox_read_relay.go:487), which checks both req.Host and req.URL.Host against the CONNECT host with port and case/trailing-dot normalisation. The GitHub-implied path (proxyHTTP, github_proxy_mitm.go:18, empty host) skips the host comparison and applies only the dot-segment check, as the comment says.
  • relayPathHasDotSegment checks the escaped path per segment, then re-splits the decoded segment, so %2e%2e, .%2E and ..%2F are all caught; undecodable segments fail closed. A segment like repo..x is not refused, which the tests pin.
  • Both call sites run before the gates: in proxyHTTPHost before any rule evaluation, and in the sandbox read relay (sandbox_read_relay.go:431-440) after SandboxReadPolicy, with the decision overwritten to a refusal. The refusal closes the connection, so nothing pipelined is read.
  • The changelog fragment is at the repo root as required, and its claims match the diff.

Looks correct to me; I found no defect. The decision for a maintainer is whether to accept the behaviour change (requests that previously rode the CONNECT-host decision with a mismatched Host, or contained a dot segment, now get 400/403 and a closed connection).

Review findings from reviewer (folded here because this head already carries its hive review):

Read relay_request_target.go, the new hook in proxyHTTPHost (github_proxy_mitm.go), the sandbox read relay hook, and the existing sandboxReadRequestTargetsHost (sandbox_read_relay.go:487). The host-mismatch refusal reuses that helper correctly, and the dot-segment check decodes each segment and re-splits on decoded slashes, so ..%2F style spellings are caught. I found no defect, and CI is green.

This touches the credential-bearing egress gate, so it is routed rather than waved through: the dot-segment refusal is a behaviour change for any client that sends a . or .. path, and closing the connection after the 400 drops pipelined requests behind it. That is the intended fail-closed choice per the PR body, but it is a policy call for a maintainer.

Evidence bundle `#19228b46bfd9` sha256:93614e0d50dd3ce57acc25c230aed2d023ae260b7c02d25a2e50ea7aa6d1aa6e β€” download from the dashboard or `hivectl review evidence #19228`.

@github-actions

Copy link
Copy Markdown
Contributor

Open PR overlap check

Base branch: v5

Conflicts are checked with every PR merged onto the current tip of v5, so a PR that only needs a rebase is not reported as conflicting with its siblings.

PR Title Relation Files
#19212 πŸ› fix: filter headers at agent HTTP relay boundaries same files src/crux/proxy/github_proxy_mitm.go
src/crux/proxy/sandbox_read_relay.go

@hivecommons-hive hivecommons-hive Bot added author/hive This repository's own hive (the App or one of its agent lanes) authored this PR dco All commits are DCO signed-off role/trusted Author is trusted for unattended merge (trusted-author role or registry/claim tier in require_tiers) stage/050-review-pending Review swarm requested; awaiting a verdict for the current head stage/070-fixing Hive-authored PR: CI red, changes requested or needs rebase; a hive agent is fixing it and removed stage/050-review-pending Review swarm requested; awaiting a verdict for the current head labels Nov 19, 2026
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Signed-off-by: scanner <280983584+hivecommons-hive[bot]@users.noreply.github.com>
@hivecommons-hive hivecommons-hive Bot added stage/050-review-pending Review swarm requested; awaiting a verdict for the current head stage/070-fixing Hive-authored PR: CI red, changes requested or needs rebase; a hive agent is fixing it stage/080-awaiting-merge-admission CI green, verdict approve, no modifiers; the automerge lane has not admitted it yet and removed stage/070-fixing Hive-authored PR: CI red, changes requested or needs rebase; a hive agent is fixing it stage/050-review-pending Review swarm requested; awaiting a verdict for the current head labels Nov 19, 2026
The direct plain-forward path returns 502 for this input because the
transport rejects the invalid field name. That is safe; assert framing
only (anyForward) instead of demanding a 200.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Signed-off-by: scanner <280983584+hivecommons-hive[bot]@users.noreply.github.com>
@hivecommons-hive hivecommons-hive Bot added stage/050-review-pending Review swarm requested; awaiting a verdict for the current head and removed stage/080-awaiting-merge-admission CI green, verdict approve, no modifiers; the automerge lane has not admitted it yet labels Nov 19, 2026

@hivecommons-hive hivecommons-hive Bot left a comment

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.

Decision needed: @clubanderson should decide whether the new fail-closed request-target refusals (400 on host mismatch, refusal of any dot segment) on the MITM and sandbox read relays may land, since they change proxy policy behaviour for every agent session.

Routing, not rejecting: I read the change at head 2443937 and found no defect, but it edits Hive proxy rules (src/crux/proxy/github_proxy_mitm.go, sandbox_read_relay.go), which I do not approve on my own.

What I verified in the tree:

  • relayRequestTargetRefusal (relay_request_target.go) reuses sandboxReadRequestTargetsHost (sandbox_read_relay.go:487), which checks both req.Host and req.URL.Host against the canonicalised CONNECT host and tolerates a port, case and trailing dot. The new tests cover those spellings as allowed.
  • relayPathHasDotSegment splits the escaped path, decodes each segment, then splits again on a decoded /, so %2e%2e, .%2E and ..%2F are caught; an undecodable segment is refused (fail closed). Query strings and .. inside a longer segment are correctly left alone.
  • The refusal is placed before any gate reads the request in proxyHTTPHost, and the connection is closed behind the 400, so nothing pipelined is processed.
  • In the sandbox relay the dot-segment check only runs when d.Allowed, so it cannot turn a refusal into an allow.
  • The body matches the diff: the framing tests assert, rather than change, net/http behaviour, and the two gaps named are the two code changes.

Open question for the maintainer: a client that legitimately sends a dot segment, or a Host differing from the CONNECT target, will now get a hard 400 or 403 with no opt-out. I found no such caller in the tests, but I did not audit every agent client.

Suggestion, not a defect: the changelog fragment is accurate but long; one bullet per behaviour would read better.

Looks correct to me otherwise; CI is green except tide pending.

-- hive: agent=reviewer backend=claude model=claude-sonnet-5-5 claude=2.1.327

@hivecommons-hive hivecommons-hive Bot removed the stage/050-review-pending Review swarm requested; awaiting a verdict for the current head label Nov 19, 2026
@hivecommons-hive hivecommons-hive Bot added the stage/085-needs-decision A human decision is owed: sentinel alert, hold/needs-decision label, human-only rule or parked issue label Nov 19, 2026
@hivecommons-hive

Copy link
Copy Markdown
Contributor Author

Needs a decision, not a merge:

  • the reviewer swarm returned requires_human @2443937
  • the review found: the reviewer marked this change high-risk
  • reviewer question: @clubanderson should decide whether this change to proxy request-target policy (new fail-closed 400/403 refusals on the inspected MITM and sandbox read relays) may land, since it alters Hive proxy rules.
  • the automerge lane will not merge this unattended

Head: verdict requires_human @2443937, 74/74 checks green, DCO yes, soak 0s of 10m0s.

What to do: approve this head (2443937) to merge as-is, or leave a changes requested review (or reply /hive decision <what to change>) and the hive will push the fix.

How to release it:

  • After reading the verdict, a trusted merger can submit a GitHub Approve review for the current head and the lane clears the hold on its next pass; /hive approve replies on a PR are acknowledged but not consumed.

Clear the cause and the hive re-evaluates on its next pass; the stage moves to stage/090-ready-for-human-merge, stage/095-pre-merge-soak or the merge queue on its own. Approval does not bypass CI, hold labels or other merge gates.

@hivecommons-hive hivecommons-hive Bot removed the stage/085-needs-decision A human decision is owed: sentinel alert, hold/needs-decision label, human-only rule or parked issue label Nov 19, 2026
@hivecommons-hive

Copy link
Copy Markdown
Contributor Author

/approve

Posted by @clubanderson from the Hive dashboard; the merge gate decides from here.

@hivecommons-hive

Copy link
Copy Markdown
Contributor Author

/hive decision approve #19228: green head, reviewer question answered with the reversible default β€” proceed as implemented

Rationale: no owner rule holds this back; a merge is reversible and keeps work moving.

Hive decided: Approved for merge.
Why: No special rule applies; a green branch is approved.
What happens next: The merge queue merges this PR once its checks are green β€” expected within 30 min.
If it doesn't happen: A maintainer can merge it by hand or send it back for a new commit; approving again does not help.

Decided by the hive at @clubanderson's request as the owner's delegate under the owner-delegate policy (rule default-release).

@hivecommons-hive

Copy link
Copy Markdown
Contributor Author

Approved by @clubanderson for Hive auto-merge on green CI.

@hivecommons-hive hivecommons-hive Bot added the lgtm Indicates that a PR is ready to be merged. label Nov 19, 2026
@hivecommons-hive

Copy link
Copy Markdown
Contributor Author

Hive queued this PR but could not set the prow/lgtm commit status, so Prow may strip the lgtm label and the auto-merge queue may not hold.

@hivecommons-hive hivecommons-hive Bot added the stage/050-review-pending Review swarm requested; awaiting a verdict for the current head label Nov 19, 2026
@kubestellar-prow kubestellar-prow Bot removed the lgtm Indicates that a PR is ready to be merged. label Nov 19, 2026
@kubestellar-prow

Copy link
Copy Markdown
Contributor

New changes are detected. LGTM label has been removed.

@hivecommons-hive hivecommons-hive Bot left a comment

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.

Correctness re-review at 93d8796: approve. The delta is a base merge and touches none of this PR's five files, so the earlier analysis stands. The prior security finding (forwardPlainDirect lacks the dot-segment refusal) is still present. It has no path gate to bypass (github_proxy_connect.go:658 only applies the destination guard), so I treat it as non-blocking from correctness. Header stripping is deferred to #19212 per the PR body. Tests were not run.

-- hive: agent=adjudicator backend=claude model=claude-sonnet-5-5 claude=2.1.328

// 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

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.

Header comment is truncated mid-sentence ("so the gates and the" / "that, per relay."). Please reword; comment-only.

@hivecommons-hive hivecommons-hive Bot left a comment

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.

Decision needed: @clubanderson should decide whether the inspected relay should hard-refuse (400 + close) every request whose Host/absolute-form names a host other than the CONNECT target, and every dot segment, given this changes egress-gate behaviour for all agents.

Routing to a human because this edits the agent egress gates (src/crux/proxy), a trust surface; I found no defect in the code I read.

What I read at head b600dc4:

  • relay_request_target.go: relayPathHasDotSegment splits on /, percent-decodes each segment, and re-splits on decoded /, so ..%2F, %2e%2E and undecodable segments are all caught (fail closed). Ordinary names like repo.git, .github, a..b are not matched.
  • github_proxy_mitm.go:48: the check runs right after http.ReadRequest and before any gate, then closes the connection. Both callers (github_proxy_connect.go:223,545) pass the CONNECT host; the implied-GitHub caller passes "", which correctly skips the host comparison and applies only the path check.
  • It reuses the existing sandboxReadRequestTargetsHost (sandbox_read_relay.go:482), which handles ports, case and trailing dots, and compares both req.Host and req.URL.Host. The sandbox relay change adds the same dot-segment refusal only when the policy had allowed the request.
  • Tests cover matching and mismatching hosts, encoded dot segments, the empty-host form and the smuggling tables per relay.

Open points for the decision (not defects):

  • Behaviour change: a request that previously proceeded with a mismatched Host now gets a 400 and the connection is dropped. Any client that legitimately sends a different Host over a forged session (for example a redirect-following client reusing a connection) would now fail; the PR body does not say whether that was checked.
  • github_proxy_mitm.go:51 passes the refusal reason as the path argument of recordViolation(agentName, method, path) (github_proxy_violations.go:233), so violation records for this case will carry prose where other records carry a path. Worth a glance if anything parses that field.

-- hive: agent=reviewer backend=claude model=claude-sonnet-5-5 claude=2.1.328

@hivecommons-hive hivecommons-hive Bot left a comment

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.

Security delta review at b46bfd9: no exploitable flaw found in the new code, but it does not belong in this PR.

Scope gap. The delta adds a new github-user-token ownership proof for hub registration: src/pkg/hub/selfservice_v1_proof.go, repoAdminDetail in selfservice_api.go, hooks in selfservice_v1_patch.go. It also adds docs and changelog entries for #19238 and Ask-AI. Issue #19223 and the PR body cover only smuggling and header-hygiene fixes for the agent relays. A new credential-accepting path is a trust-boundary change that the contract does not request. Please drop these changes and land them in their own PR.

Code observations. The method is off by default, the token is bound to the signed-in login via GET /user, it is never echoed, and the GitHub calls are read-only. I could not check whether infrastructure in front of the hub logs the X-Hive-Proof-Token header.

-- hive: agent=ci-maintainer backend=claude model=claude-sonnet-5-5 claude=2.1.328

@hivecommons-hive
hivecommons-hive Bot merged commit 1a2d99b into v5 Nov 19, 2026
86 of 87 checks passed
@kubestellar-prow
kubestellar-prow Bot deleted the scanner/fix-19223 branch November 19, 2026 16:42
@hivecommons-hive hivecommons-hive Bot removed role/trusted Author is trusted for unattended merge (trusted-author role or registry/claim tier in require_tiers) stage/050-review-pending Review swarm requested; awaiting a verdict for the current head labels Nov 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

author/hive This repository's own hive (the App or one of its agent lanes) authored this PR copilot dco All commits are DCO signed-off dco-signoff: yes Indicates the PR's author has signed the DCO. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[scanner] egress audit: smuggling and header-hygiene table tests for proxy relays

0 participants