did:web resolver percent-decodes path segments, so the DID document URL is wrong, and the document id is not checked
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 54/100
- Tipo di issue
- Bug
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Attiva
- Stack tecnologico
- java
- Ambito
- backend-api-design, security
Direzione di ricerca
Start with WebDidUrlResolver.apply() and WebDidResolver.toDidDocument() in extensions/common/iam/decentralized-identity/identity-did-web; read the did:web Read steps cited in the issue. The reproduction cases in WebDidUrlResolverTest show the URL behavior to check, and the resolver reproduction describes the missing document ID check. Done means encoded path segments remain encoded and a document with a different ID is rejected; the issue notes related IdentityHub work is separate.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Bug Report
Describe the Bug
WebDidUrlResolver (module extensions/common/iam/decentralized-identity/identity-did-web) percent-decodes the
whole DID document URL. The did:web specification decodes only the port colon of the domain.
So a DID with a percent-encoded character in a path segment resolves to a different URL:
%28becomes(. The server gets a different path.%3Fbecomes?. The rest of the path becomes a query string. The request goes to the parent path, and that
can be the DID document of a different DID.
WebDidResolver then returns the fetched document without checking that its id equals the requested DID.
did:web "Read (Resolve)" step 7 requires this check.
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
did:web:example.com%3A8443:participants:acme%28EU%29resolves to
https://example.com:8443/participants/acme%28EU%29/did.json.did:web:example.com%3A8443:participants:acme%3Fbetaresolves to
https://example.com:8443/participants/acme%3Fbeta/did.json.- If the fetched document has an
idthat is not the requested DID, resolution fails.
Observed Behavior
did:web:example.com%3A8443:participants:acme%28EU%29resolves to
https://example.com:8443/participants/acme(EU)/did.json.did:web:example.com%3A8443:participants:acme%3Fbetaresolves to
https://example.com:8443/participants/acme?beta/did.json. The HTTP request has path/participants/acmeand
querybeta/did.json. An IdentityHub serves a DID document at/<path>(seeDidWebParser), so this returns the
document ofdid:web:example.com%3A8443:participants:acme.WebDidResolveraccepts that document.DidResolverRegistryImplcaches it under the requested DID.
DidPublicKeyResolverImplthen selects a verification method from it. None of them compares the documentid
with the requested DID.
Steps to Reproduce
Steps to reproduce the behavior:
- Add this test to
WebDidUrlResolverTest(same package, because the class is package-private):
@ParameterizedTest
@CsvSource({
"did:web:example.com%3A8443:participants:acme%28EU%29, https://example.com:8443/participants/acme%28EU%29/did.json",
"did:web:example.com%3A8443:participants:acme%3Fbeta, https://example.com:8443/participants/acme%3Fbeta/did.json"
})
void apply_keepsPercentEncodedPathSegments(String did, String expectedUrl) {
var resolver = new WebDidUrlResolver(true);
assertThat(resolver.apply(did)).isEqualTo(expectedUrl);
}
- Run it. Both cases fail:
expected: "https://example.com:8443/participants/acme%28EU%29/did.json"
but was: "https://example.com:8443/participants/acme(EU)/did.json"
expected: "https://example.com:8443/participants/acme%3Fbeta/did.json"
but was: "https://example.com:8443/participants/acme?beta/did.json"
- For the missing
idcheck: serve, athttps://<host>/participants/acme, a DID document with
"id": "did:web:<host>:participants:acme". CallWebDidResolver.resolve("did:web:<host>:participants:acme%3Fbeta").
The resolver requestshttps://<host>/participants/acme?beta/did.json. By code reading, the result succeeds and
contains the document of the other DID: no code path compares the documentidwith the requested DID.
Context Information
- Used version: EDC Connector
1.0.0-RC8. Also present onmain(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:- This issue: Connector
WebDidUrlResolverdecodes path segments, andWebDidResolverdoes not
check the documentid(resolving side). - eclipse-edc/IdentityHub#1296: IdentityHub
DidWebParserbuilds the DID from the decoded request path (serving side). - eclipse-edc/IdentityHub#1297: IdentityHub
SelfIssuedTokenPrecheckrejects such DIDs (token verification).
- This issue: Connector
- Affected code:
WebDidUrlResolver.apply()line 65, andWebDidResolver.toDidDocument(). - 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 exampleacme(EU)oracme?beta, so the segment is percent-encoded (acme%28EU%29,
acme%3Fbeta).
Detailed Description
The current code on main:
// WebDidUrlResolver.java
var identifier = extractIdentifier(did);
var url = identifier.toString();
if (identifier.getPath().length() == 0) {
url += WELL_KNOWN;
}
return URLDecoder.decode(url + "/" + DID_DOCUMENT, StandardCharsets.UTF_8); // line 65
// WebDidResolver.java, toDidDocument()
var didDocument = mapper.readValue(content.getContent(), DidDocument.class);
return Result.success(didDocument);
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
So acme%28EU%29 and acme%3Fbeta are valid DID path segments.
did:web Method Specification, "Read (Resolve)" (https://w3c-ccg.github.io/did-method-web/#read-resolve):
- Replace ":" with "/" in the method specific identifier to obtain the fully qualified domain name and optional path.
- If the domain contains a port percent decode the colon.
- Generate an HTTPS URL to the expected location of the DID document by prepending https://.
- If no path has been specified in the URL, append /.well-known.
- Append /did.json to complete the URL.
- Perform an HTTP GET request to the URL ...
- Verify that the ID of the resolved DID document matches the Web DID being resolved.
Step 2 decodes only the port colon. No step decodes path segments, so %28 stays %28 in the URL. Step 7 is not
implemented.
RFC 3986, section 2.2 (https://www.rfc-editor.org/rfc/rfc3986#section-2.2) also says that URIs which differ by
replacing a reserved character with its percent-encoded octet are not equivalent. /participants/acme%28EU%29 and
/participants/acme(EU) are different paths for the server.
Why the decoding is there (history). We think the decoding of path segments is not intended:
- The first version (
DidFunctions.resolveDidDocumentUrl) usedURI.getSchemeSpecificPart(), which also decodes. - Issue #1652 ("
WebDidResolverdoes not support domain port") reported thatdid:web:example.com%3A3000:user:alice
resolved tohttps://example.com/3000/user/alice. PR #1701 fixed it: it reads the raw part, replaces:with/,
and then URL-decodes the full URL. That decodes the port colon, but also every other escape. - The tests cover only the port (
"HTTPS WITH DOMAIN PORT"). No test covers an escape in a path segment. - We found no decision record about this.
Impact.
- DIDs with an encoded path segment cannot be resolved. With
%3F,%23or%2F, the request goes to another URL. - With no
idcheck, a DID can resolve to the document of another DID. Its verification methods are then used for
the requested DID. Whether a token is then accepted depends on the verification method ids in that document. - IdentityHub added a strict did:web shape check (eclipse-edc/IdentityHub#1200, eclipse-edc/IdentityHub#1203) because escapes such as
%2F,%3F,
%23and%40"are decoded into the resolution URL, where they can change the path or host". That check now
rejects valid DIDs such as...:acme%28EU%29(see eclipse-edc/IdentityHub#1297). When the resolver keeps path
escapes and checks the documentid, that protection can live in the resolver, and the IdentityHub check can
accept DID Coreidchar.
Possible Implementation
Decode only the port colon in the domain. Keep path segments as they are. Reject a path segment that is not
1*idchar, and reject any other escape in the domain. Then check the document id.
--- a/extensions/common/iam/decentralized-identity/identity-did-web/src/main/java/org/eclipse/edc/iam/did/web/resolution/WebDidUrlResolver.java
+++ b/extensions/common/iam/decentralized-identity/identity-did-web/src/main/java/org/eclipse/edc/iam/did/web/resolution/WebDidUrlResolver.java
@@
-import java.net.URLDecoder;
-import java.nio.charset.StandardCharsets;
import java.util.Objects;
import java.util.function.UnaryOperator;
+import java.util.regex.Pattern;
@SuppressWarnings("HttpUrlsUsage")
class WebDidUrlResolver implements UnaryOperator<String> {
private static final String DID_SCHEME = "did";
private static final String DID_METHOD_PREFIX = "web:";
private static final String DID_DOCUMENT = "did.json";
private static final String WELL_KNOWN = "/.well-known";
+ // DID Core: 1*idchar, idchar = ALPHA / DIGIT / "." / "-" / "_" / pct-encoded
+ private static final Pattern PATH_SEGMENT = Pattern.compile("(?:[A-Za-z0-9._-]|%[0-9A-Fa-f]{2})+");
@@
if (identifier.getPath().length() == 0) {
url += WELL_KNOWN;
}
- return URLDecoder.decode(url + "/" + DID_DOCUMENT, StandardCharsets.UTF_8);
+ return url + "/" + DID_DOCUMENT;
@@
- var host = part.substring(DID_METHOD_PREFIX.length()).replace(':', '/');
- return new URL(scheme + "://" + host);
+ var segments = part.substring(DID_METHOD_PREFIX.length()).split(":", -1);
+ // did:web Read step 2: only the port colon of the domain is percent-decoded
+ var domain = segments[0].replaceFirst("%3[Aa]", ":");
+ if (domain.contains("%")) {
+ throw new IllegalArgumentException("Invalid DID format, the domain may only percent-encode the port colon: " + did);
+ }
+ var path = new StringBuilder();
+ for (var i = 1; i < segments.length; i++) {
+ if (!PATH_SEGMENT.matcher(segments[i]).matches()) {
+ throw new IllegalArgumentException("Invalid DID format, invalid path segment '%s': %s".formatted(segments[i], did));
+ }
+ path.append('/').append(segments[i]);
+ }
+ return new URL(scheme + "://" + domain + path);
}
--- a/extensions/common/iam/decentralized-identity/identity-did-web/src/main/java/org/eclipse/edc/iam/did/web/resolution/WebDidResolver.java
+++ b/extensions/common/iam/decentralized-identity/identity-did-web/src/main/java/org/eclipse/edc/iam/did/web/resolution/WebDidResolver.java
@@
var didDocument = mapper.readValue(content.getContent(), DidDocument.class);
+ // did:web Read step 7
+ if (!didKey.equals(didDocument.getId())) {
+ return Result.failure("DID document id '%s' does not match the resolved DID '%s'".formatted(didDocument.getId(), didKey));
+ }
return Result.success(didDocument);
We checked the patched mapping with OkHttp HttpUrl.get():
| DID | URL | OkHttp encoded path |
|---|---|---|
did:web:w3c-ccg.github.io |
https://w3c-ccg.github.io/.well-known/did.json |
/.well-known/did.json |
did:web:example.com%3A3000:user:alice |
https://example.com:3000/user/alice/did.json |
/user/alice/did.json |
did:web:example.com%3A8443:participants:acme%28EU%29 |
https://example.com:8443/participants/acme%28EU%29/did.json |
same, no query |
did:web:example.com%3A8443:participants:acme%3Fbeta |
https://example.com:8443/participants/acme%3Fbeta/did.json |
same, no query |
did:web:user%40internal.host |
rejected | |
did:web:example.com%3A80%3A81 |
rejected |
The existing WebDidUrlResolverTest cases still pass.
Note: the id check can break deployments that serve a document whose id differs from its DID. Such documents
are already invalid under did:web. A setting to turn the check off could ease the migration, if needed.
The serving side has the matching problem: IdentityHub DidWebParser builds the DID from the decoded request path
(eclipse-edc/IdentityHub#1296).
- Lingua principale
- Java
- Stelle
- 429
- Fork
- 302
- Merge medio
- 10h 46m
- PR unite (30g)
- 75
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Nessun modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di eclipse-edc/Connector
-
Implement conditional extension loading (DR 2026-11-24)Forse già presa @paullatzelsperger l’ha presa 5 giorni fa. Apertafeature_request triage
eclipse-edc/Connector#6275 · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
-
feature_request stale triage
Difficoltà 5/5 Più di una settimana Idoneità per principianti 18/100
eclipse-edc/Connector#6235 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Don't hold a DB connection during token validation of incoming negotiation and transfer messagesApertafeature_request triage
Difficoltà 4/5 3-5 giorni Idoneità per principianti 54/100
eclipse-edc/Connector#6183 · 3 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
feature_request triage
Difficoltà 4/5 3-5 giorni Idoneità per principianti 45/100
eclipse-edc/Connector#6182 · 3 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
feature_request triage
Difficoltà 4/5 3-5 giorni Idoneità per principianti 45/100
eclipse-edc/Connector#6178 · 3 commenti ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di eclipse-edc/Connector
Issue simili
-
triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
eclipse-edc/IdentityHub#1296 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 80/100
cloudfoundry/uaa#4194 ·
I maintainer di solito rispondono entro 1 giorno
-
ui: 進捗状況線ダイアログが日本語表示で英語のままApertaarea: ui priority: medium
Difficoltà 2/5 1-3 ore Idoneità per principianti 83/100
tetsuji16/microProject#1721 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
I maintainer di solito rispondono entro 2 giorni
-
The engine's "loaded, but had errors" message leaves out which library and line each error is inAperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
cqframework/clinical_quality_language#1980 ·
I maintainer di solito rispondono entro 3 giorni