-
Notifications
You must be signed in to change notification settings - Fork 136
fix(did): validate did:jwks OIDC jwks_uri fetch targets #193
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Kewe63
wants to merge
1
commit into
agentcommercekit:main
Choose a base branch
from
Kewe63:fix-191-jwks-uri-policy
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+300
−7
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| import { describe, expect, it, vi } from "vitest" | ||
|
|
||
| import { getDidResolver } from "./get-did-resolver" | ||
|
|
||
| type MockFetch = (input: string | URL | Request) => Promise<Response> | ||
|
|
||
| const mockJwks = { | ||
| keys: [ | ||
| { | ||
| kty: "EC", | ||
| crv: "P-256", | ||
| x: "f83OJ3D2xF4d2cBFj4JfFq8RUBnOXHnm9dXfNhf0U4o", | ||
| y: "x_FEzRu9-2jMlqG8tWJBz1y8Z5bO1T_3WqF5svQ7vZk", | ||
| use: "sig", | ||
| }, | ||
| ], | ||
| } | ||
|
|
||
| function getFetchInputUrl(input: string | URL | Request): string { | ||
| if (typeof input === "string") { | ||
| return input | ||
| } | ||
|
|
||
| if (input instanceof URL) { | ||
| return input.href | ||
| } | ||
|
|
||
| return input.url | ||
| } | ||
|
|
||
| function createDiscoveryFetch(jwksUri: string) { | ||
| return vi.fn<MockFetch>(async (input) => { | ||
| const url = getFetchInputUrl(input) | ||
|
|
||
| if (url === "https://issuer.example/.well-known/jwks.json") { | ||
| return new Response("not found", { | ||
| status: 404, | ||
| statusText: "Not Found", | ||
| }) | ||
| } | ||
|
|
||
| if (url === "https://issuer.example/.well-known/openid-configuration") { | ||
| return Response.json({ jwks_uri: jwksUri }) | ||
| } | ||
|
|
||
| return Response.json(mockJwks) | ||
| }) | ||
| } | ||
|
|
||
| describe("getDidResolver", () => { | ||
| it.each([ | ||
| "http://169.254.169.254/latest/meta-data/iam/security-credentials/", | ||
| "https://[::ffff:127.0.0.1]/jwks.json", | ||
| "https://[::ffff:192.168.0.1]/jwks.json", | ||
| "https://[fe90::1]/jwks.json", | ||
| ])( | ||
| "rejects did:jwks OIDC jwks_uri targets that do not satisfy the URL policy: %s", | ||
| async (jwksUri) => { | ||
| const fetch = createDiscoveryFetch(jwksUri) | ||
|
|
||
| const resolver = getDidResolver({ webOptions: { fetch } }) | ||
| const result = await resolver.resolve("did:jwks:issuer.example") | ||
|
|
||
| expect(result.didDocument).toBeNull() | ||
| expect(result.didResolutionMetadata.error).toBe("internalError") | ||
| expect(fetch).toHaveBeenCalledTimes(2) | ||
| expect(fetch).not.toHaveBeenCalledWith(jwksUri, undefined) | ||
| }, | ||
| ) | ||
|
|
||
| it.each(["https://keys.example/jwks.json", "https://fd.example/jwks.json"])( | ||
| "allows did:jwks OIDC jwks_uri targets that satisfy the URL policy: %s", | ||
| async (jwksUri) => { | ||
| const fetch = createDiscoveryFetch(jwksUri) | ||
|
|
||
| const resolver = getDidResolver({ webOptions: { fetch } }) | ||
| const result = await resolver.resolve("did:jwks:issuer.example") | ||
|
|
||
| expect(result.didDocument?.id).toBe("did:jwks:issuer.example") | ||
| expect(result.didResolutionMetadata.contentType).toBe( | ||
| "application/did+ld+json", | ||
| ) | ||
| expect(fetch).toHaveBeenCalledWith(jwksUri, undefined) | ||
| }, | ||
| ) | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔒 Security & Privacy | 🟠 Major | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
Repository: agentcommercekit/ack
Length of output: 1770
🏁 Script executed:
Repository: agentcommercekit/ack
Length of output: 28293
🏁 Script executed:
Repository: agentcommercekit/ack
Length of output: 9487
SSRF (CWE-918): Server-Side Request Forgery (SSRF)
Reachability: External · Exploitability: Moderate
Extend the blocked IPv4 ranges and cover embedded IPv4 IPv6 forms.
0.1.2.3and100.64.1.1bypassisPrivateIpv4Address. Add0.0.0.0/8and100.64.0.0/10. Also apply the private-IPv4 check to IPv4-compatible and IPv4-translated IPv6 forms before the JWKS fetch proceeds.🤖 Prompt for AI Agents