#19

Require canonical auth origin in live mode

MergedstylesshOwnermerged intofrom

Summary

  • require BETTER_AUTH_URL whenever 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:3000 only 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 --noEmit
  • pnpm build
  • git diff --check
  • exact validated tree carried onto current main

Activity

5
mikeyreviewed3mo ago
mikey3mo ago

Reviewed the diff (lib/env.ts, lib/auth.ts, lib/env.test.mjs, docs/gmail.md) against the base at ee2af65 and traced call sites.

No blocking issues found.

What I verified:

  • getAppUrl() is the only reader of BETTER_AUTH_URL, and lib/auth.ts is its only consumer (baseURL: getAppUrl()), so the stricter validation can't silently diverge from what's passed to Better Auth.
  • createAuth() short-circuits on isDemoMode() before calling getAppUrl(), 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.
  • CI (.trylle/workflows/railway.yml) builds with DEMO_MODE: "true", so pnpm build in CI won't hit the new throw; Railway deploy envs already set DEMO_MODE=false + BETTER_AUTH_URL per docs/self-hosting.md/docs/gmail.md, so this doesn't create a build-time trap in the existing pipeline.
  • URL validation (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.origin normalizes the trailing-slash case the old .replace(/\/$/, "") handled.
  • Ran node --experimental-strip-types --test lib/env.test.mjs locally — 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_URL happens 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.

stylesshOwner3mo ago

Staging evidence for this head:

  • Railway deployment 975c7a11-7568-4d95-894a-2653a06efd4a reached SUCCESS.
  • GET /api/health returns HTTP 200.
  • GET /api/mail/accounts/google/complete without a session returns HTTP 307 with Location: 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.
stylessh merged commit 1235e84 into main3mo ago

Branch stylessh/require-canonical-auth-origin has been merged.

Checking branch