Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

[Bug]: Agent card signature verification raises raw binascii.Error on a malformed protected header instead of SignatureVerificationError

Aperta
#1,332 0 commenti 0 reazioni 2 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 2 giorni

@Iwaniukooo11 ci sta già lavorando.

Dal 12/10/2026.

  • #1335 di @sean0407 — aperta

Valutazione

Questa issue non è ancora stata valutata.

Descrizione

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
Lingua principale
Python
Stelle
2.2k
Fork
511
Merge medio
2g 22h
PR unite (30g)
43

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di a2aproject/a2a-python

Tutte le issue di a2aproject/a2a-python

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.