Repository navigation
fix: forward-proxy requests no longer misread as self, restoring per-upstream window config (#562) - #563
Conversation
…upstream window config (#562) resolveUpstream() decided "is this the proxy itself?" by comparing the absolute-URL authority against the client-provided Host header. In a real forward proxy the client sets Host to the UPSTREAM (== the URL authority), so every legitimate forward-proxy request was misclassified as a self-request and dropped to undefined — losing per-upstream context-window config (route?.rewrittenUrl undefined) while the fallback forward still reached the upstream (chat kept working, the window silently did not). Every well-formed absolute-form request is now marked a tunnel and routed through checkTunnelDestination, whose self-layer (destination port == our bound port AND a local-machine IP) 403s a genuine self-forward before any forwarding — no silent fall-through to the fallback path. Self-detection uses the actual listening endpoint instead of the client-provided Host header. Tests: forward-proxy (Host == upstream authority) routes as a tunnel; the forward-proxy and /bili/ forms of the same upstream resolve the same model window; a self-targeting absolute URL is denied with 403 instead of forwarded.
📦 Built Package ArtifactBranch: Option A — Install from npm PR tag (recommended)npm install -g billion-context@pr-563Each push to this PR publishes a new version under the Option B — Download artifact
tar xzf billion-context-pr563.tgz
npm install -g packageThis comment is automatically updated on each push. |
[bot] 🏷 Reviewed #563 (fix for the forward-proxy self-misclassification). Verdict: LGTM — correct, root-cause, and well-covered. No blocking issues. Triage (bug verification)Bug is real — confirmed at code level. In base const ownHost = (req?.headers.host ?? "").toLowerCase();
if (u.host.toLowerCase() !== ownHost) { return { …, tunnel: true }; }
// else → fall through to `return undefined`In a real HTTP forward proxy the client sets
Layer: the diagnosis hits the root cause, not a symptom. Using a client-supplied header as a self-detection signal is fundamentally unsound for a forward proxy (the header IS the upstream). The fix removes that signal and decides self-ness from the actual listening endpoint via Solution assessmentCorrect and strictly safer than the status quo:
Pre-flight (ran locally on the PR head)
Minor notes (non-blocking)
Recommendation: merge-ready. Per repo rules I can't merge PRs (human-only) — please merge when you're ready: #563 |
…s in tunnel-guard WHATWG URL canonicalizes [::ffff:127.0.0.1] to the hex form [::ffff:7f00:1], which sailed past classifyIp's dotted-only matcher as 'public' — a remote client could tunnel to loopback, RFC1918, or 169.254.169.254 metadata through the hex spelling (#409 follow-up found while reviewing #562). Fold both mapped spellings to the dotted quad via normalizeIpLiteral at the checkTunnelDestination entry, and treat 0.0.0.0/:: destinations on our own serving port as the self-loop they route to (previously misrouted to the default upstream after one hop-marker bounce).
Fixes #562.
What changed
resolveUpstream()(src/server.ts) decided whether an absolute-form request targeted the proxy itself by comparing the URL authority against the client-providedHostheader. In a real HTTP forward proxy the client setsHostto the upstream (== the URL authority), so every legitimate forward-proxy request was misclassified as a self-request and dropped toundefined. Consequences:embeddedUrl = route?.rewrittenUrl) receivedundefined→ the per-upstream model-window config was silently missed (fell back to the global window).buildForwardTargetstill forwarded via the full URL → chat kept working while the window config did not take effect.Fix
Every well-formed absolute-form request is now marked a tunnel and routed through
checkTunnelDestination, whose self-layer (destination port == our bound port AND a local-machine IP) 403s a genuine self-forward before any forwarding — no silent fall-through to the fallback path. Self-detection now uses the actual listening endpoint instead of the client-providedHostheader. This preserves the original goals (prevent self-loop + keep the management plane unreachable through the tunnel) while fixing the misclassification./bili/, CONNECT/MITM, and the admin gate are unchanged.Regression coverage (mapped to the issue's list)
Host) forwards correctly — the existingforward-absolute-urltest now exercises the previously-broken branch (before, it only passed via the fallback forward).resolveConfiguredContextLimiton the resolvedrewrittenUrl, not the global default./bili/forms of the same upstream resolve to the same window.tunnel_destination_denied) instead of being forwarded; admin/tunnel protection does not regress (self-targets still carry the tunnel marker + admission gate).Pre-flight
npm run typecheck— passnpm test— 1049/1050. The single failure (tests/launcher.test.ts→resolveClientCommand: codex/claude resolve to themselves) is pre-existing and environment-specific: this sandbox has a realcodexbinary at/usr/bin/codex, sowhich codexresolves to the absolute path rather than the bare name the test expects. Verified it fails identically with these changes stashed. Unrelated to this change.npm run build— passtests/e2e/e2e-codex.test.ts) not run here: it requires a live local sglang upstream at127.0.0.1:8199, which is outside this sandbox's permitted network boundary. Note the e2e drives codex via origin-form //bili/requests, which do not exercise the forward-proxy (absolute-form) branch touched here; that branch is covered directly by the new unit + integration tests above.