Repository navigation
fix(server-core): decouple CORS from app-origin allowlist - #3117
Conversation
Revert the getAppOrigins(config) CORS origin default introduced with the per-realm web-client work: OAuth2 clients (and their UIs) are registered at runtime on domains unknown at startup, so a startup-time allowlist breaks every dynamically registered browser client on preflight. All authentication is header-based (Bearer/Basic) — no endpoint is cookie-authenticated — so an origin allowlist adds no security here; the actual boundary for browser flows is redirect_uri binding + PKCE. ADDITIONAL_DOMAINS keeps its security-sensitive job (the built-in web client's redirect wildcard), and an explicit CORS allowlist remains configurable via the middlewareCors options.
|
Warning Review limit reached
More reviews will be available in 3 minutes and 37 seconds. Learn how PR review limits work. Your organization has run out of usage credits. Purchase more credits in the billing tab to continue. ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (5)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
authup
@authup/client-web
@authup/server-core
@authup/access
@authup/client-web-kit
@authup/client-web-kit-theme
@authup/client-web-nuxt
@authup/client-web-theme
@authup/core-http-kit
@authup/core-kit
@authup/core-realtime-kit
@authup/errors
@authup/i18n
@authup/kit
@authup/server-adapter-kit
@authup/server-adapter-node
@authup/server-adapter-socket-io
@authup/server-adapter-web
@authup/server-kit
@authup/server-test-kit
@authup/specs
commit: |
additionalOrigins / ADDITIONAL_ORIGINS becomes trustedOrigins / TRUSTED_ORIGINS — the list is the trusted first-party app-origin set, not generic extra origins. Also corrects the stale config doc comment claiming the list drives CORS (decoupled in #3117).
…pt scheme-less hosts (#3120) * feat(server-core)!: rename additionalDomains to additionalOrigins & accept scheme-less hosts An additionalOrigins entry may now be a bare host[:port] (e.g. hub.local), which expands to both its http and https origin; entries with an explicit protocol contribute exactly that origin. normalizeConfig canonicalizes the list to bare origins (expansion + dedupe), and config validation moved from a plain zod object schema to the validup + zod ConfigValidator, making parseConfig/normalizeConfig async. ConfigModule additionally accepts a lazy config factory. BREAKING CHANGE: the config key additionalDomains and the environment variable ADDITIONAL_DOMAINS were renamed to additionalOrigins / ADDITIONAL_ORIGINS. * feat(server-core)!: rename trusted-origin config to trustedOrigins additionalOrigins / ADDITIONAL_ORIGINS becomes trustedOrigins / TRUSTED_ORIGINS — the list is the trusted first-party app-origin set, not generic extra origins. Also corrects the stale config doc comment claiming the list drives CORS (decoupled in #3117). * fix(server-core): respect supplied env for dev-origin seeding & clean up review findings Base the non-production dev-origin seeding on the parsed config env (falling back to process NODE_ENV) so normalizeConfig({ env: 'production' }) no longer widens the trusted-origin allowlist. Clarify the trustedOrigins doc comment (full origins, no path) and drop the dead config.vault assignment from the test factory (vault module removed in #2978). * fix(server-core): harden config validation per audit findings - expandToOrigins rejects non-http(s) protocols (a myapp:// entry previously contributed the literal origin "null" to the web client's redirect allowlist) - parseConfig throws on non-object input instead of silently booting a default config - ConfigValidator mounts are driven from a Record<keyof Config, ValidatorDescriptor> map, restoring compile-time exhaustiveness — an unmounted Config key now fails the build instead of being silently stripped - normalizeConfig is the single owner of trusted-origin canonicalization; getAppOrigins merges entries verbatim instead of re-expanding - an explicit port of 0 (OS-assigned) survives env reading and normalization (falsy checks replaced with undefined checks) - redis/smtp are validated as string | boolean | object instead of z.any()
Motivation
The
getAppOrigins(config)CORS origin default (introduced with the per-realmweb-client work, #3104) couples browser API reachability to a startup-time config list. But OAuth2 clients — and the UIs they belong to — are registered at runtime on domains unknown at startup: a legitimately registered SPA client passes/authorize, obtains tokens via PKCE, and then fails every API call on CORS preflight unless the operator also mirrored its domain intoADDITIONAL_DOMAINS. That's a hidden coupling between two mechanisms that should be independent.Why this is safe
Authorization: Bearer/Basic) — no endpoint is cookie-authenticated (the only cookies the server reads arevc-locale/vc-color-mode). A CORS allowlist only adds security against ambient-credential (cookie) attacks, so it adds none here: a malicious origin doesn't hold the victim's token.redirect_uribinding + PKCE, which authup enforces.ADDITIONAL_DOMAINSkeeps its genuinely security-sensitive job: which origins get the built-inwebclient's<origin>/**redirect wildcard (auto-consent + global scope). That stays explicit startup config.Changes
mountCorsno longer defaultsorigintogetAppOrigins(config)—registerCorsMiddleware's reflect-any-origin default applies again (pre-feat: per-realm web client login, realm chooser & backend-served auth workflow UI #3104 behavior). An explicit allowlist remains configurable via themiddlewareCorsconfig options.cors.tsand theADDITIONAL_DOMAINSdocs (.agents/architecture.md, deployment configuration + provisioning guides) to stop claiming the origin list drives CORS.Verification
npm run build -w apps/server-coreclean🤖 Generated with Claude Code