Problem
Public key JWK parsing uses unchecked as any casts without validation, allowing type-mismatched data to silently proceed through cryptographic verification.
Affected Code
packages/lib/sdk/src/mercury/DIDCommDIDResolver.ts:44-45 - JWK coordinates cast as any without validation
packages/lib/sdk/src/castor/methods/prism/index.ts - Base64 JWK decoding with unvalidated any cast
packages/lib/sdk/src/plugins/internal/didcomm/tasks/HandleRequestCredential.ts:397, 401 - Credential format/claims type-casted without guards
Why This Matters
This is in the cryptographic verification layer. If malformed JWK data gets through, signature verification could incorrectly succeed or fail silently. The TODO comment in prism/index.ts confirms this was always incomplete: 'TODO need to properly parse JWK into key / raw'
Current Code Example
// DIDCommDIDResolver.ts:44-45
const publicKeyBase64 = method.publicKeyJwk?.x as any;
const publicKeyKid = (method.publicKeyJwk as any).kid;
Suggested Fix
Create proper type guards and validated parsers:
function parseJWKCoordinate(jwk: unknown, field: string): string {
if (typeof jwk !== 'object' || jwk === null) {
throw new CastorError.InvalidKeyError(`Invalid JWK: missing ${field}`);
}
const value = (jwk as Record<string, unknown>)[field];
if (typeof value !== 'string') {
throw new CastorError.InvalidKeyError(`Invalid JWK: ${field} is not a string`);
}
return value;
}
Impact
Critical - Affects signature verification and authentication in credential issuance/verification flows
Problem
Public key JWK parsing uses unchecked
as anycasts without validation, allowing type-mismatched data to silently proceed through cryptographic verification.Affected Code
packages/lib/sdk/src/mercury/DIDCommDIDResolver.ts:44-45- JWK coordinates cast asanywithout validationpackages/lib/sdk/src/castor/methods/prism/index.ts- Base64 JWK decoding with unvalidatedanycastpackages/lib/sdk/src/plugins/internal/didcomm/tasks/HandleRequestCredential.ts:397, 401- Credential format/claims type-casted without guardsWhy This Matters
This is in the cryptographic verification layer. If malformed JWK data gets through, signature verification could incorrectly succeed or fail silently. The TODO comment in prism/index.ts confirms this was always incomplete: 'TODO need to properly parse JWK into key / raw'
Current Code Example
Suggested Fix
Create proper type guards and validated parsers:
Impact
Critical - Affects signature verification and authentication in credential issuance/verification flows