[Bug]: Agent card signature verification raises raw binascii.Error on a malformed protected header instead of SignatureVerificationError
维护者通常 2 天内回复
@rohityan 已经在做这个了。
开始于 2026年10月9日。
评估
这个 Issue 还没有评估数据。
描述
What happened?
create_signature_verifier's verification loop (src/a2a/utils/signing.py:139-159) only catches PyJWTError:
for agent_card_signature in agent_card.signatures:
try:
protected_header_json = base64url_decode(
agent_card_signature.protected.encode('utf-8')
).decode('utf-8') # may raise binascii.Error / UnicodeDecodeError
protected_header = json.loads(protected_header_json) # may raise JSONDecodeError
...
verification_key = key_provider(kid, jku) # may raise anything (e.g. network errors)
jwt.decode(...)
break
except PyJWTError:
continue
agent_card_signature.protected is an attacker-controlled field. A malformed value makes base64url_decode raise a raw binascii.Error, which escapes the verifier entirely — violating the module's own contract: the canonicalization step just above explicitly converts failures to InvalidSignaturesError "so every failure on this path is a SignatureVerificationError", but the per-signature loop does not.
It also breaks the documented multi-signature semantic ("succeeds if at least one signature is valid"): a card holding [malformed_signature, valid_signature] raises instead of verifying.
Additionally, any exception raised by key_provider (e.g. a network failure while fetching the JKU) aborts the whole loop for the same reason.
Reproduction
from a2a.types.a2a_pb2 import AgentCard, AgentCardSignature
from a2a.utils.signing import (
SignatureVerificationError,
create_signature_verifier,
)
verifier = create_signature_verifier(
key_provider=lambda kid, jku: b'dummy-key',
algorithms=['RS256'],
)
card = AgentCard(
name='t',
version='1.0',
signatures=[
AgentCardSignature(protected='!!!not-base64url!!!', signature='aaa')
],
)
try:
verifier(card)
except SignatureVerificationError as e:
print(f'contract respected: {type(e).__name__}: {e}')
except Exception as e:
print(f'CONTRACT BROKEN -> {type(e).__name__}: {e}')
Observed output:
CONTRACT BROKEN -> Error: Invalid base64-encoded string: number of data characters (13) cannot be 1 more than a multiple of 4
Expected behavior
Every failure on the verification path should surface as SignatureVerificationError (per the contract established at signing.py:124-128), and a malformed signature should count as "invalid" so remaining signatures are still attempted.
Suggested fix
Widen the per-signature except clause, e.g.:
except (PyJWTError, ValueError, binascii.Error, UnicodeDecodeError):
continue
or wrap the loop body so parse/key-provider failures are logged and treated as an invalid signature. This is non-breaking for correct inputs and only converts escapes into the documented error type.
Happy to submit a PR with tests.
Code of Conduct
- I agree to follow this project's Code of Conduct
- 主要语言
- Python
- 星标
- 2.2k
- 派生
- 509
- 平均合并
- 3 天 11 小时
- 30 天内合并 PR
- 43
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
a2aproject/a2a-python 的其他 Issue
-
[Bug]: REST task/request id sanitization可能已有人在做 @Linux2010 于 106 天前认领。 未关闭maintainers-only
难度 2/5 1-3 小时 新手友好度 65/100
a2aproject/a2a-python#805 · 1 条评论 ·
维护者通常 2 天内回复
-
[Bug]: Framework-written FAILED status drops status.timestamp, persisting last_updated as NULL可能已有人在做 @rohityan 于 2 天前认领。 未关闭
a2aproject/a2a-python#1331 · 已指派 2 人 ·
维护者通常 2 天内回复
-
[Bug]: message/send hangs forever when the AgentExecutor returns without producing events可能已有人在做 @rohityan 于 2 天前认领。 未关闭
a2aproject/a2a-python#1330 · 已指派 2 人 ·
维护者通常 2 天内回复
-
Whole numbers in a data Part are returned as floats (e.g. 4326 becomes 4326.0)可能已有人在做 @rohityan 于 3 天前认领。 未关闭
a2aproject/a2a-python#1328 · 已指派 1 人 ·
维护者通常 2 天内回复
-
[Feat]: Cluster mode: detect and recover tasks abandoned by a crashed replica (heartbeat/lease)可能已有人在做 @ishymko 于 3 天前认领。 未关闭component: server status: needs review
a2aproject/a2a-python#1324 · 4 条评论 · 已指派 1 人 ·
维护者通常 2 天内回复
查看 a2aproject/a2a-python 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 68/100
KalicoCrew/kalico#1012 ·
维护者通常 1 天内回复
-
难度 1/5 1 小时以内 新手友好度 82/100
esphome/esphome.io#7657 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 62/100
VNG-Realisatie/gemma-zaken#2658 ·
-
难度 1/5 1 小时以内 新手友好度 75/100
维护者通常 1 天内回复
-
comp/gateway comp/plugins duplicate P3 type/bug
难度 2/5 1-3 小时 新手友好度 82/100
NousResearch/hermes-agent#137019 ·
维护者通常 1 天内回复