Skip to content

A one-of-a-kind resume builder that keeps your privacy in mind. Completely secure, customizable, portable, open-source and free forever. Try it out today!

fix: show app callback schemes on OAuth consent (RX-108)

Amruth Pillaif151d833c7c0
diff --git a/apps/server/src/http/oauth-flow.integration.test.ts b/apps/server/src/http/oauth-flow.integration.test.ts
index 9c1d4dc14..6ce8a41cd 100644
--- a/apps/server/src/http/oauth-flow.integration.test.ts
+++ b/apps/server/src/http/oauth-flow.integration.test.ts
@@ -234,16 +234,27 @@ describe.skipIf(!databaseURL)("MCP OAuth flow with PostgreSQL", () => {
process.env.APP_URL = "http://localhost:33920";
process.env.AUTH_SECRET = "oauth-integration-test-secret-only";
const { handleAuth } = await import("./auth");
+ const { db } = await import("@reactive-resume/db/client");
+ const schema = await import("@reactive-resume/db/schema");
+ const { eq } = await import("drizzle-orm");
const origin = process.env.APP_URL;
const redirectURI = "http://127.0.0.1:33921/callback";
- const registration = await handleAuth(
- new Request(`${origin}/api/auth/oauth2/register`, {
- method: "POST",
- headers: { "content-type": "application/json", origin },
- body: JSON.stringify({ client_name: "Resource check", redirect_uris: [redirectURI] }),
- }),
- );
- const client = await registration.json();
+ const register = async () =>
+ (
+ await handleAuth(
+ new Request(`${origin}/api/auth/oauth2/register`, {
+ method: "POST",
+ headers: { "content-type": "application/json", origin },
+ body: JSON.stringify({ client_name: "Resource check", redirect_uris: [redirectURI] }),
+ }),
+ )
+ ).json();
+ const client = await register();
+ const disabled = await register();
+ await db
+ .update(schema.oauthClient)
+ .set({ disabled: true })
+ .where(eq(schema.oauthClient.clientId, disabled.client_id));
const params = (overrides: Record<string, string> = {}) =>
new URLSearchParams({
client_id: client.client_id,
@@ -283,10 +294,14 @@ describe.skipIf(!databaseURL)("MCP OAuth flow with PostgreSQL", () => {
}
expect((await authorize(params({ resource: "" }))).headers.get("location")).toContain("error=invalid_target");
- // A callback the client never registered, or an unknown client, must not receive a redirect.
+ // A callback the client never registered, even one extending a registered callback, an unknown client
+ // and a disabled client must not receive a redirect.
for (const untrusted of [
params({ redirect_uri: "https://attacker.example/callback" }),
+ params({ redirect_uri: `${redirectURI}.attacker.example` }),
+ params({ redirect_uri: `${redirectURI}/../attacker` }),
params({ client_id: "unknown-client" }),
+ params({ client_id: disabled.client_id }),
]) {
const refused = await authorize(untrusted);
expect(refused.status).toBe(400);
diff --git a/apps/web/src/features/auth/pages/consent.tsx b/apps/web/src/features/auth/pages/consent.tsx
index 1f1c6346f..83cffe504 100644
--- a/apps/web/src/features/auth/pages/consent.tsx
+++ b/apps/web/src/features/auth/pages/consent.tsx
@@ -35,8 +35,9 @@ function redirectDestination(redirectUri: string | null) {
if (!redirectUri) return null;
try {
const url = new URL(redirectUri);
- // Native apps return through their own scheme, which has no host.
- return url.host || url.protocol.replace(/:$/, "");
+ if (url.protocol === "http:" || url.protocol === "https:") return url.host;
+ // Any installed app can claim a custom scheme and pair it with a familiar host, so name the scheme too.
+ return url.host ? `${url.protocol}//${url.host}` : url.protocol.replace(/:$/, "");
} catch {
return null;
}
diff --git a/tests/e2e/specs/oauth-consent.spec.ts b/tests/e2e/specs/oauth-consent.spec.ts
index 6a80d0e38..69723b6d4 100644
--- a/tests/e2e/specs/oauth-consent.spec.ts
+++ b/tests/e2e/specs/oauth-consent.spec.ts
@@ -93,6 +93,31 @@ test("requires explicit OAuth consent before denying or allowing access", async
}
});
+test("names an app callback's scheme, not just its host, before consent", async ({ authPage: page, baseURL }) => {
+ const origin = new URL(baseURL ?? "http://localhost:3000").origin;
+ for (const [callback, destination] of [
+ ["evilapp://www.cursor.com/oauth/callback", "evilapp://www.cursor.com"],
+ ["com.example.app:/oauth/callback", "com.example.app"],
+ ]) {
+ const registration = await page.request.post("/api/auth/oauth2/register", {
+ headers: { origin },
+ data: { client_name: "Cursor", redirect_uris: [callback] },
+ });
+ expect(registration.status(), await registration.text()).toBe(201);
+ const query = new URLSearchParams({
+ client_id: (await registration.json()).client_id,
+ redirect_uri: callback,
+ response_type: "code",
+ scope: "openid api:read",
+ code_challenge: createHash("sha256").update(randomBytes(32)).digest("base64url"),
+ code_challenge_method: "S256",
+ resource: origin,
+ });
+ await page.goto(`/api/auth/oauth2/authorize?${query}`);
+ await expect(page.getByText(destination, { exact: true })).toBeVisible();
+ }
+});
+
test("confirms a named disconnect and revokes every token without widening read-only access", async ({
authPage: page,
baseURL,