Skip to content

Unify and fix SD-JWT handling for DCQL - #793

Open
nodh wants to merge 6 commits into
developfrom
fix/sd-jwt-decoys
Open

nodh wants to merge 6 commits into
developfrom
fix/sd-jwt-decoys

Conversation

@nodh

@nodh nodh commented Nov 9, 2026 •

Copy link
Copy Markdown
Member

Fixes some arcane details for SD-JWT processing (mostly regarding arrays and possibly decoy elements within, messing up index handling), and unifies the view on a reconstructed SD-JWT object (extending the existing SdJwtDecoded)

@nodh nodh added this to the 10.0 milestone Nov 9, 2026
@nodh
nodh requested review from JesusMcCloud and tlenz November 9, 2026 13:51
@nodh nodh self-assigned this Nov 9, 2026
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 9, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-19T08:32:44.132954Z 1a8d504 Manual request
🔒 Security Review ✅ Completed 2026-11-09T14:00:27.274818Z 6402a97 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 6402a97cf3

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@nodh nodh changed the title DCQL: Fix disclosing arrays with decoy elements in it Unify and fix SD-JWT handling for DCQL Nov 11, 2026
@nodh

nodh commented Nov 11, 2026

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Bravo.

Reviewed commit: b66e574c2e

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@nodh
nodh added this pull request to stack #797 November 11, 2026 14:56

@JesusMcCloud JesusMcCloud left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

more comments than requested changes, but the regression test for equality and hashcode contracts should really make it into this PR

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

add regression tests. for equality (success and failure cases, property-based). I know it is fine now, but if we change it up again in the future, it might not be any more

}
// The claims as RFC 9901, 7.1 processes them, so that the positions DCQL selects are those of
// SdJwtDecoded.disclosuresByPath, from which the disclosures to present are taken
is SubjectCredentialStore.StoreEntry.SdJwt -> catchingUnwrapped {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I am 95% sure that conflating "no claims", with "cannot reconstruct" is a non-issue and this function's signature is fine, but please double check on the remaining 5%

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

It's cleaner to throw here, you're right

// OpenID4VP 1.0, 6.1: multiple: "If omitted, the default value is false"
require(credentialQuery.multiple || presentations.size == 1) {
"Credential query $id does not allow for multiple submissions, but received ${presentations.size}"
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

how in the name of the lich king was such a spec ever approved!? no matter…


private fun processArray(input: JsonArray): JsonArray = JsonArray(
input.mapNotNull { element ->
/** Positions count only the elements kept, so decoys and withheld elements shift no index (step 3.d). */

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

what is a decoy?
Follow-up Q: can we also booby-trap the array?

@nodh nodh Nov 18, 2026 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

private fun processArray(input: JsonArray): JsonArray = JsonArray(
input.mapNotNull { element ->
/** Positions count only the elements kept, so decoys and withheld elements shift no index (step 3.d). */
private fun processArray(input: JsonArray, path: List<DCQLClaimsPathPointerSegment>): JsonArray {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I don't feel confident giving a verdict on the correctness of this function

@nodh
nodh force-pushed the fix/sd-jwt-decoys branch 2 times, most recently from d0de121 to 1a8d504 Compare November 18, 2026 10:10
@nodh
nodh requested a review from JesusMcCloud November 18, 2026 10:10
@nodh

nodh commented Nov 19, 2026

Copy link
Copy Markdown
Member Author

@codex review again

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Hooray!

Reviewed commit: 1a8d504a76

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

nodh and others added 6 commits November 19, 2026 10:56
The salt and the claim name of a disclosure "MUST be a string" (RFC 9901,
4.2.1). The parser read both with `jsonPrimitive.content`, so it accepted
numbers, booleans and even `null` as their text, while it rejected any salt
that is not base64url, which RFC 9901 does not require.

`SelectiveDisclosureItem.salt` is now the salt string exactly as in the
disclosure; a constructor taking a `ByteArray` base64url-encodes it, so
existing callers keep working. Non-string salts and claim names are rejected.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The holder reconstructed an SD-JWT with its own algorithm in SdJwtDecoded,
which dropped empty objects and arrays and skipped arrays nested in arrays,
while validation processed it per RFC 9901, 7.1. Positions of array elements
therefore differed between the two.

SdJwtDecoded is now built by the validation's processDisclosures, which also
records the position of each disclosed claim as a claims path pointer
(disclosuresByPath), counting no decoys, and the arrays that contain array
element digests. disclosuresFor(pointers) returns the disclosures of the
selected claims with their ancestors and sub-claims (RFC 9901, 7.2;
OpenID4VP 1.0, 6.4, 7.3). ValidatedCredential.SdJwtVc is built from it, and
StoreEntry.SdJwt derives it on first use.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The holder matched DCQL claims queries on a mix of the raw issuer-signed
payload and SdJwtDecoded, then walked the issuer-signed payload to find the
disclosures at the selected positions. Both counted array elements
differently, e.g. next to decoy digests or objects without disclosed claims,
so a holder could disclose another array element than the one selected.

The holder's view of an SD-JWT is now SdJwtDecoded.reconstructedJsonObject,
and the disclosures to present are SdJwtDecoded.disclosuresFor the selected
positions, so both use the same positions (RFC 9901, 7.1 and 7.2;
OpenID4VP 1.0, 6.4, 7.3). The walk over the issuer-signed payload is removed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The verifier replaced every array index in a DCQL query by null, so an index
into a fully visible array matched any element, e.g. ["nationalities", 0]
accepted a presentation with "DE" at index 1.

Each presentation is now matched against its own copy of the credential
query, in which an index becomes null only for arrays that, as issued,
contain array element digests (SdJwtDecoded.arraysWithElementDigests): only
there can a withheld element or a decoy shift the positions of the disclosed
elements (RFC 9901, 7.1 step 3.d and 4.2.5). Indices into other arrays are
checked at their position.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…wtVc

ValidatedCredential.SdJwtVc carries its SdJwtDecoded as decoded, so its
sdJwtSigned, reconstructedJsonObject and disclosures only repeat that view.
They are deprecated in favor of decoded.sdJwtSigned,
decoded.reconstructedJsonObject and decoded.validDisclosures, and all callers
in VC-K read from decoded.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@nodh
nodh force-pushed the fix/sd-jwt-decoys branch from 1a8d504 to 0fea5fd Compare November 19, 2026 09:58

This branch has not been deployed

No deployments
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.

2 participants