Repository navigation
fix(server): treat request bodies that are not valid UTF-8 as parse errors - #1401
Merged
Merged
Conversation
🧪 Code Coverage (vs
|
| Base | PR | Delta | |
|---|---|---|---|
| src/a2a/utils/proto_utils.py | 95.85% | 95.97% | 🟢 +0.12% |
| Total | 93.40% | 93.40% | ⚪️ 0.00% |
Generated by coverage-comment.yml
3 of 4 tasks
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.
Description
A request body that is not valid UTF-8 is reported as a server fault: JSON-RPC answers
-32603Internal Error (logged with a traceback at ERROR), and RESTmessage:send,message:streamandpushNotificationConfigs(v1 and v0.3) answer 500. Malformed JSON already gets-32700/ 400.request.json()and protobuf'sParse(bytes)raiseUnicodeDecodeErrorbefore any JSON error, so neither path catches it.The JSON-RPC dispatcher now catches
UnicodeDecodeErrorwithJSONDecodeError, andparse_lenientturns invalid UTF-8 bytes intoParseError; the REST handlers use it instead of callingParsedirectly (all of them already passedignore_unknown_fields=True). Valid bodies parse exactly as before.Not covered: v0.3
message:streamreturns an empty 200 stream for any malformed body, including plain bad JSON; that's a separate, existing problem.New tests (JSON-RPC, v1 REST x3, v0.3 REST x2,
parse_lenient) fail on main and pass with the fix.ruff check,ruff format --check,ty check(no new diagnostics), anduv run pytest --cov=srcon Linux pass.Follow the
CONTRIBUTINGGuide.Make your Pull Request title in the https://www.conventionalcommits.org/ specification.
Ensure the tests and linter pass
Appropriate docs were updated (not needed)