did:web endpoint builds the DID from the decoded request path, so DIDs with percent-encoded segments return 404

Aperta Adatta ai principianti
#1,296 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à
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
78/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
java
Ambito
api, backend

Direzione di ricerca

Inizia con DidWebParser.parse() in spi/did-spi/src/main/java/org/eclipse/edc/identityhub/spi/did/DidWebParser.java e DidWebParserTest. Controlla come il parser suddivide il percorso della richiesta e confronta URI.getPath() con getRawPath() per i segmenti codificati forniti. Aggiungi i due casi parametrizzati dell’issue ed esegui DidWebParserTest; il lavoro è completato quando i segmenti DID codificati vengono preservati e i casi esistenti passano.

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

Descrizione

triage

Bug Report

Describe the Bug

DidWebParser (module spi/did-spi) maps the request URL of the did:web endpoint back to a DID. It uses
URI.getPath(), which percent-decodes the path. A DID with a percent-encoded path segment is stored in its encoded
form, for example did:web:example.com%3A8443:participants:acme%28EU%29. The parser produces
did:web:example.com%3A8443:participants:acme(EU). This DID is not in the store, so DidWebController answers 404.

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

GET https://example.com:8443/participants/acme%28EU%29/did.json returns the published DID document of
did:web:example.com%3A8443:participants:acme%28EU%29.

Observed Behavior

The endpoint answers 404. The parser looks up did:web:example.com%3A8443:participants:acme(EU).

With %3F the parser produces a DID that contains ? (...:acme?beta). That is not a valid DID.

Steps to Reproduce

Steps to reproduce the behavior:

  1. Add this test to DidWebParserTest:
@ParameterizedTest
@CsvSource({
        "https://example.com:8443/participants/acme%28EU%29/did.json, did:web:example.com%3A8443:participants:acme%28EU%29",
        "https://example.com:8443/participants/acme%3Fbeta/did.json,  did:web:example.com%3A8443:participants:acme%3Fbeta"
})
void parse_keepsPercentEncodedPathSegments(String url, String expectedDid) {
    assertThat(parser.parse(URI.create(url), StandardCharsets.UTF_8)).isEqualTo(expectedDid);
}
  1. Run it. Both cases fail:
expected: "did:web:example.com%3A8443:participants:acme%28EU%29"
 but was: "did:web:example.com%3A8443:participants:acme(EU)"

expected: "did:web:example.com%3A8443:participants:acme%3Fbeta"
 but was: "did:web:example.com%3A8443:participants:acme?beta"
  1. End to end: create a participant context with DID did:web:<host>:participants:acme%28EU%29 (the participant
    manifest validator accepts it), publish the DID, then request https://<host>/participants/acme%28EU%29/did.json.
    The answer is 404.

Context Information

  • Used version: EDC IdentityHub 1.0.0-RC8. 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).
    • This issue: IdentityHub DidWebParser builds the DID from the decoded request path (serving side).
    • eclipse-edc/IdentityHub#1297: IdentityHub SelfIssuedTokenPrecheck rejects such DIDs (token verification).
  • Affected code: DidWebParser.parse(), line 63: var segments = pathSegments(url.getPath());
  • DidWebController passes context.getUriInfo().getAbsolutePath(). That URI keeps the escapes, so
    getRawPath() returns /participants/acme%28EU%29/did.json.
  • 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) or acme?beta, so the segment is percent-encoded (acme%28EU%29,
    acme%3Fbeta).

Detailed Description

The current code on main:

public @Nullable String parse(URI url, Charset charset) {
    var segments = pathSegments(url.getPath());   // decoded path
    ...
    // ports must be percent-encoded:
    var identifier = new StringBuilder(URLEncoder.encode(url.getAuthority(), charset));
    segments.forEach(segment -> identifier.append(":").append(segment));
    return "%s:%s".formatted(DidConstants.DID_WEB_METHOD, identifier);
}

The parser must be the inverse of did:web resolution. Resolution keeps path segments as they are.

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.

Only the port colon is decoded. So did:web:example.com%3A8443:participants:acme%28EU%29 has the document URL
https://example.com:8443/participants/acme%28EU%29/did.json. The way back from that URL must give acme%28EU%29, not acme(EU).

RFC 3986, section 2.2 (https://www.rfc-editor.org/rfc/rfc3986#section-2.2): URIs that differ by replacing a reserved
character with its percent-encoded octet are not equivalent. So the decoded path is a different resource.

Why the parser decodes (history). We think it is not intended:

  • getPath() is in the first version of the parser (PR #198, local DID publisher).
  • PR #1214 (issue #1213) hardened the endpoint: one DID document under exactly three URLs, everything else 404.
    It kept getPath(). The issue and the PR do not discuss percent-encoding.
  • The Javadoc talks about encoding only for the authority ("URL-Encode the authority ... to clearly distinguish it
    from the method separator"). The tests cover only the encoded port. No test covers an escape in a path segment.
  • In the same change (#1214), ParticipantManifestValidator started to accept DID Core idchar (%XX) in did:web
    DIDs. So IdentityHub lets a participant create such a DID, but its own endpoint cannot serve it.

Side effect. With the decoded path, an escaped / changes the segment list. The parser maps
/a%2Fb/did.json to did:web:<host>:a:b. That is a fourth URL for the document of did:web:<host>:a:b, which the
class Javadoc excludes. (The servlet container may reject %2F before the parser runs.) With the raw path,
a%2Fb stays one segment, and maps to the DID did:web:<host>:a%2Fb.

Possible Implementation

Use the raw path. Each DID then keeps exactly the URLs the Javadoc lists, in its own spelling.

--- a/spi/did-spi/src/main/java/org/eclipse/edc/identityhub/spi/did/DidWebParser.java
+++ b/spi/did-spi/src/main/java/org/eclipse/edc/identityhub/spi/did/DidWebParser.java
@@
     public @Nullable String parse(URI url, Charset charset) {
-        var segments = pathSegments(url.getPath());
+        // did:web keeps percent-encoded path segments as they are, only the port colon is encoded/decoded
+        var segments = pathSegments(url.getRawPath());
         if (segments == null) {
             return null;
         }

The existing DidWebParserTest cases have no escapes in the path, so they still pass. Add the cases from
"Steps to Reproduce".

Optional: also reject a raw segment that is not DID Core 1*idchar (return null, so 404). A request such as
/participants/acme(EU)/did.json then gives no DID, instead of the invalid DID ...:acme(EU).

The client side has the matching problem: Connector WebDidUrlResolver decodes path segments when it builds the
URL (see eclipse-edc/Connector#6293). Both fixes are needed for such DIDs to work end to end.

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.