Skip to content

πŸ› fix: consistent redirect policy and credential stripping for http clients - #19226

Open
hivecommons-hive[bot] wants to merge 2 commits into
v5from
scanner/fix-19222
Open

hivecommons-hive[bot] wants to merge 2 commits into
v5from
scanner/fix-19222

Conversation

@hivecommons-hive

@hivecommons-hive hivecommons-hive Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Why

Part of the egress audit (#18986, sections 3 and 3b). Several outbound clients that send credentials relied on net/http's default redirect policy, which follows 10 hops, keeps Authorization on a hop to the same domain on another port, to a subdomain, or across an https to http downgrade, and never strips custom headers such as X-IBM-Project-ID or a route's ExtraHeaders. An upstream answering with a redirect could walk the gateway key or a GitHub token to another host.

What

  • src/crux/proxy/egress_redirect.go: new egressCheckRedirect policy (3 hops, matching ssrfMaxRedirects; http(s) only; credential headers plus route extra headers stripped on any off-host or downgrading hop; same-host redirects keep credentials).
  • Applied to inferenceHTTPClient (all paths; it no longer returns http.DefaultClient, the transport is unchanged), FindEndpointForModel, queryMaxModelLen, probeEntitledModels and defaultReferenceLookup.
  • src/pkg/knowledge: StripCredentialsOnCrossHostRedirect plus knowledgeRedirectPolicy, used by the llm-wiki client, Context7 and CheckRedirectNoPrivate (connector HTTP client). The connector AllowPrivate policy also strips and refuses non-http(s) schemes.
  • src/pkg/hub/lite_enrollment.go: repo-access check no longer forwards the user's GitHub token off-host or to plain http.

Audit results and decisions

  • forwardPlainDirect uses Transport.RoundTrip and never follows redirects. A regression test pins that the 307 is relayed to the agent and the target is never contacted.
  • dialUpstreamRaw hostname case on the chained path: kept as delegation. The upstream proxy resolves the name, so a local resolve would be both split-DNS-wrong and a TOCTOU with no enforcement value. Test pins that the hostname reaches the upstream proxy verbatim while private literals (IPv6 and v4-mapped) are refused before it is asked.
  • Dashboard clients already strip via stripAuthOnCrossHostRedirect; untouched. docsource.go, ssrf_guard.go and other dial-pinning files are not edited (sibling work).

Left for follow-up

  • Hub lite-enrollment keeps its 10-hop limit (existing tests pin it for GHE redirects); the literal is now the named constant liteRepoAccessMaxRedirects and stripping goes through knowledge.StripCredentialsOnCrossHostRedirect. Shrinking the limit is follow-up.
  • Unguarded inspected TLS legs (explicit config for private enterprise hosts) are not addressed here.

Tests added alongside each fix. Not run locally (gofmt only).

Refs #19222

πŸ€– Generated with Claude Code

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

…lients

The egress proxy's own clients (inferenceHTTPClient, FindEndpointForModel,
queryMaxModelLen, probeEntitledModels, defaultReferenceLookup) used
net/http's default redirect policy: 10 hops, Authorization kept on
same-domain/other-port/subdomain hops and https->http downgrades, and custom
headers such as X-IBM-Project-ID never stripped. They now share
egressCheckRedirect: 3 hops, http(s) only, credentials and route
ExtraHeaders stripped on any off-host or downgrading hop.

The knowledge clients and the connector HTTP client gain the same
stripping on top of their private-host policy, and the hub lite-enrollment
repo-access check stops forwarding the GitHub token off-host.

Tests pin that forwardPlainDirect relays redirects without following them,
and the decision for dialUpstreamRaw's chained hostname case: names are
delegated verbatim to the upstream proxy, literal IPs are still refused
locally.

Closes #19222

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

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. Note: the PR body says Closes #19222, but two items remain open: the hub lite-enrollment redirect limit stays at 10 (existing GHE tests require it), and explicit config for private enterprise hosts on the inspected TLS legs is not done. Maintainers may prefer Refs #19222.


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

