Skip to content

Commit b14cc82

Browse files
authored
OIDC: only pass logo_uri, policy_uri, tos_uri if they conform to "common base" (#4748)
* OIDC: only pass logo_uri, policy_uri, tos_uri if they conform to "common base" Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Tests Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --------- Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>
1 parent 9f9be70 commit b14cc82

File tree

2 files changed

+41
-6
lines changed

2 files changed

+41
-6
lines changed

spec/unit/oidc/register.spec.ts

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ describe("registerOidcClient()", () => {
2929
redirectUris: [baseUrl],
3030
clientName,
3131
applicationType: "web",
32-
tosUri: "http://tos-uri",
33-
policyUri: "http://policy-uri",
32+
tosUri: "https://just.testing/tos",
33+
policyUri: "https://policy.just.testing",
3434
contacts: ["admin@example.com"],
3535
};
3636
const dynamicClientId = "xyz789";
@@ -67,6 +67,8 @@ describe("registerOidcClient()", () => {
6767
id_token_signed_response_alg: "RS256",
6868
token_endpoint_auth_method: "none",
6969
application_type: "web",
70+
tos_uri: "https://just.testing/tos",
71+
policy_uri: "https://policy.just.testing",
7072
}),
7173
);
7274
});
@@ -114,4 +116,24 @@ describe("registerOidcClient()", () => {
114116
),
115117
).rejects.toThrow(OidcError.DynamicRegistrationNotSupported);
116118
});
119+
120+
it("should filter out invalid URIs", async () => {
121+
fetchMockJest.post(delegatedAuthConfig.registration_endpoint!, {
122+
status: 200,
123+
body: JSON.stringify({ client_id: dynamicClientId }),
124+
});
125+
expect(
126+
await registerOidcClient(delegatedAuthConfig, {
127+
...metadata,
128+
tosUri: "http://just.testing/tos",
129+
policyUri: "https://policy-uri/",
130+
}),
131+
).toEqual(dynamicClientId);
132+
expect(JSON.parse(fetchMockJest.mock.calls[0][1]!.body as string)).not.toEqual(
133+
expect.objectContaining({
134+
tos_uri: "http://just.testing/tos",
135+
policy_uri: "https://policy-uri/",
136+
}),
137+
);
138+
});
117139
});

src/oidc/register.ts

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,18 @@ interface OidcRegistrationRequestBody {
5454

5555
export const DEVICE_CODE_SCOPE = "urn:ietf:params:oauth:grant-type:device_code";
5656

57+
// Check that URIs have a common base, as per the MSC2966 definition
58+
const urlHasCommonBase = (base: URL, urlStr?: string): boolean => {
59+
if (!urlStr) return false;
60+
const url = new URL(urlStr);
61+
if (url.protocol !== base.protocol) return false;
62+
if (url.host !== base.host && !url.host.endsWith(`.${base.host}`)) return false;
63+
return true;
64+
};
65+
5766
/**
58-
* Attempts dynamic registration against the configured registration endpoint
67+
* Attempts dynamic registration against the configured registration endpoint.
68+
* Will ignore any URIs that do not use client_uri as a common base as per the spec.
5969
* @param delegatedAuthConfig - Auth config from {@link discoverAndValidateOIDCIssuerWellKnown}
6070
* @param clientMetadata - The metadata for the client which to register
6171
* @returns Promise<string> resolved with registered clientId
@@ -74,6 +84,8 @@ export const registerOidcClient = async (
7484
throw new Error(OidcError.DynamicRegistrationNotSupported);
7585
}
7686

87+
const commonBase = new URL(clientMetadata.clientUri);
88+
7789
// https://openid.net/specs/openid-connect-registration-1_0.html
7890
const metadata: OidcRegistrationRequestBody = {
7991
client_name: clientMetadata.clientName,
@@ -84,11 +96,12 @@ export const registerOidcClient = async (
8496
id_token_signed_response_alg: "RS256",
8597
token_endpoint_auth_method: "none",
8698
application_type: clientMetadata.applicationType,
87-
logo_uri: clientMetadata.logoUri,
8899
contacts: clientMetadata.contacts,
89-
policy_uri: clientMetadata.policyUri,
90-
tos_uri: clientMetadata.tosUri,
100+
logo_uri: urlHasCommonBase(commonBase, clientMetadata.logoUri) ? clientMetadata.logoUri : undefined,
101+
policy_uri: urlHasCommonBase(commonBase, clientMetadata.policyUri) ? clientMetadata.policyUri : undefined,
102+
tos_uri: urlHasCommonBase(commonBase, clientMetadata.tosUri) ? clientMetadata.tosUri : undefined,
91103
};
104+
92105
const headers = {
93106
"Accept": "application/json",
94107
"Content-Type": "application/json",

0 commit comments

Comments
 (0)