Skip to content

fix(a2aclient): honor API key security scheme Location - #497

Merged
yarolegovich merged 4 commits into
a2aproject:mainfrom
dongjiang1989:fix-api-key-location
Nov 5, 2026
Merged

yarolegovich merged 4 commits into
a2aproject:mainfrom
dongjiang1989:fix-api-key-location

Conversation

@dongjiang1989

@dongjiang1989 dongjiang1989 commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Problem

AuthInterceptor injects API key credentials into ServiceParams regardless of the scheme's Location field (a2aclient/auth.go). Since the HTTP transports apply ServiceParams as headers (rest.go, jsonrpc.go), keys declared with query or cookie location are sent as an undeclared header and never reach the server where it expects them — authentication fails and the credential leaks into the wrong place on the wire.

Fix

For the HTTP-based protocol bindings (JSON-RPC, REST), attach the credential according to APIKeySecurityScheme.Location:

  • header / unset — unchanged behavior (backward compatible)
  • cookie — sent as a proper Cookie: name=value header. If another interceptor already set cookies, values are merged into a single header (; -joined) as required by RFC 6265 §5.4. Names/credentials containing characters that would corrupt the header or allow cookie injection (;, ,, whitespace, quotes, backslash, control chars) are rejected before the call is made
  • query — attached via context (same side-channel pattern as tenant propagation) and appended to the request URL by the REST and JSON-RPC transports. The helpers are exported as AttachHTTPQueryParams / HTTPQueryParamsFrom so custom Transport implementations can read and apply them instead of silently dropping them
  • unknown — credential is not injected and a warning is logged (matches the Java SDK's defensive behavior)

Non-HTTP transports (gRPC and custom bindings) have no notion of query/cookie locations and only convey ServiceParams, so for them the credential keeps flowing via ServiceParams under the scheme name — the previous behavior is preserved.

Since http.Client.Do errors carry the full request URL, both HTTP transports now strip the query from *url.Error before returning, so query-located credentials cannot leak into error messages and logs.

One non-breaking rename: NewJSONRPCTransport(url string, ...) parameter renamed to serverURL to satisfy revive's import-shadowing check after adding the net/url import.

Tests

  • TestAuthInterceptor_APIKeyLocation (auth_test.go) — header/unset/cookie/query/unknown locations, cookie merging, invalid credential rejection, and gRPC + unknown-binding fallback to ServiceParams
  • TestRESTTransport_QueryParamsFromContext / TestJSONRPCTransport_QueryParamsFromContext — transport-level query injection
  • TestRESTTransport_ErrorRedactsQueryParams / TestJSONRPCTransport_ErrorRedactsQueryParams — request errors do not leak query-located credentials
  • TestAuth_APIKeyQueryLocation_REST / TestAuth_APIKeyCookieLocation_JSONRPC — end-to-end through Client + AuthInterceptor, asserting the credential arrives at the right location and does not leak into headers

go test ./..., go vet, gofmt, and golangci-lint run ./... all pass.

yarolegovich added a commit that referenced this pull request Nov 4, 2026
The authentication interceptor currently prefixes every HTTP security
credential with `Bearer`, including cards advertising `scheme: basic`. A
real Basic-auth endpoint therefore rejects the client with HTTP 401 even
when the stored base64 credentials are correct.

Use the configured HTTP authentication scheme when building
Authorization. OAuth2 continues to use Bearer; an empty HTTP scheme
keeps the existing Bearer fallback for compatibility. This change
concerns HTTP authentication schemes; API-key locations are handled
separately in #497.

Validation:
- REST and JSON-RPC HTTP regressions both return 401 before the fix and
authenticate successfully afterward.
- Go 1.26: focused auth tests, `go mod tidy -diff`, full build, `go vet
./...`, and the full shuffled race suite passed.
- golangci-lint 2.11.4: zero issues.
- Separate clustermode example module build and `git diff --check`
passed.

---------

Co-authored-by: Harshil <[email protected]>
Co-authored-by: Yaroslav Shevchuk <[email protected]>

@yarolegovich yarolegovich left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for the fix! the error leak and grpc behavior change need to be addressed, the rest is minor

Comment thread a2aclient/rest.go Resolved
Comment thread a2aclient/jsonrpc.go Resolved
Comment thread a2aclient/auth.go Resolved
Comment thread a2aclient/auth.go Resolved
Comment thread a2aclient/queryparams.go Resolved
Comment thread a2aclient/auth_location_test.go Resolved
Comment thread a2aclient/auth_location_test.go Resolved
AuthInterceptor previously injected API key credentials into
ServiceParams regardless of the scheme's Location field. Since HTTP
transports apply ServiceParams as headers, keys declared with query or
cookie location were sent as (undeclared) headers and never reached the
server where it expected them.

- header / unset location: unchanged behavior (backward compatible)
- cookie: sent as a proper Cookie header (name=value)
- query: attached via context and appended to the request URL by the
  REST and JSON-RPC transports
- unknown location: credential is not injected and a warning is logged,
  to avoid leaking it to the wrong place on the wire

Signed-off-by: dongjiang1989 <[email protected]>
@dongjiang1989

Copy link
Copy Markdown
Contributor Author

@yarolegovich all fixed. Please re-check it, thx

Comment thread a2aclient/auth.go Resolved
Comment thread a2aclient/auth.go Resolved
Comment thread a2aclient/queryparams.go Resolved
- apply HTTP query params in a2acompat/a2av0 jsonrpc and rest
  transports so query-located API keys reach v0.3 servers; move
  mergeQueryParams/redactURLError to internal/utils and redact
  *url.Error in the compat transports too
- carry the selected interface ProtocolBinding in Request instead of
  matching agent card interface URLs, so a shared URL listed as
  [HTTP+JSON, GRPC] no longer drops query keys on grpc requests
- bump queryparams.go copyright to 2026

Signed-off-by: dongjiang1989 <[email protected]>
@dongjiang1989

dongjiang1989 commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor Author

@yarolegovich round-2 feedback addressed:

  • a2av0 jsonrpc/rest transports now apply HTTPQueryParamsFrom and redact *url.Error; MergeQueryParams/RedactURLError moved to internal/utils and shared by all four transports (with tests in a2acompat/a2av0 and internal/utils)
  • Request now carries the selected ProtocolBinding from c.endpoint; isHTTPProtocolBinding no longer matches card interface URLs, so a shared [HTTP+JSON, GRPC] URL keeps grpc behavior regardless of card order
  • copyright year bumped to 2026

Full suite, vet and golangci-lint pass. Please re-check, thx.

@yarolegovich
yarolegovich merged commit c59beb5 into a2aproject:main Nov 5, 2026
5 checks passed
@dongjiang1989
dongjiang1989 deleted the fix-api-key-location branch November 5, 2026 14:30
yarolegovich added a commit that referenced this pull request Nov 6, 2026
🤖 I have created a release *beep* *boop*
---


## [2.8.0](v2.7.0...v2.8.0)
(2026-11-06)


### Features

* **a2aacp:** add an A2A agent executor for Agent Client Protocol (ACP)
agents ([#491](#491),
[#492](#492),
[#493](#493),
[#494](#494),
[#530](#530),
[#545](#545),
[#548](#548),
[#552](#552),
[#562](#562))
* **a2agrpc:** add GRPCConnectionPool for gRPC client connection reuse
(fixes [#109](#109))
([#382](#382))
([a2411f7](a2411f7))
* **a2asrv:** add NewErrorSanitizer, an opt-in interceptor which logs
request errors in full and sends clients only A2A errors
([#552](#552))
([ece71bc](ece71bc))
* **a2asrv:** agent card HTTP caching (ETag/304, opt-in Cache-Control)
([#496](#496))
([313efd9](313efd9))
* implement structured input extension
([#490](#490))
([367f987](367f987))


### Bug Fixes

* **a2aclient:** honor API key security scheme Location
([#497](#497))
([c59beb5](c59beb5))
* **a2aclient:** honor configured HTTP authentication schemes
([#502](#502))
([413de0c](413de0c))
* **a2aclient:** normalize service param keys set by the client and
AuthInterceptor
([#479](#479))
([96f4df0](96f4df0))
* **a2aclient:** return JSON-RPC errors from non-200 responses
([#559](#559))
([97f1fac](97f1fac))
* **a2acrypto:** reject malformed Unicode before signing
([#450](#450))
([ec6cb14](ec6cb14))
* **a2aevent:** preserve input-required history order
([#501](#501))
([72f94a3](72f94a3))
* **a2aevent:** recover the whole artifact when it changes in place
([#485](#485))
([4d61739](4d61739))
* **a2a:** round-trip null data and nil raw parts through JSON
([#513](#513))
([186decc](186decc))
* **a2asrv:** make ServiceParams.With nil-safe
([#544](#544))
([c6042b8](c6042b8))
* **a2asrv:** preserve escaped tenant REST paths
([#514](#514),
[#562](#562))
([f86cf6c](f86cf6c))
* **a2asrv:** preserve numeric precision in raw card ETags
([#546](#546))
([18c2e72](18c2e72))
* **a2asrv:** reject HEAD before creating task subscriptions
([#481](#481))
([e641e3c](e641e3c))
* **a2asrv:** split comma-separated A2A-Extensions values
([#519](#519))
([db83820](db83820)),
closes [#516](#516)
* **a2av0:** keep security schemes and v0.3 interface in extended agent
cards ([#558](#558))
([196d4bb](196d4bb)),
closes [#556](#556)
* **client:** accept cached status and artifact stream events
([#508](#508))
([ea78132](ea78132))
* **client:** honor streaming interceptor error recovery
([#507](#507))
([737b626](737b626))
* **client:** keep propagated tenants local to each call
([#495](#495))
([0eaf017](0eaf017))
* **client:** preserve escaped REST path segments
([#488](#488))
([8880d8f](8880d8f))
* compare and send A2A-Version as Major.Minor
([#555](#555))
([b5ea753](b5ea753))
* don't fail CancelTask when the canceled execution ends first
([#521](#521))
([1613ae6](1613ae6)),
closes [#518](#518)
* don't move a task to FAILED when cancelation retries run out
([#522](#522))
([247933b](247933b))
* **jsonrpc:** return empty result for successful push config deletion
([#525](#525))
([42d0738](42d0738))
* pass CancelTask metadata over REST
([#520](#520))
([a104b2e](a104b2e)),
closes [#517](#517)
* **pbconv:** preserve JSON data part values
([#503](#503))
([7c040e0](7c040e0))
* **pbconv:** send pkceRequired for authorization code flows
([#542](#542))
([cb2c30b](cb2c30b))
* **push:** cap push notification configs per task
([#405](#405))
([6bb5a68](6bb5a68))
* report executions or cancelations in progress, and messages to
terminal tasks in cluster mode, as UnsupportedOperation
([#552](#552))
([ece71bc](ece71bc))
* **sse:** ignore a leading UTF-8 byte order mark
([#511](#511))
([248f628](248f628))
* **taskexec:** keep the error when broadcasting an event fails
([#536](#536))
([636fa9f](636fa9f))
* **taskexec:** report canceler panics during concurrent cancelation
([#535](#535))
([7ffc680](7ffc680))
* **taskexec:** skip heartbeats for non-positive intervals
([#543](#543))
([c4158ae](c4158ae))
* **taskexec:** wait for the cancelation result of input-required tasks
([#560](#560))
([3194abe](3194abe))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

---------

Co-authored-by: Yaroslav Shevchuk <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants