Repository navigation
fix: reject trailing data after the JSON body - #453
Conversation
nahapetyan-serob
left a comment
There was a problem hiding this comment.
Thanks for the fix. General comments here, I have also left a few inline comments.
- FromRESTError in internal/rest/rest.go still decodes REST error bodies with
json.NewDecoder(resp.Body).Decode - a2acrypto/cannonical.go uses the same pattern, as it has decoder option, we might add an inline check in this case.
Wrap the decoder error into ErrTrailingData so callers keep the original cause, and apply the same check to FromRESTError and agent card canonicalization, which still accepted trailing bytes. Add client transport tests (JSON-RPC, REST and both v0.3 compat transports) because clients now reject responses they used to accept, plus the /message:stream server case.
7f2a519 to
e4c0a91
Compare
|
Thanks for the review, all points are addressed. The helper now wraps the decoder error ( |
Merge the success and failure error checks into a single errors.Is (or wantErr bool) check, and compare the decoded task with cmp.Diff against a full expected value instead of checking the ID alone, so a partly decoded task fails the test. Fold the trailing-whitespace case of the canonicalization test into the table with per-row canonicalize and verify errors. Decode JSON-RPC requests in the client test fakes with utils.DecodeJSON, so the fakes reject trailing data the same way the transports now do.
|
Thanks for the review, all five points are addressed in the latest push.
|
🤖 I have created a release *beep* *boop* --- ## [2.7.0](v2.6.0...v2.7.0) (2026-10-21) ### Features * add input mode validation ([#456](#456)) ([8c814be](8c814be)) * extension point for snapshot materialization logic ([#449](#449)) ([4899045](4899045)) * reject requests with unsupported A2A-Version ([#457](#457)) ([4226e74](4226e74)) * use application/a2a+json with Accept-based negotiation ([#465](#465)) ([a8caf47](a8caf47)) ### Bug Fixes * **a2a:** serialize task status timestamps in UTC ([#452](#452)) ([b657f33](b657f33)) * decode application/a2a+json error responses in the REST client ([#448](#448)) ([3e1aa7f](3e1aa7f)) * **errordetails:** handle nil Value in Typed.MarshalJSON ([#474](#474)) ([73c49ac](73c49ac)) * **grpc:** forward next_page_token in push config list responses ([#455](#455)) ([7210014](7210014)) * **grpc:** keep caller metadata when attaching service params ([#476](#476)) ([f01e895](f01e895)) * honor a2a+json Content Type when Accept is */* or missing ([#468](#468)) ([2169266](2169266)) * reject trailing data after the JSON body ([#453](#453)) ([e85760e](e85760e)) * **rest:** map non-A2A HTTP error responses by status code ([#471](#471)) ([4baba5f](4baba5f)) * return plain error when streaming fails before the first event ([#463](#463)) ([cf62533](cf62533)) * **taskstate:** reject unknown task state values on unmarshal and REST status param ([#404](#404)) ([534a60f](534a60f)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).
Fixes #446
json.NewDecoder(body).Decode(v)stops after the first JSON value, so a body like{...}TRAILING_GARBAGEor two concatenated objects was accepted and processed.Changes:
internal/utils.DecodeJSONdecodes one value and then requires EOF, the same rule asjson.Unmarshal. Trailing whitespace is still accepted.a2asrv(JSON-RPC and the three REST handlers that read a body) and for response bodies ina2aclient(JSON-RPC and REST), plus the same two paths ina2acompat/a2av0.-32700 Parse error(JSON-RPC) or400with a parse error (REST), as a2a-python and a2a-js do.Tests:
internal/utils/json_test.go: single value, trailing whitespace, trailing garbage, concatenated objects, an extra}, empty and invalid input.TestJSONRPC_Validations: trailing data and concatenated requests give a parse error, trailing whitespace still succeeds.TestREST_InvalidPayloads: trailing data and concatenated payloads onmessage:sendandpushNotificationConfigs.The new handler cases fail on
mainand pass with the change.go test ./...passes.