Skip to content

Open source CapCut alternative.

TypeScript

refactor(site): trust auth subdomains by pattern [rebuild]

David Lec8e5d3a22d9e
diff --git a/site/src/cut/lib/hosts.ts b/site/src/cut/lib/hosts.ts
index 5c117420..a0730d34 100644
--- a/site/src/cut/lib/hosts.ts
+++ b/site/src/cut/lib/hosts.ts
@@ -25,12 +25,6 @@ export const CUT_MEDIA_ORIGIN = `https://${CUT_MEDIA_HOST}`;
// not serve is a card that plays nothing.
export const STOCK_AUDIO_PUBLIC_KEY = /^stock\/(sfx|music)\/[a-z0-9-]+\.mp3$/;
-// Founder outreach replies land here: Resend receives mail for this subdomain
-// and posts it to /api/email/resend-webhook. It is deliberately a subdomain —
-// the MX record belongs to Resend, and the apex keeps whatever routes its mail
-// today (src/lib/marketing/replyAddress.ts).
-export const OUTREACH_REPLY_HOST = "reply.donkeycut.com";
-
// The Cut Worker's control plane — the /wake the hosted API posts to when it
// queues a render. Its own custom domain, claimed in wrangler.jsonc beside the
// media route, so it cannot be revoked by a deploy default the way the
@@ -39,14 +33,13 @@ export const OUTREACH_REPLY_HOST = "reply.donkeycut.com";
export const CUT_WORKER_HOST = "worker.donkeycut.com";
export const CUT_WORKER_WAKE_URL = `https://${CUT_WORKER_HOST}/wake`;
-// An internal admin app on su.donkeycut.com signs in through this host.
-export const SU_HOST = "su.donkeycut.com";
-export const SU_ORIGIN = `https://${SU_HOST}`;
-
// The registrable host the auth cookies are scoped to, so a session started on
// the apex reaches its subdomains.
export const AUTH_COOKIE_DOMAIN = "donkeycut.com";
+// Every subdomain of that host, as a trusted-origin pattern.
+export const AUTH_SUBDOMAINS = `https://*.${AUTH_COOKIE_DOMAIN}`;
+
// Where the worker's runner calls the hosted API back: production containers
// (NODE_ENV=production in the image) talk to the canonical host, a dev worker
// run by hand talks to the local dev server.
diff --git a/site/src/lib/auth.ts b/site/src/lib/auth.ts
index ed022865..0b177386 100644
--- a/site/src/lib/auth.ts
+++ b/site/src/lib/auth.ts
@@ -3,7 +3,7 @@ import { prismaAdapter } from "better-auth/adapters/prisma";
import { nextCookies } from "better-auth/next-js";
import { bearer } from "better-auth/plugins";
-import { AUTH_COOKIE_DOMAIN, DONKEYCUT_CANONICAL, SU_ORIGIN } from "@/cut/lib/hosts";
+import { AUTH_COOKIE_DOMAIN, AUTH_SUBDOMAINS, DONKEYCUT_CANONICAL } from "@/cut/lib/hosts";
import { provisionSignupGrants } from "@/lib/onboarding/signup-grants";
import { prisma } from "@/lib/prisma";
import { emailPasswordDisabledPaths, emailPasswordGuard, emailPasswordOptions } from "@/lib/email-password-auth";
@@ -16,19 +16,18 @@ import { AUTH_ERROR_PATH } from "@/lib/signInReturn";
// it from the localhost request.
const baseURL = process.env.VERCEL ? DONKEYCUT_CANONICAL : undefined;
-// The session is shared with the apex's subdomains: an internal admin app on
-// su.donkeycut.com signs in through this host, and a host-only cookie would
-// never reach it.
-// Scoping the auth cookies to the registrable host lets the session ride
-// across, and listing the subdomain as a trusted origin lets a sign-in started
-// there name its own address as the post-auth callback. Hosted only —
+// The session is shared with the apex's subdomains, which sign in through
+// this host; a host-only cookie would never reach them. Scoping the auth
+// cookies to the registrable host lets the session ride across, and trusting
+// the subdomains lets a sign-in started on one name its own address as the
+// post-auth callback. Hosted only —
// localhost can't carry a Domain attribute.
const crossSubDomain = process.env.VERCEL
? {
advanced: {
crossSubDomainCookies: { domain: AUTH_COOKIE_DOMAIN, enabled: true },
},
- trustedOrigins: [DONKEYCUT_CANONICAL, SU_ORIGIN],
+ trustedOrigins: [DONKEYCUT_CANONICAL, AUTH_SUBDOMAINS],
}
: {};