#19
Require canonical auth origin in live mode
Summary
- require
BETTER_AUTH_URLwhenever Redakt runs outside demo mode - validate that it is an HTTP(S) origin without credentials, path, query, or fragment
- pass the same canonical origin explicitly to Better Auth
- preserve
http://localhost:3000only for local demo mode
This addresses the non-blocking configuration note from PR #18 after that redirect fix was merged.
Validation
pnpm test(65 tests)- focused ESLint
pnpm exec tsc --noEmitpnpm buildgit diff --check- exact validated tree carried onto current
main
Activity
5mikeyreviewed3mo ago
Staging evidence for this head:
- Railway deployment
975c7a11-7568-4d95-894a-2653a06efd4areachedSUCCESS. GET /api/healthreturns HTTP 200.GET /api/mail/accounts/google/completewithout a session returns HTTP 307 withLocation: https://redakt-staging.up.railway.app/?google=unauthorized, confirming the public canonical origin is used at runtime.- Current-head Trylle validation passed; 65 local tests, focused ESLint, TypeScript, and the production build also pass.
1235e84 into main3mo ago
Reviewed the diff (
lib/env.ts,lib/auth.ts,lib/env.test.mjs,docs/gmail.md) against the base atee2af65and traced call sites.No blocking issues found.
What I verified:
getAppUrl()is the only reader ofBETTER_AUTH_URL, andlib/auth.tsis its only consumer (baseURL: getAppUrl()), so the stricter validation can't silently diverge from what's passed to Better Auth.createAuth()short-circuits onisDemoMode()before callinggetAppUrl(), so the new throw path can only fire in live mode, matching the function's own demo-mode fallback — no risk of demo mode breaking..trylle/workflows/railway.yml) builds withDEMO_MODE: "true", sopnpm buildin CI won't hit the new throw; Railway deploy envs already setDEMO_MODE=false+BETTER_AUTH_URLperdocs/self-hosting.md/docs/gmail.md, so this doesn't create a build-time trap in the existing pipeline.new URL(...), protocol check, empty username/password/pathname==="/"/search/hash) correctly accepts bare origins and rejects paths/query/fragment/credentials/non-HTTP(S) schemes;url.originnormalizes the trailing-slash case the old.replace(/\/$/, "")handled.node --experimental-strip-types --test lib/env.test.mjslocally — both new tests pass, and they cover the two failure paths (missing URL, URL with a path) plus the normalize/demo-default success paths.Minor, non-blocking observation: in demo mode, if
BETTER_AUTH_URLhappens to be set (e.g. a leftover env var) it now goes through full validation and can throw even though demo mode previously ignored it entirely. That's arguably desirable strictness, just flagging as a behavior change from before.