Repository navigation
fix: bind JWT signing key to credential issuer - #302
marco-a-affinidi wants to merge 3 commits into
Conversation
|
Coverage after merging fix/verify_kid_iss into main will be
Coverage Report |
|
Coverage after merging fix/verify_kid_iss into main will be
Coverage Report |
| VerificationRelationship.keyAgreement => didDocument.keyAgreement, | ||
| null => didDocument.verificationMethod, | ||
| }; | ||
| final isFullyQualifiedKid = kidToUse.contains('#'); |
🛡️ AI Agentic Security Code Review1 AI-confirmed issue, 3 findings need a human to review/validate. Mandatory to check: 🔒 Security Code Review Report — Security tab ↗ 📊 Summary & findings
Finding details (titles, evidence + remediation) are in the 🔒 Security tab ↗ — visible to maintainers / code owners only. |
| algorithm: algorithm, | ||
| kid: decodedHeader['kid'] as String?, | ||
| issuerDid: did.toString(), | ||
| kid: kid, |
There was a problem hiding this comment.
before we had String?, but now
final kid = decodedHeader['kid'] as String;
so kid is required now. Is it expected and isn't it a breaking change?
| {'id': final String issuer} => issuer, | ||
| _ => null, | ||
| }; | ||
| if (jwtIssuer != issuerDid) { |
There was a problem hiding this comment.
Should it return false instead of throwing an exception?
| static String _resolutionDid(String issuerDid, String kid) { | ||
| final issuer = DidUrl.fromUrlString(issuerDid); | ||
| final signingKey = DidUrl.fromUrlString(kid); | ||
| final hasWebVhVersionSelector = signingKey.method == 'webvh' && |
There was a problem hiding this comment.
B407
Key rotation/revocation can be bypassed. If a signing key is compromised and rotated out, an attacker can point kid at an earlier ?versionId= where that key was still authorized, and verification succeeds. There's no check tying the selected version to the credential's issuance time (iat / issuanceDate), which is the usual mitigation. Right now any historical version is acceptable for a credential issued at any time.
The check is query != null, not "is a version selector". Any query is honored - ?service=, ?relativeRef=, or anything else a future method defines. If we want version selectors, we should whitelist versionId / versionTime explicitly and ignore (or reject) everything else.
better to have security attention here
This pull request introduces stricter issuer binding and verification relationship enforcement in JWT Verifiable Credential (VC) processing, along with expanded test coverage. The main changes ensure that the issuer in a JWT VC is strictly identified by the resolved DID Document, and optionally require that the signing key be authorized for a specific verification relationship (such as
assertionMethod). This improves security and standards compliance for JWT-based credentials.Enhancements to Issuer Binding and Verification:
Strict Issuer Identity Verification:
The
JwtDm1Suitenow ensures that the issuer (iss) in the JWT payload matches the DID resolved from the issuer field in the credential. If they do not match, verification fails. The resolved DID Document must directly identify the issuer and not rely onalsoKnownAsaliases. [1] [2]Verification Relationship Enforcement:
The
JwtDm1SuiteandDidVerifiercan now require that the signing key is authorized for a specific verification relationship (e.g.,assertionMethod). This is controlled by a newrequireAssertionMethodflag inJwtDm1Suiteand a newverificationRelationshipparameter inDidVerifier.create. If required and the key is not authorized, verification fails. [1] [2] [3] [4] [5]Improvements in DID Resolution and Key Matching:
WebVH Version Selector Handling:
Added logic to preserve and correctly resolve DID URLs with WebVH version selectors, ensuring the correct key and document are used during verification. [1] [2]
Key Matching Logic:
Improved internal matching for verification methods to ensure keys are authorized as required, accounting for both fully qualified and fragment-only key IDs.
Expanded and Updated Test Coverage:
Comprehensive tests were added to verify the new issuer binding and verification relationship logic, including scenarios for issuer mismatch,
alsoKnownAsalias rejection, assertion method requirements, and WebVH versioned DIDs. [1] [2] [3]Fixture and Utility Updates:
Updated JWT test fixtures to align with new verification logic and added a dynamic invalid signature generator.
Relevant Encoded References:
[1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13]