Skip to content

fix: ClaimsExtractor DCQL response type to map[string][]string#387

Merged
masv3971 merged 2 commits into
SUNET:mainfrom
sirosfoundation:fix/claims-extractor-dcql-array
May 18, 2026
Merged

fix: ClaimsExtractor DCQL response type to map[string][]string#387
masv3971 merged 2 commits into
SUNET:mainfrom
sirosfoundation:fix/claims-extractor-dcql-array

Conversation

@leifj
Copy link
Copy Markdown
Contributor

@leifj leifj commented May 8, 2026

Summary

ClaimsExtractor.extractClaimsFromDCQLResponse uses map[string]string to unmarshal the DCQL vp_token JSON, but OID4VP §6.3 requires values to be arrays of presentations (map[string][]string). When a spec-compliant wallet sends array values, json.Unmarshal fails with:

json: cannot unmarshal array into Go value of type string

Changes

  • Change dcqlResponse from map[string]string to map[string][]string
  • Iterate over all tokens per credential query ID
  • Add empty-array guard
  • Add tests for DCQL array format acceptance/rejection

Affected code paths

The OIDC handler (handler_oidc.go) and OpenID4VP direct-post handler (handler_openid4vp.go) both pass raw DCQL JSON to extractAndMapClaimsExtractClaimsFromVPTokenextractClaimsFromDCQLResponse, hitting this bug.

Companion to sirosfoundation#6 (targeting release/sirosid/v0.5.0).

OID4VP §6.3 DCQL vp_token values are arrays of presentations, not
single strings. The extractClaimsFromDCQLResponse function used
map[string]string which caused json.Unmarshal to fail with:
  cannot unmarshal array into Go value of type string

Change dcqlResponse to map[string][]string and iterate over all
tokens per credential query ID. Add empty-array guard and tests.

Fixes the claims extraction path used by OIDC and OpenID4VP
direct-post handlers that pass raw DCQL JSON to
ExtractClaimsFromVPToken.
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes DCQL vp_token claim extraction to support the spec-compliant JSON shape where each credential query ID maps to an array of one or more VP tokens, avoiding json.Unmarshal failures when wallets return arrays.

Changes:

  • Change DCQL response parsing from map[string]string to map[string][]string.
  • Iterate over all VP tokens per credential query ID and guard against empty arrays.
  • Add unit tests validating acceptance of the array format and rejection of invalid/empty DCQL payloads.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
pkg/openid4vp/claims_extractor.go Updates DCQL vp_token unmarshalling to map[string][]string and processes multiple tokens per credential query ID.
pkg/openid4vp/claims_extractor_test.go Adds tests covering DCQL array parsing, rejection of old/non-array values, and empty payload guards.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread pkg/openid4vp/claims_extractor.go
Comment thread pkg/openid4vp/claims_extractor.go Outdated
Comment thread pkg/openid4vp/claims_extractor.go
- Update doc comment to accurately describe array structure per OID4VP §6.3
- Improve error message to specify expected map[string][]string type
- Sort credential query IDs before merging for deterministic output
@sonarqubecloud
Copy link
Copy Markdown

@masv3971 masv3971 merged commit ee44ee0 into SUNET:main May 18, 2026
5 checks passed
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.

3 participants