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

Open Beginner friendly
#1,296 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
78/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
java
Domain
api, backend

Research direction

Start with DidWebParser.parse() in spi/did-spi/src/main/java/org/eclipse/edc/identityhub/spi/did/DidWebParser.java and DidWebParserTest. Check how the parser splits the request path and compare URI.getPath() with getRawPath() for the supplied encoded segments. Add the two parameterized cases from the issue and run DidWebParserTest; done when they preserve the encoded DID segments and existing cases pass.

Written by the indexing model from the issue text.

Description

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.

Dominant language
Java
Stars
46
Forks
65
Avg merge
1d 5h
Merged PRs (30d)
26

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from eclipse-edc/IdentityHub

All issues in eclipse-edc/IdentityHub

Similar issues

More Java issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.