Skip to content

Commit b28b7fd

Browse files
committed
feat: jwk validation
Signed-off-by: Daniel Bluhm <[email protected]>
1 parent 00371a2 commit b28b7fd

File tree

1 file changed

+12
-2
lines changed
  • didcomm_messaging/resolver

1 file changed

+12
-2
lines changed

didcomm_messaging/resolver/jwk.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
class JWKResolver(DIDResolver):
1414
"""Resolve did:jwk."""
1515

16-
PATTERN = re.compile(r"^did:jwk:(?P<did>.*)$")
16+
PATTERN = re.compile(r"^did:jwk:(?P<did>[A-Za-z0-9\-_]+)$")
1717

1818
async def resolve(self, did: str) -> dict:
1919
"""Resolve a did:jwk."""
@@ -22,7 +22,17 @@ async def resolve(self, did: str) -> dict:
2222
else:
2323
raise DIDResolutionError(f"Invalid DID: {did}")
2424

25-
jwk = json.loads(b64.decode(encoded))
25+
try:
26+
jwk = json.loads(b64.decode(encoded))
27+
except json.JSONDecodeError:
28+
raise DIDResolutionError("Invalid JWK")
29+
30+
if not isinstance(jwk, dict):
31+
raise DIDResolutionError("Invalid JWK")
32+
33+
if "kty" not in jwk:
34+
raise DIDResolutionError("Invalid JWK")
35+
2636
doc = {
2737
"@context": [
2838
"https://www.w3.org/ns/did/v1",

0 commit comments

Comments
 (0)