Skip to content

fix(server): treat request bodies that are not valid UTF-8 as parse errors - #1401

Merged
Iwaniukooo11 merged 2 commits into
a2aproject:mainfrom
jaeminbird:fix/invalid-utf8-body
Oct 30, 2026
Merged

Iwaniukooo11 merged 2 commits into
a2aproject:mainfrom
jaeminbird:fix/invalid-utf8-body

Conversation

@jaeminbird

Copy link
Copy Markdown
Contributor

Description

A request body that is not valid UTF-8 is reported as a server fault: JSON-RPC answers -32603 Internal Error (logged with a traceback at ERROR), and REST message:send, message:stream and pushNotificationConfigs (v1 and v0.3) answer 500. Malformed JSON already gets -32700 / 400. request.json() and protobuf's Parse(bytes) raise UnicodeDecodeError before any JSON error, so neither path catches it.

The JSON-RPC dispatcher now catches UnicodeDecodeError with JSONDecodeError, and parse_lenient turns invalid UTF-8 bytes into ParseError; the REST handlers use it instead of calling Parse directly (all of them already passed ignore_unknown_fields=True). Valid bodies parse exactly as before.

Not covered: v0.3 message:stream returns 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), and uv run pytest --cov=src on Linux pass.

  • Follow the CONTRIBUTING Guide.

  • Make your Pull Request title in the https://www.conventionalcommits.org/ specification.

  • Ensure the tests and linter pass

  • Appropriate docs were updated (not needed)

@jaeminbird
jaeminbird requested a review from a team as a code owner October 29, 2026 06:31
@github-actions

github-actions Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

🧪 Code Coverage (vs main)

⬇️ Download Full Report

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

@Iwaniukooo11 Iwaniukooo11 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.

LGTM

@Iwaniukooo11
Iwaniukooo11 merged commit 56ec855 into a2aproject:main Oct 30, 2026
17 checks passed
@jaeminbird
jaeminbird deleted the fix/invalid-utf8-body branch October 30, 2026 10:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants