SelfIssuedTokenPrecheck rejects valid did:web DIDs with percent-encoded path segments

Aperta
#1,297 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
55/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
java

Direzione di ricerca

Start with SelfIssuedTokenPrecheck.java and SelfIssuedTokenPrecheckTest; read the existing malformed and well-formed DID cases and the hardening rationale from #1200 and PR #1203. Compare the proposed path-segment rules with the related Connector resolver issue #6293, since the safe validation options depend on that resolver's behavior. Done means valid percent-encoded path segments pass while the URL-changing cases remain rejected; run the focused precheck tests.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

triage

Bug Report

Describe the Bug

SelfIssuedTokenPrecheck.checkDid() (core/lib/common-lib) rejects a did:web DID when a path segment contains a
percent-encoded character. Example: did:web:example.com%3A8443:participants:acme%28EU%29 fails with
"Malformed did:web identifier". This DID is valid under DID Core.

The precheck runs before every self-issued token is verified: the Issuer credential request
(DcpHolderTokenVerifierImpl), the presentation query (SelfIssuedTokenVerifierImpl), the credential offer
(DcpHolderCoreExtension) and the Storage API (StorageApiController). So a participant with such a DID can be
created and its DID can be published, but it cannot get a credential or answer a presentation query.

ParticipantManifestValidator in the same release accepts DID Core idchar (%XX) in did:web DIDs. So IdentityHub
is not consistent with itself.

The code is the same on v1.0.0-RC8 and on main.

This is one of three related issues about percent-encoded did:web path segments (see Context Information).

Expected Behavior

A self-issued token with iss = did:web:example.com%3A8443:participants:acme%28EU%29 and
kid = did:web:example.com%3A8443:participants:acme%28EU%29#key-1 passes the precheck. Verification continues with DID
resolution and the signature check.

Observed Behavior

The precheck fails with Malformed did:web identifier 'did:web:example.com%3A8443:participants:acme%28EU%29'.
The Issuer answers the credential request with 401 ("ID token verification failed"). The holder's credential
request ends in an error state.

did:web:example.com%3A8443:participants:acme (no escape) passes.

Steps to Reproduce

Steps to reproduce the behavior:

  1. Add this test to SelfIssuedTokenPrecheckTest:
@ParameterizedTest
@ValueSource(strings = {
        "did:web:example.com%3A8443:participants:acme%28EU%29",
        "did:web:example.com:user:%C3%A4lice"
})
void checkDid_percentEncodedPathSegment_succeeds(String did) {
    assertThat(SelfIssuedTokenPrecheck.checkDid(did)).isSucceeded();
}
  1. Run it. Both cases fail with Malformed did:web identifier.

  2. End to end: create a participant context with DID did:web:<host>:participants:acme%28EU%29 and request a credential
    from an Issuer that runs IdentityHub. The Issuer answers 401.

Context Information

  • Used version: EDC IdentityHub 1.0.0-RC8 (we reproduced it with the RC8 jar). Also present on main
    (checked 2026-11-30).
  • OS: not OS-specific.
  • Related issues: this is one of three issues about percent-encoded did:web path segments. All three must be
    fixed for such DIDs to work end to end:
    • eclipse-edc/Connector#6293: Connector WebDidUrlResolver decodes path segments, and WebDidResolver does not
      check the document id (resolving side).
    • eclipse-edc/IdentityHub#1296: IdentityHub DidWebParser builds the DID from the decoded request path (serving side).
    • This issue: IdentityHub SelfIssuedTokenPrecheck rejects such DIDs (token verification).
  • Affected code: SelfIssuedTokenPrecheck.java, line 36:
// a domain name, optionally followed by a percent-encoded port, then optional colon-separated path segments
private static final Pattern DID_WEB = Pattern.compile("did:web:[A-Za-z0-9._-]+(%3[Aa][0-9]{1,5})?(:[A-Za-z0-9._-]+)*");
  • We run EDC Connector and IdentityHub in a dataspace where each participant has a did:web DID. The last path
    segment is the participant's identifier from an external registry. Such identifiers can contain characters outside
    [A-Za-z0-9._-], for example acme(EU), so the segment is percent-encoded (acme%28EU%29).

Detailed Description

Why the check exists. The strict pattern is deliberate. Issue #1200 and PR #1203 added it as hardening:
resolving a did:web is an outbound HTTP request, and the Connector's did:web resolver percent-decodes the whole
DID document URL. PR #1203: "A crafted did:web could also change the resolved URL's path or host through
percent-decoding." Issue #1200 names %2F, %3F, %23 and %40. The tests pin this:
did:web:example.com%2Fadmin, did:web:example.com%3Fx=, did:web:example.com%23, did:web:user%40internal.host
and did:web:example.com:path%3A8080 must fail.

We agree with that goal. But the pattern blocks every escape in a path segment, also the ones that cannot change
the URL, such as %28 (() or %C3%A4 (ä). These are valid DIDs.

Specification. DID Core 1.0, section 3.1 "DID Syntax" (https://www.w3.org/TR/did-1.0/#did-syntax):

method-specific-id = *( *idchar ":" ) 1*idchar
idchar             = ALPHA / DIGIT / "." / "-" / "_" / pct-encoded
pct-encoded        = "%" HEXDIG HEXDIG

did:web Method Specification, "Read (Resolve)" (https://w3c-ccg.github.io/did-method-web/#read-resolve):

  1. Replace ":" with "/" in the method specific identifier to obtain the fully qualified domain name and optional path.
  2. If the domain contains a port percent decode the colon.

The did:web method does not restrict path segments more than DID Core does. It decodes only the port colon. So a
path segment keeps its escapes in the document URL, and an escape cannot change the path, query or host. The danger
named in #1200 comes from the resolver decoding path escapes, which the did:web specification does not do. We
reported that in eclipse-edc/Connector#6293.

Possible Implementation

Option A (now, one line). Allow percent-encoding in path segments, but keep rejecting the escapes that change
a URL when it is decoded: %2F (/), %3F (?), %23 (#), %25 (%, double decoding), %5C (\, which
OkHttp treats as /) and %3A (:). The host part does not change, so %40 in the host stays rejected.

-    private static final Pattern DID_WEB = Pattern.compile("did:web:[A-Za-z0-9._-]+(%3[Aa][0-9]{1,5})?(:[A-Za-z0-9._-]+)*");
+    private static final Pattern DID_WEB = Pattern.compile("did:web:[A-Za-z0-9._-]+(%3[Aa][0-9]{1,5})?(:(?:[A-Za-z0-9._-]|%(?!2[Ff]|3[Ff]|23|25|5[Cc]|3[Aa])[0-9A-Fa-f]{2})+)*");

We ran the patched pattern against the existing test lists:

  • All current "well-formed" cases still pass.
  • All current "malformed" cases still fail, including did:web:example.com:path%3A8080.
  • New: ...:acme%28EU%29 and ...:%C3%A4lice pass. ...:a%2Fb, ...:a%3fb, ...:a%23b, ...:a%252Fb,
    ...:a%5Cb and ...:a%zz fail.

Option A still rejects some valid DIDs, for example a segment with %3F (acme%3Fbeta for the identifier acme?beta).

Option B (after the Connector resolver is fixed). When the resolver keeps path escapes (eclipse-edc/Connector#6293), no
escape in a path segment can change the URL. Then the precheck can accept all of DID Core idchar in path
segments and keep the strict host rule:

private static final Pattern DID_WEB = Pattern.compile("did:web:[A-Za-z0-9._-]+(%3[Aa][0-9]{1,5})?(:(?:[A-Za-z0-9._-]|%[0-9A-Fa-f]{2})+)*");

With option B, did:web:example.com:path%3A8080 becomes valid and moves to the "well-formed" test list. It is a
valid DID, and with the fixed resolver its URL is https://example.com/path%3A8080/did.json.

We suggest option A now, and option B together with the Connector fix.

Lingua principale
Java
Stelle
46
Fork
65
Merge medio
1g 5h
PR unite (30g)
26

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di eclipse-edc/IdentityHub

Tutte le issue di eclipse-edc/IdentityHub

Issue simili

Altre issue su Java

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.