fix(gateway): match Proxy-Authorization scheme case-insensitively - #483
Open
tenequm wants to merge 4 commits into
Open
fix(gateway): match Proxy-Authorization scheme case-insensitively#483tenequm wants to merge 4 commits into
tenequm wants to merge 4 commits into
Conversation
RFC 7235 2.1 defines auth-scheme as a case-insensitive token, but
extract_agent_token matched it byte-for-byte with strip_prefix("Basic ").
PySocks emits the lowercase form, so every httplib2-based client (which
includes google-api-python-client) had its agent token dropped.
The failure was silent: no token meant intercept stayed false and the
gateway plain-tunneled the connection, so the request left the sandbox
unauthenticated with no credential injected and no error surfaced.
Compare the scheme case-insensitively and leave every other behavior
unchanged. Bearer in any casing is still rejected.
|
All contributors have signed the CLA ✍️ ✅ |
Contributor
Author
|
I have read the CLA Document and I hereby sign the CLA |
Contributor
Author
|
recheck |
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.
I have read the CONTRIBUTING.md file.
YES
What kind of change does this PR introduce?
Bug fix (gateway).
What is the current behavior?
extract_agent_tokenmatches theProxy-Authorizationauth-scheme byte-for-byte:RFC 7235 section 2.1 defines
auth-schemeas a case-insensitive token, and PySocks emits the lowercase form:PySocks is what httplib2 uses for proxy support, so this affects every httplib2-based client. That includes
google-api-python-client, and therefore any Python MCP server or script reaching a Google API through the gateway.The failure mode is silent rather than loud.
extract_agent_tokenreturnsNone, the CONNECT carries no agent identity, andinterceptstaysfalse(apps/gateway/src/gateway.rs:786-812), so the gateway plain-tunnels the connection. No 407, no error: the request leaves the sandbox unauthenticated, with no credential injected, and the only trace isproject_id="-"in the gateway logs. A client that should have been credentialed instead reaches the upstream API as an anonymous caller.An invalid token is handled correctly (407). Only the casing mismatch takes this path, because a dropped token is indistinguishable from "no proxy auth was offered at all".
Reproduce with any httplib2 caller through the gateway, or directly:
Prior art in this repo:
validate_api_key(apps/gateway/src/auth.rs:119-120) already handles the same class of problem forAuthorization, viastrip_prefix("Bearer ").or_else(|| strip_prefix("bearer ")). That form covers two casings but still missesBEARER, which is why this PR compares the scheme rather than enumerating spellings.What is the new behavior?
The scheme is compared case-insensitively. Everything else is unchanged:
Bearerin any casing still returnsNone, and the base64 payload is still trimmed and decoded exactly as before. I walked the input shapes (Basic/basic/mixed case, no-space, trailing-space, leading-space, double-space, tab-separated, wrong scheme) and the only behavioral difference is the intended one.Four tests added alongside the existing
extract_agent_tokencases: lowercasebasic, mixed-caseBaSiC, and lowercasebearerstill rejected. The mixed-case test is deliberate: it fails against theor_else(strip_prefix("basic "))shape, so a future revert to that idiom will not pass silently.Checks
Run locally on this branch:
cargo testinapps/gateway: 521 passed, 0 failedcargo fmt --checkandcargo clippy --all-targets: cleanpnpm build: 2/2 tasks successfulpnpm check: 9/9 tasks successful