Skip to content

Commit 05018cc

Browse files
vvillait88claude
andcommitted
fix(identity): validate kid/kty are non-empty strings in UCPSigningKey.from_jwk
Previously only checked key presence, not type. A JWK with kid=None or kid="" would fall through to the dataclass and serialize to invalid JSON during JCS canonicalization (signing would still succeed, producing a profile that verifiers cannot parse). Tighter validation matches the node sibling's `typeof jwk.kid !== 'string' || !jwk.kid` check. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 1b40810 commit 05018cc

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

  • agentscore_commerce/identity

agentscore_commerce/identity/ucp.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,11 @@ def from_jwk(cls, jwk: dict[str, Any]) -> UCPSigningKey:
8181
if not isinstance(jwk, dict):
8282
msg = f"UCPSigningKey.from_jwk expected a dict; got {type(jwk).__name__}."
8383
raise ValueError(msg)
84-
if "kid" not in jwk:
85-
msg = "UCPSigningKey.from_jwk: JWK missing required field `kid`."
84+
if not isinstance(jwk.get("kid"), str) or not jwk["kid"]:
85+
msg = "UCPSigningKey.from_jwk: JWK missing required field `kid` (or non-string/empty)."
8686
raise ValueError(msg)
87-
if "kty" not in jwk:
88-
msg = "UCPSigningKey.from_jwk: JWK missing required field `kty`."
87+
if not isinstance(jwk.get("kty"), str) or not jwk["kty"]:
88+
msg = "UCPSigningKey.from_jwk: JWK missing required field `kty` (or non-string/empty)."
8989
raise ValueError(msg)
9090
if jwk["kty"] not in {"OKP", "EC", "RSA"}:
9191
msg = (

0 commit comments

Comments
 (0)