Files
Tahsin Ahmed RefatandClaude Opus 5.5 62ef10d629 fix: Allow private-use URI schemes for OAuth redirect URIs (#13945)
* fix: Allow private-use URI schemes for OAuth redirect URIs

Native apps receive OAuth redirects on a private-use URI scheme
(RFC 8252 section 7.1), e.g. com.example.app:/oauth2redirect or
myapp://callback. These were rejected when registering a client
because IsUrlList only accepted http, https and ftp, and the
recommended com.example.app:/path form was also rejected at authorize
time because it has no host.

Add isPrivateUseSchemeUrl, which accepts private-use schemes while
excluding web schemes and schemes that can execute or embed content,
and use it in both places.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix: Require a protocol for OAuth redirect URIs

isURL treats a bare word such as "callback" as a hostname, so a client
could be saved with a redirect URI that validateRedirectUri would always
reject at authorize time. Require a protocol when validating the list.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix: Accept one-character private-use URI destinations

The destination check compared the pathname length, so a valid opaque URI
such as myapp:a was rejected along with the empty myapp: and myapp:/.
Reject only those empty forms.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-08 17:59:34 -04:00

47 lines
1.6 KiB
TypeScript

import { OAuthClient } from "@server/models";
describe("IsUrlList", () => {
const validateUrls = (redirectUris: string[]) =>
OAuthClient.build({ redirectUris }).validate({ fields: ["redirectUris"] });
it("should allow http and https urls", async () => {
await expect(
validateUrls(["https://example.com/callback", "http://localhost:8080"])
).resolves.toBeTruthy();
});
it("should allow urls without a top-level domain", async () => {
await expect(
validateUrls(["https://internal/callback"])
).resolves.toBeTruthy();
});
it("should allow private-use schemes for native apps", async () => {
await expect(
validateUrls(["com.example.app:/oauth2redirect", "myapp://callback"])
).resolves.toBeTruthy();
});
it("should reject schemes that can execute or embed content", async () => {
await expect(validateUrls(["javascript:alert(1)"])).rejects.toThrow();
await expect(validateUrls(["data:text/html,hi"])).rejects.toThrow();
await expect(validateUrls(["file:///etc/passwd"])).rejects.toThrow();
});
it("should reject urls without a protocol", async () => {
await expect(validateUrls(["callback"])).rejects.toThrow();
await expect(validateUrls(["example.com/callback"])).rejects.toThrow();
});
it("should reject a private-use scheme without a destination", async () => {
await expect(validateUrls(["myapp:"])).rejects.toThrow();
await expect(validateUrls(["myapp:/"])).rejects.toThrow();
});
it("should reject duplicate urls", async () => {
await expect(
validateUrls(["myapp://callback", "myapp://callback"])
).rejects.toThrow();
});
});