Repository navigation
fix: pin auth scheme and credential fields to the issued request - #766
prasanna8585 wants to merge 1 commit into
Conversation
storeAuthAndCollectResumeTargets took authConfig.authScheme (and
rawAuthCredential/exchangedAuthCredential, except credentialKey)
directly from authResponses[fcId] -- the CLIENT's response to an
adk_request_credential call -- rather than from the request this
server originally issued.
authScheme names the OAuth2 token endpoint that
OAuth2CredentialExchanger.exchange() POSTs the developer's
clientSecret and the authorization code to
(getTokenEndpoint(authScheme) -> fetchOAuth2Tokens(tokenEndpoint,
body)). A malicious or compromised client could therefore forge a
response with authScheme.tokenEndpoint pointed at an
attacker-controlled server, causing the token exchange -- including
the developer's real OAuth2 client secret -- to be sent there instead
of the legitimate provider, enabling an authorization-code
interception attack.
Mirrors adk-python's identical, already-fixed vulnerability in the
same-named auth_preprocessor.py ("fix(auth): take the auth scheme
from the request, not the client's response"), whose own test
docstring states the risk explicitly: taking the scheme from the
response would let a client redirect the token exchange, and the
developer's secret with it, to itself. Also ports
_merge_credential_oauth2_fields as mergeCredentialOAuth2Fields, since
adk-js had no equivalent helper and rawAuthCredential/
exchangedAuthCredential were similarly unpinned.
Also adds a fail-closed guard: a response with no matching request in
history is now skipped entirely (previously it would still reach
AuthHandler with an authConfig entirely controlled by the response).
Adds two regression tests: one confirming the token endpoint used is
the one the server issued even when the response claims a different
one, and one confirming an unmatched response never reaches
AuthHandler. Both were verified to fail against the pre-fix code
(exact assertion failure: expected the attacker's forged endpoint to
equal the real one) before the fix was applied, and pass after.
|
This is a real bug and you diagnosed it correctly — but it's since been fixed on For what it's worth, here's what's now on return {
...requested,
oauth2: {...requested.oauth2, ...answer}, // answer = authResponseUri, authCode only
};That's an allowlist rather than a gap-fill merge, which turns out to matter. I reproduced this branch's behaviour before comparing: with The other reason to take the One more thing worth passing on, because it was a good catch on your part that I'd want to keep: your JSDoc says the helper mirrors adk-python's, and I checked the upstream function — it uses a five-field allowlist and logs a So I'm going to close this as superseded. Genuinely sorry to do that to a correct finding that was filed first — if you hit the |
|
Hey @ScottMansfield , Thanks for the genuinely thorough writeup -- I appreciate you taking the time to show exactly what main does differently rather than just closing it out. The allowlist-vs-gap-fill distinction is a real difference in strength and I hadn't considered the state/codeVerifier angle specifically, so that's a useful thing to have internalized for next time. Good catch on hitl_utils.ts too -- I'd only swept auth_preprocessor.ts and clearly should have grepped for other AuthConfig construction sites. Happy to send the small PR adding the warning log to match adk-python's behavior, since you mentioned you'd take it -- I'll get that over shortly. Thanks again for reviewing all of these so carefully. Best, |
storeAuthAndCollectResumeTargetstookauthConfig.authScheme(andrawAuthCredential/exchangedAuthCredential, exceptcredentialKey) directly fromauthResponses[fcId]— the CLIENT's response to anadk_request_credentialcall — rather than from the request this server originally issued.authSchemenames the OAuth2 token endpoint thatOAuth2CredentialExchanger.exchange()POSTs the developer'sclientSecretand the authorization code to (getTokenEndpoint(authScheme)→fetchOAuth2Tokens(tokenEndpoint, body)). A malicious or compromised client could therefore forge a response withauthScheme.tokenEndpointpointed at an attacker-controlled server, causing the token exchange — including the developer's real OAuth2 client secret — to be sent there instead of the legitimate provider, enabling an authorization-code interception attack.Mirrors adk-python's identical, already-fixed vulnerability in the same-named
auth_preprocessor.py("fix(auth): take the auth scheme from the request, not the client's response", commit8989aead), whose own test docstring states the risk explicitly: taking the scheme from the response would let a client redirect the token exchange, and the developer's secret with it, to itself. Also ports_merge_credential_oauth2_fieldsasmergeCredentialOAuth2Fields, since adk-js had no equivalent helper andrawAuthCredential/exchangedAuthCredentialwere similarly unpinned.Also adds a fail-closed guard: a response with no matching request in history is now skipped entirely (previously it would still reach
AuthHandlerwith anauthConfigentirely controlled by the response).Adds two regression tests: one confirming the token endpoint used is the one the server issued even when the response claims a different one, and one confirming an unmatched response never reaches
AuthHandler. Both were verified to fail against the pre-fix code (exact assertion failure: expected the attacker's forged endpoint to equal the real one) before the fix was applied, and pass after.Verified: both new tests fail against the pre-fix code with the exact expected assertion failure, and pass after the fix. Broader
core/test/auth/suite passes clean (12 files, 176/176 tests).tsc --noEmitclean.