[Bug]: Agent card signature verification raises raw binascii.Error on a malformed protected header instead of SignatureVerificationError
Maintainer antworten meist innerhalb von 3 Tagen
Bewertung
Dieses Issue wurde noch nicht bewertet.
Beschreibung
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
- Vorherrschende Sprache
- Python
- Sterne
- 2.2k
- Forks
- 518
- Ø Merge
- 3 T. 23 Std.
- Gemergte PRs (30 T.)
- 41
Entwicklungsumgebung
- Kein Dockerfile und keine Docker-Compose-Datei
- Hat eine Pull-Request-Vorlage
- Beitragsleitfaden lesen
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus a2aproject/a2a-python
-
[Bug]: `A2A-Version` validation ignores minor versions and the query parameterEvtl. vergeben @rohityan hat das vor 56 Tagen übernommen. Offencomponent: server status:awaiting response
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 75/100
a2aproject/a2a-python#1204 · 3 Kommentare · 1 zugewiesene Person ·
Maintainer antworten meist innerhalb von 3 Tagen
-
[Bug]: REST task/request id sanitizationEvtl. vergeben @Linux2010 hat das vor 115 Tagen übernommen. Offenmaintainers-only
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 65/100
a2aproject/a2a-python#805 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 3 Tagen
-
Legacy handler ignores history_length on message/streamEvtl. vergeben @rohityan hat das heute übernommen. Offen
a2aproject/a2a-python#1363 · 2 zugewiesene Personen ·
Maintainer antworten meist innerhalb von 3 Tagen
-
v0.3 client returns an empty status message and provider when they are unsetEvtl. vergeben @rohityan hat das heute übernommen. Offen
a2aproject/a2a-python#1361 · 2 zugewiesene Personen ·
Maintainer antworten meist innerhalb von 3 Tagen
-
[Bug]: VersionedDatabaseTaskStore get() and delete() fail with "no such table" when initialize() was not calledEvtl. vergeben @rohityan hat das vor 1 Tag übernommen. Offen
a2aproject/a2a-python#1356 · 2 zugewiesene Personen ·
Maintainer antworten meist innerhalb von 3 Tagen
Alle Issues in a2aproject/a2a-python
Ähnliche Issues
-
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 80/100
521xueweihan/HelloGitHub#4063 ·
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 62/100
Vanilla-OS/apx-gui#112 ·
-
Devstral and Voxtral: section 5 fails in us-east-1 with 400 "Model does not support audio modality"Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 76/100
aws-samples/sample-per-model-bedrock#409 ·
Maintainer antworten meist innerhalb von 1 Tag
-
DuckDB 2.0 breaks to_pyarrow_batchesEvtl. vergeben @DG47 hat das heute übernommen. Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 76/100
ibis-project/ibis#12196 ·
Maintainer antworten meist innerhalb von 1 Tag