@github-actions

github-actions Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Open PR overlap check

βœ… Resolved: no conflicting open PRs or same-file overlaps remain against v5.

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

hivecommons-hive Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor Author

Needs a decision, not a merge:

  • the reviewer swarm returned requires_human @f0c2909
  • reviewer summary: security requires human: Not deeply reviewed: the diff touches Hive proxy policy / egress trust surfaces, which are routed to a person rather than judged by the reviewer.
  • the decision-needed label was set by the hive itself

Head: verdict requires_human @f0c2909, 76/77 checks green, 1 pending, DCO yes, soak 0s of 10m0s, labels: decision-needed.

What to do: approve this head (f0c2909) 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.
  • The hive set decision-needed itself for its own gate. Release it (dashboard row menu β†’ Release hold, or remove the decision-needed label) and the lane merges on its next pass once the other gates are clear, or keep it until a maintainer has reviewed the issue's reporter; /hive approve does not remove it.

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.

Updated 2026-11-19 06:40 UTC.

@github-actions

github-actions Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Mutation testing

❌ gremlins did not produce a report for 1 package(s), so no verdict can be derived from this run (see the job log):

  • crux/proxy: gremlins exited 1

Verdict: error (#17349).

@hivecommons-hive hivecommons-hive Bot added decision-needed Hive is blocked on a human decision; a maintainer decides (see hive's comment). needs-owner Only the hive owner can act on this (secrets, tokens, org permissions) labels Nov 19, 2026
@hivecommons-hive

Copy link
Copy Markdown
Contributor Author

owner action required: set or rotate the secret named in the title, then remove decision-needed and needs-owner

Rationale: secrets, PATs and org permissions are the owner's alone. stage/085-needs-decision stays.

Hive decided: Only the hive owner can do this.
Why: Only the hive owner can do this.
What happens next: Nothing by itself. The item stays parked until a person decides it: approve it, give direction, or close it from the Activity Monitor.

Decided by the hive at @hosted-available-oke-11-placeholder-r05x's request as the owner's delegate under the owner-delegate policy (rule owner-only).

@clubanderson

Copy link
Copy Markdown
Member

/hive decision Request changes at f0c2909, then this can merge:

  1. Strip the connector API-key headers on cross-host redirects: add X-Api-Key to the list in src/pkg/knowledge/redirect_credentials.go (fathom.go sends X-Api-Key, limitless.go sends X-API-Key; Header.Del normalises case) and to src/crux/proxy/egress_redirect.go for consistency, with a test that the header is absent after a cross-host hop.
  2. In egressCheckRedirect, on a hop to a different host refuse private, loopback, link-local and metadata targets using the shared netguard classifier, failing closed on resolve errors; allow it only when the original endpoint is itself private (in-cluster model backends). Add a test.
  3. In src/pkg/hub/lite_enrollment.go replace the literal 10 redirect limit with a named constant and also strip Proxy-Authorization on cross-host hops, ideally through the shared helper.
  4. Change "Closes [scanner] egress audit: redirect policy and credential stripping across http.Client valuesΒ #19222" to "Refs [scanner] egress audit: redirect policy and credential stripping across http.Client valuesΒ #19222": the lite-enrollment hop limit and the inspected TLS legs remain follow-up work.
    Optional follow-up, not required here: dashboard/ssrf_guard.go stripAuthOnCrossHostRedirect should also strip on a same-host https to http downgrade.

@clubanderson clubanderson removed the needs-owner Only the hive owner can act on this (secrets, tokens, org permissions) label Nov 19, 2026
@hivecommons-hive hivecommons-hive Bot added stage/070-fixing Hive-authored PR: CI red, changes requested or needs rebase; a hive agent is fixing it and removed stage/085-needs-decision A human decision is owed: sentinel alert, hold/needs-decision label, human-only rule or parked issue labels Nov 19, 2026
@hivecommons-hive

Copy link
Copy Markdown
Contributor Author

Decision recorded by @clubanderson for head f0c2909. The hive is treating it as a changes requested review: this PR moves to the fixing stage and the author agent pushes a new head following your instruction verbatim. The review swarm then re-reviews that head; if it approves, the PR comes back for your merge approval.

…irect limit

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Signed-off-by: scanner <280983584+hivecommons-hive[bot]@users.noreply.github.com>
@hivecommons-hive

Copy link
Copy Markdown
Contributor Author

Thanks. I re-checked each point against f0c2909 before changing anything, and all four were right. Fixed in 71cecc6 on the same branch.

  1. Verified fathom.go:118 sets X-Api-Key and limitless.go:124 sets X-API-Key; neither was in either strip list. Added X-Api-Key to redirect_credentials.go and egress_redirect.go (Header.Del is case-insensitive). Tests: TestEgressCheckRedirectStripsAPIKeyCrossHost, and the knowledge strip test now sets and checks X-Api-Key.
  2. egressCheckRedirect now refuses a hop to a different host that is private, loopback, link-local (metadata) or unresolvable, failing closed on resolve errors, unless the original endpoint is itself private. One deviation: src/crux is a separate Go module that does not import src/pkg/netguard, so I used the proxy's own shared classifier plainForwardDenyReasonAddr (the one the plain-forward guard uses) rather than netguard. If you want netguard itself, that needs a crux go.mod dependency, so say so and I will do it as a follow-up. Test: TestEgressCheckRedirectRefusesPrivateTargets (literals, rebinding name, metadata, unresolvable, localhost, public allowed, private-to-private allowed).
  3. lite_enrollment.go now uses the named constant liteRepoAccessMaxRedirects (value still 10, since existing GHE tests pin it) and strips through knowledge.StripCredentialsOnCrossHostRedirect, which covers Proxy-Authorization. The existing off-host test now asserts it.
  4. Changed the PR body to Refs #19222 and noted the constant in the follow-up list.

Left unchanged: the optional dashboard/ssrf_guard.go https to http downgrade strip, as you marked it not required here. Per CLAUDE.md I did not run the tests locally (gofmt only); CI is the verdict.


🐝 Hive Agent: scanner | Instance: hosted-available-oke-11-placeholder-r05x | SHA: 71cecc6b3

@hivecommons-hive hivecommons-hive Bot added stage/050-review-pending Review swarm requested; awaiting a verdict for the current head and removed stage/070-fixing Hive-authored PR: CI red, changes requested or needs rebase; a hive agent is fixing it labels Nov 19, 2026
@hivecommons-hive hivecommons-hive Bot added 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 decision-needed Hive is blocked on a human decision; a maintainer decides (see hive's comment). labels Nov 19, 2026
@hivecommons-hive

Copy link
Copy Markdown
Contributor Author

πŸ”’ Hold-gate integrity: branch changed while hold-gated β€” fresh review required

This PR's branch moved while it sat hold-gated: the head recorded when the hold was applied was f0c290991a5a, but the branch now sits at 71cecc6b343d. The diff a reviewer saw under the hold is no longer the diff that would merge, so auto-merge is blocked and the decision-needed label has been re-applied.

Commits not present in the hold-time snapshot (1):

  • 71cecc6b343d by hivecommons-hive[bot] β€” πŸ› fix: strip X-Api-Key, refuse private redirect targets, name hub redirect limit

A human should review the FULL diff at the current head β€” a rebase or force-push renames every commit, so everything above needs eyes even if it looks familiar. Removing the hold label after that review is the fresh approval: the guard has re-pinned its snapshot to the current head, so a clean lift re-opens the merge lanes.

@hivecommons-hive hivecommons-hive Bot added the decision-needed Hive is blocked on a human decision; a maintainer decides (see hive's comment). label 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. decision-needed Hive is blocked on a human decision; a maintainer decides (see hive's comment). role/trusted Author is trusted for unattended merge (trusted-author role or registry/claim tier in require_tiers) size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. stage/070-fixing Hive-authored PR: CI red, changes requested or needs rebase; a hive agent is fixing it

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant