Skip to content

Fix/mdoc sub document number - #31

Open
grahamallen-1 wants to merge 2 commits into
stateofca:mainfrom
spruceid:fix/mdoc-sub-document-number
Open

Fix/mdoc sub document number#31
grahamallen-1 wants to merge 2 commits into
stateofca:mainfrom
spruceid:fix/mdoc-sub-document-number

Conversation

@grahamallen-1

Copy link
Copy Markdown
Contributor

Summary

Use the mDL document number as the OIDC sub for mso_mdoc (mDL) presentations, instead of the enveloped credential id.

Problem

For an mso_mdoc presentation the credential is an EnvelopedVerifiableCredential whose credentialSubject.id is the data:application/mdl;base64,… URI — i.e. the entire mDL DeviceResponse. extractClaimsForIdToken uses that as sub, which is broken two ways:

  • Non-deterministic. The DeviceResponse is regenerated every presentation (fresh device signature / session transcript / nonce), so sub differs on every login and an RP can never recognize a returning user.
  • Oversized / leaks the whole mDL. The value is the full base64 mDL, far beyond the 255-ASCII-character limit OpenID Connect Core 1.0 §2 sets for sub, and it ship the entire credential to the RP as the subject identifier.

OpenID Connect Core 1.0 §2 (ID Token): sub is "a locally unique and never reassigned identifier … It MUST NOT exceed 255 ASCII characters in length" — https://openid.net/specs/openid-connect-core-1_0.html#IDToken

Fix

common/oidc.js: for an mso_mdoc credential, derive sub from org.iso.18013.5.1.document_number (a stable, per-license identifier already flattened into credentialSubject by buildMdocCredentialSubject). When the document number was not disclosed, or for non-mdoc credentials, fall back to the existing credentialSubject.id ?? id — so the change is strictly never-worse-than the current behavior. VC and hybrid flows are unaffected.

Tests

Added to test/unit/60-oidc.test.js:

  • mso_mdoc → sub is the document number, not the base64 id
  • mso_mdoc without a disclosed document number → falls back to credentialSubject.id
  • hybrid flow (VC first) → sub is the VC subject, unchanged

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant