Skip to content

fix(server-core): decouple CORS from app-origin allowlist - #3117

Merged
tada5hi merged 1 commit into
masterfrom
fix/cors-decouple-app-origins
Jun 12, 2026
Merged

tada5hi merged 1 commit into
masterfrom
fix/cors-decouple-app-origins

Conversation

@tada5hi

@tada5hi tada5hi commented Jun 12, 2026

Copy link
Copy Markdown
Collaborator

Motivation

The getAppOrigins(config) CORS origin default (introduced with the per-realm web-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 into ADDITIONAL_DOMAINS. That's a hidden coupling between two mechanisms that should be independent.

Why this is safe

  • All authentication is header-based (Authorization: Bearer/Basic) — no endpoint is cookie-authenticated (the only cookies the server reads are vc-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.
  • This matches the OAuth Browser-Based Apps BCP: the token endpoint should be CORS-open to any origin; the real security boundary for browser flows is redirect_uri binding + PKCE, which authup enforces.
  • ADDITIONAL_DOMAINS keeps its genuinely security-sensitive job: which origins get the built-in web client's <origin>/** redirect wildcard (auto-consent + global scope). That stays explicit startup config.

Changes

  • mountCors no longer defaults origin to getAppOrigins(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 the middlewareCors config options.
  • Updated the rationale comment in cors.ts and the ADDITIONAL_DOMAINS docs (.agents/architecture.md, deployment configuration + provisioning guides) to stop claiming the origin list drives CORS.

Verification

  • npm run build -w apps/server-core clean
  • Full server-core suite: 89 files / 868 tests passed

🤖 Generated with Claude Code

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.
@coderabbitai

coderabbitai Bot commented Jun 12, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

@tada5hi, we couldn't start this review because you've reached your PR review rate limit.

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 @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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 configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 5a56aacb-a061-4119-afc3-5b208432b1af

📥 Commits

Reviewing files that changed from the base of the PR and between 15b08e3 and cd378de.

📒 Files selected for processing (5)
  • .agents/architecture.md
  • apps/server-core/src/adapters/http/middleware/built-in/cors.ts
  • apps/server-core/src/app/modules/http/modules/middleware.ts
  • docs/src/guide/deployment/configuration-server-core.md
  • docs/src/guide/deployment/provisioning.md
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/cors-decouple-app-origins

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@pkg-pr-new

pkg-pr-new Bot commented Jun 12, 2026

Copy link
Copy Markdown

Open in StackBlitz

authup

npm i https://pkg.pr.new/authup@3117

@authup/client-web

npm i https://pkg.pr.new/@authup/client-web@3117

@authup/server-core

npm i https://pkg.pr.new/@authup/server-core@3117

@authup/access

npm i https://pkg.pr.new/@authup/access@3117

@authup/client-web-kit

npm i https://pkg.pr.new/@authup/client-web-kit@3117

@authup/client-web-kit-theme

npm i https://pkg.pr.new/@authup/client-web-kit-theme@3117

@authup/client-web-nuxt

npm i https://pkg.pr.new/@authup/client-web-nuxt@3117

@authup/client-web-theme

npm i https://pkg.pr.new/@authup/client-web-theme@3117

@authup/core-http-kit

npm i https://pkg.pr.new/@authup/core-http-kit@3117

@authup/core-kit

npm i https://pkg.pr.new/@authup/core-kit@3117

@authup/core-realtime-kit

npm i https://pkg.pr.new/@authup/core-realtime-kit@3117

@authup/errors

npm i https://pkg.pr.new/@authup/errors@3117

@authup/i18n

npm i https://pkg.pr.new/@authup/i18n@3117

@authup/kit

npm i https://pkg.pr.new/@authup/kit@3117

@authup/server-adapter-kit

npm i https://pkg.pr.new/@authup/server-adapter-kit@3117

@authup/server-adapter-node

npm i https://pkg.pr.new/@authup/server-adapter-node@3117

@authup/server-adapter-socket-io

npm i https://pkg.pr.new/@authup/server-adapter-socket-io@3117

@authup/server-adapter-web

npm i https://pkg.pr.new/@authup/server-adapter-web@3117

@authup/server-kit

npm i https://pkg.pr.new/@authup/server-kit@3117

@authup/server-test-kit

npm i https://pkg.pr.new/@authup/server-test-kit@3117

@authup/specs

npm i https://pkg.pr.new/@authup/specs@3117

commit: cd378de

@tada5hi
tada5hi marked this pull request as ready for review June 12, 2026 13:35
Copilot AI review requested due to automatic review settings June 12, 2026 13:35
@tada5hi
tada5hi merged commit 66ba0e4 into master Jun 12, 2026
13 of 14 checks passed

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@tada5hi
tada5hi deleted the fix/cors-decouple-app-origins branch June 12, 2026 13:35
@github-actions github-actions Bot mentioned this pull request Jun 12, 2026
tada5hi added a commit that referenced this pull request Jun 12, 2026
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).
tada5hi added a commit that referenced this pull request Jun 12, 2026
…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()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants