Skip to content

feat(server-core)!: rename additionalDomains to trustedOrigins & accept scheme-less hosts - #3120

Merged
tada5hi merged 4 commits into
masterfrom
feat/additional-origins
Jun 12, 2026
Merged

tada5hi merged 4 commits into
masterfrom
feat/additional-origins

Conversation

@tada5hi

@tada5hi tada5hi commented Jun 12, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • Rename (breaking): config key additionalDomains → trustedOrigins, env var ADDITIONAL_DOMAINS → TRUSTED_ORIGINS. The value is the trusted first-party app-origin set (Keycloak's "web origins" concept), not domains and not redirect URIs — released only hours ago, so no compat alias is kept.
  • Scheme-less entries: an entry may now be a bare host[:port] (e.g. hub.local, hub.local:8080), which expands to both its http and https origin via expandToOrigins. An entry with an explicit protocol contributes exactly that origin — the way to restrict a host to https only.
  • Canonicalization at normalization: normalizeConfig expands + dedupes the list, so Config['trustedOrigins'] always holds bare origins (scheme://host[:port]) and the dev-origin seeding can't duplicate.
  • validup + zod config validation: parseConfig's plain zod object schema moved to the project-standard ConfigValidator (validup container + @validup/zod), making parseConfig/normalizeConfig async. ConfigModule now also accepts a lazy config factory so the test app factory stays sync.
  • Scope note: the list only gates the built-in per-realm web client's redirect_uri allowlist (<origin>/**). It does NOT drive CORS (decoupled in fix(server-core): decouple CORS from app-origin allowlist #3117 — the stale claim in the config doc comment is corrected here) and does not affect UIs that register their own OAuth2 client.
  • Docs (configuration-server-core, provisioning, configuration-client-web) and .agents/architecture.md updated.

Test plan

  • New unit tests: expandToOrigins (full URL, bare host+port, invalid), parseConfig (mixed shapes, rejection, unknown-key stripping), normalizeConfig (canonicalization, dev-origin idempotency).
  • Full apps/server-core suite: 89 files / 877 tests passing.

Summary by CodeRabbit

  • New Features

    • Asynchronous configuration factory support for flexible deployment scenarios.
    • Automatic scheme expansion for trusted origins: bare hostnames now expand to both HTTP and HTTPS variants.
  • Documentation

    • Configuration parameter renamed: additionalDomains → trustedOrigins.
    • Environment variable renamed: ADDITIONAL_DOMAINS → TRUSTED_ORIGINS.
    • Updated deployment guides to reflect configuration naming and origin handling changes.

…ccept 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.
Copilot AI review requested due to automatic review settings June 12, 2026 15:58

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.

@coderabbitai

coderabbitai Bot commented Jun 12, 2026 •

Copy link
Copy Markdown

Review Change Stack

Important

Review skipped

This PR was authored by the user configured for CodeRabbit reviews. CodeRabbit does not review PRs authored by this user. It's recommended to use a dedicated user account to post CodeRabbit review feedback.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: badb9ee6-00b3-4c78-a69e-dd01662dc236

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • ✅ Review completed - (🔄 Check again to review again)
📝 Walkthrough

Walkthrough

This PR refactors the application's configuration system to replace the additionalDomains concept with additionalOrigins, adds logic to expand bare hostnames into scheme-qualified origins (http and https), makes configuration parsing and normalization asynchronous, and introduces a dedicated validator class for runtime config validation.

Changes

Configuration Origins & Async Refactoring

Layer / File(s) Summary
Type System & Configuration Contracts
apps/server-core/src/app/modules/config/types.ts, apps/server-core/src/app/modules/config/constants.ts
Introduces ConfigFactory type for async/sync config factories, documents additionalOrigins field with normalization and security guidance, and adds ADDITIONAL_ORIGINS environment variable constant.
Origin Expansion & Allowlist Logic
apps/server-core/src/app/modules/config/origins.ts
Adds expandToOrigins() helper that converts full origins or bare host[:port] into one or two scheme-qualified origins; updates getAppOrigins() to expand and deduplicate additionalOrigins entries.
Configuration Validation Infrastructure
apps/server-core/src/app/modules/config/validator.ts
Introduces ConfigValidator class with runtime validation for all Config fields using validup/zod, including custom validation for additionalOrigins via expandToOrigins.
Async Configuration Pipeline
apps/server-core/src/app/modules/config/parse.ts, apps/server-core/src/app/modules/config/normalize.ts, apps/server-core/src/app/modules/config/read/env.ts
Converts parseConfig to async delegation to ConfigValidator; makes normalizeConfig async and adds canonicalization of additionalOrigins with deduplication and dev-environment localhost seeding; reads ADDITIONAL_ORIGINS environment variable.
Configuration Module & Runtime Wiring
apps/server-core/src/app/modules/config/module.ts, apps/server-core/src/cli/module.ts, apps/server-core/test/app/factory.ts
Updates ConfigModule to support ConfigFactory (async config functions); awaits async normalization in CLI setup; converts test config builder to async and updates factory wiring.
Test Coverage & Validation
apps/server-core/test/unit/config/index.spec.ts
Comprehensive unit tests for origin expansion (full URL passthrough, bare host to http/https expansion), async config parsing/normalization, canonicalization with localhost seeding, and idempotency.
User Documentation Updates
.agents/architecture.md, docs/src/guide/deployment/configuration-client-web.md, docs/src/guide/deployment/configuration-server-core.md, docs/src/guide/deployment/provisioning.md
Updates all documentation to reference additionalOrigins instead of additionalDomains, documents origin expansion behavior, clarifies ADDITIONAL_ORIGINS environment variable, and updates security guidance.

Sequence Diagram

sequenceDiagram
  participant Client as Caller
  participant ConfigModule as ConfigModule
  participant parseConfig as parseConfig()
  participant ConfigValidator as ConfigValidator
  participant normalizeConfig as normalizeConfig()
  participant getAppOrigins as getAppOrigins()
  Client->>ConfigModule: setup with Config or ConfigFactory
  ConfigModule->>ConfigModule: detect if instance is function
  alt instance is ConfigFactory
    ConfigModule->>ConfigFactory: call async function
    ConfigFactory->>ConfigModule: Promise<Config>
  end
  ConfigModule->>parseConfig: raw config input
  parseConfig->>ConfigValidator: validate schema
  ConfigValidator->>parseConfig: validated ConfigInput
  parseConfig->>normalizeConfig: Promise<ConfigInput>
  normalizeConfig->>normalizeConfig: expand additionalOrigins
  normalizeConfig->>normalizeConfig: deduplicate origins
  normalizeConfig->>normalizeConfig: seed localhost (dev only)
  normalizeConfig->>ConfigModule: Promise<Config>
  ConfigModule->>getAppOrigins: publicUrl + additionalOrigins
  getAppOrigins->>getAppOrigins: expand bare hosts
  getAppOrigins->>Client: final origin allowlist
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • authup/authup#3104: This PR's per-realm web client provisioning and login flow depends on getAppOrigins/CORS allowlisting derived from additionalDomains, and the current PR directly refactors that configuration pipeline (env parsing, normalization, and origin allowlist derivation) from additionalDomains to additionalOrigins with expansion logic.

Poem

🐰 Origins expand like burrows, from bare hosts to https,
Async pipelines hum, validation runs with bliss,
Where additionalOrigins now dance in sets,
And localhost seeds dev with grateful nets,
A config refactor, by designs of refs.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 22.22% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ⚠️ Warning The PR title references 'trustedOrigins' but the actual implementation uses 'additionalOrigins' throughout the codebase and objectives. Update the PR title to 'feat(server-core)!: rename additionalDomains to additionalOrigins & accept scheme-less hosts' to match the actual changes implemented.
✅ Passed checks (3 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


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@3120

@authup/client-web

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

@authup/server-core

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

@authup/access

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

@authup/client-web-kit

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

@authup/client-web-kit-theme

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

@authup/client-web-nuxt

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

@authup/client-web-theme

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

@authup/core-http-kit

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

@authup/core-kit

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

@authup/core-realtime-kit

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

@authup/errors

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

@authup/i18n

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

@authup/kit

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

@authup/server-adapter-kit

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

@authup/server-adapter-node

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

@authup/server-adapter-socket-io

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

@authup/server-adapter-web

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

@authup/server-kit

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

@authup/server-test-kit

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

@authup/specs

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

commit: e8b39cf

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

Actionable comments posted: 3

🧹 Nitpick comments (2)
apps/server-core/test/unit/config/index.spec.ts (1)

54-68: ⚡ Quick win

Consider adding a test for bare hostname without port.

The test suite covers full URLs and hosts with ports, but could benefit from an explicit test case for a simple bare hostname (e.g., 'hub.local') to document that common case.

📝 Suggested additional test case
     it('should expand a bare host with port', () => {
         expect(expandToOrigins('hub.local:8080'))
             .toEqual(['http://hub.local:8080', 'https://hub.local:8080']);
     });
+
+    it('should expand a bare hostname to both schemes', () => {
+        expect(expandToOrigins('hub.local'))
+            .toEqual(['http://hub.local', 'https://hub.local']);
+    });

     it('should throw on an invalid value', () => {
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@apps/server-core/test/unit/config/index.spec.ts` around lines 54 - 68, Add a
unit test for expandToOrigins that asserts a bare hostname (e.g., 'hub.local')
expands to both 'http://hub.local' and 'https://hub.local'; update the
describe('expandToOrigins') block by adding an it('should expand a bare host
without port', ...) similar to the existing "bare host with port" test but
expecting origins without ports, using the expandToOrigins function to locate
the code under test.
apps/server-core/src/app/modules/config/origins.ts (1)

38-50: Consider clarifying the defensive re-expansion rationale.

Lines 38-40 state that additionalOrigins entries are "already canonicalized by normalizeConfig" but then "raw values (scheme-less hosts) are tolerated and expanded the same way." This suggests getAppOrigins is intentionally defensive and can handle both normalized and raw inputs.

However, the comment doesn't clearly explain why this defensive behavior is necessary. If getAppOrigins is always called with normalized config (where origins are already expanded), the re-expansion via expandToOrigins is redundant (though harmless due to the SCHEME_REGEX check returning the single origin for already-expanded entries).

Consider updating the comment to clarify either:

  • That getAppOrigins may be called outside the normalized config path, or
  • That the defensive expansion is a safety measure for future refactoring, or
  • Remove the redundancy if getAppOrigins will always receive normalized config.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@apps/server-core/src/app/modules/config/origins.ts` around lines 38 - 50,
Update the comment above getAppOrigins to clarify the defensive re-expansion:
state that normalizeConfig normally canonicalizes additionalOrigins but
getAppOrigins calls expandToOrigins (which uses SCHEME_REGEX) to tolerate legacy
or unnormalized inputs and to remain safe if the function is invoked outside the
normalized-config path or future refactors change callers; alternatively, if you
decide the codebase guarantees normalized input, remove the redundant
expandToOrigins loop and note that normalizeConfig produces fully expanded
origins. Reference getAppOrigins, normalizeConfig, expandToOrigins, and
SCHEME_REGEX in the comment so readers understand the reason for (or removal of)
the defensive expansion.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@apps/server-core/src/app/modules/config/normalize.ts`:
- Around line 40-47: The code reads NODE_ENV directly (read('NODE_ENV', ...))
instead of using the already-validated parsed env when deciding to seed the dev
origin; update normalizeConfig to base the dev-origin branch on parsed.env (or
the function's parsed config object) rather than calling read('NODE_ENV') so
normalizeConfig({ env: 'production', ... }) does not add http://localhost:3000;
make the same change for the similar logic around the other occurrence (the
block referenced at the later lines) so both decisions use parsed.env (or the
parsed config variable) instead of re-reading process env.

In `@apps/server-core/src/app/modules/config/types.ts`:
- Around line 83-96: The doc comment for additionalOrigins is incorrect: it
claims "the normalized config always holds bare origins" but the code (see
expandToOrigins in origins.ts) normalizes bare hosts into full canonical origins
(scheme://host[:port]); update the comment for the additionalOrigins field to
state that normalized config stores full origins (e.g., "http://hub.local",
"https://hub.local") and that each normalized origin is stored as `<origin>/**`
in the web client's redirect_uri set, mentioning expandToOrigins as the
canonicalizer.

In `@apps/server-core/src/app/modules/config/validator.ts`:
- Around line 36-44: ConfigValidator is dropping the vault property because it
never mounts 'vault'; add a mount for 'vault' in the same style as the other
optional blocks so unknown-key stripping preserves the vault entry.
Specifically, update the validator to call mount('vault', optional,
createValidator(z.any())) (matching the pattern used for 'redis' and 'smtp')
inside the class/method that configures mounts (look for the existing
mount('logger'...), mount('db'...), mount('redis'...) calls) so
parseConfig()/normalizeConfig() retains config.vault.

---

Nitpick comments:
In `@apps/server-core/src/app/modules/config/origins.ts`:
- Around line 38-50: Update the comment above getAppOrigins to clarify the
defensive re-expansion: state that normalizeConfig normally canonicalizes
additionalOrigins but getAppOrigins calls expandToOrigins (which uses
SCHEME_REGEX) to tolerate legacy or unnormalized inputs and to remain safe if
the function is invoked outside the normalized-config path or future refactors
change callers; alternatively, if you decide the codebase guarantees normalized
input, remove the redundant expandToOrigins loop and note that normalizeConfig
produces fully expanded origins. Reference getAppOrigins, normalizeConfig,
expandToOrigins, and SCHEME_REGEX in the comment so readers understand the
reason for (or removal of) the defensive expansion.

In `@apps/server-core/test/unit/config/index.spec.ts`:
- Around line 54-68: Add a unit test for expandToOrigins that asserts a bare
hostname (e.g., 'hub.local') expands to both 'http://hub.local' and
'https://hub.local'; update the describe('expandToOrigins') block by adding an
it('should expand a bare host without port', ...) similar to the existing "bare
host with port" test but expecting origins without ports, using the
expandToOrigins function to locate the code under test.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 3eb6da32-798c-4fcf-a68d-617dec0f5d23

📥 Commits

Reviewing files that changed from the base of the PR and between 754811e and 2960bbc.

📒 Files selected for processing (15)
  • .agents/architecture.md
  • apps/server-core/src/app/modules/config/constants.ts
  • apps/server-core/src/app/modules/config/module.ts
  • apps/server-core/src/app/modules/config/normalize.ts
  • apps/server-core/src/app/modules/config/origins.ts
  • apps/server-core/src/app/modules/config/parse.ts
  • apps/server-core/src/app/modules/config/read/env.ts
  • apps/server-core/src/app/modules/config/types.ts
  • apps/server-core/src/app/modules/config/validator.ts
  • apps/server-core/src/cli/module.ts
  • apps/server-core/test/app/factory.ts
  • apps/server-core/test/unit/config/index.spec.ts
  • docs/src/guide/deployment/configuration-client-web.md
  • docs/src/guide/deployment/configuration-server-core.md
  • docs/src/guide/deployment/provisioning.md

@tada5hi

tada5hi commented Jun 12, 2026

Copy link
Copy Markdown
Collaborator Author

@coderabbitai pause

@coderabbitai

coderabbitai Bot commented Jun 12, 2026

Copy link
Copy Markdown
✅ Action performed

Reviews paused.

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 tada5hi changed the title feat(server-core)!: rename additionalDomains to additionalOrigins & accept scheme-less hosts feat(server-core)!: rename additionalDomains to trustedOrigins & accept scheme-less hosts Jun 12, 2026
tada5hi added 2 commits June 12, 2026 20:19
… 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).
- 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()
@tada5hi
tada5hi merged commit 3123430 into master Jun 12, 2026
14 checks passed
@tada5hi
tada5hi deleted the feat/additional-origins branch June 12, 2026 18:57
@github-actions github-actions Bot mentioned this pull request Jun 12, 2026
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