Repository navigation
feat(server-core)!: rename additionalDomains to trustedOrigins & accept scheme-less hosts - #3120
Conversation
…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.
|
Important Review skippedThis 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 configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
📝 WalkthroughWalkthroughThis PR refactors the application's configuration system to replace the ChangesConfiguration Origins & Async Refactoring
Sequence DiagramsequenceDiagram
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
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. 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: |
There was a problem hiding this comment.
Actionable comments posted: 3
🧹 Nitpick comments (2)
apps/server-core/test/unit/config/index.spec.ts (1)
54-68: ⚡ Quick winConsider 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
additionalOriginsentries are "already canonicalized by normalizeConfig" but then "raw values (scheme-less hosts) are tolerated and expanded the same way." This suggestsgetAppOriginsis intentionally defensive and can handle both normalized and raw inputs.However, the comment doesn't clearly explain why this defensive behavior is necessary. If
getAppOriginsis always called with normalized config (where origins are already expanded), the re-expansion viaexpandToOriginsis redundant (though harmless due to theSCHEME_REGEXcheck returning the single origin for already-expanded entries).Consider updating the comment to clarify either:
- That
getAppOriginsmay be called outside the normalized config path, or- That the defensive expansion is a safety measure for future refactoring, or
- Remove the redundancy if
getAppOriginswill 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
📒 Files selected for processing (15)
.agents/architecture.mdapps/server-core/src/app/modules/config/constants.tsapps/server-core/src/app/modules/config/module.tsapps/server-core/src/app/modules/config/normalize.tsapps/server-core/src/app/modules/config/origins.tsapps/server-core/src/app/modules/config/parse.tsapps/server-core/src/app/modules/config/read/env.tsapps/server-core/src/app/modules/config/types.tsapps/server-core/src/app/modules/config/validator.tsapps/server-core/src/cli/module.tsapps/server-core/test/app/factory.tsapps/server-core/test/unit/config/index.spec.tsdocs/src/guide/deployment/configuration-client-web.mddocs/src/guide/deployment/configuration-server-core.mddocs/src/guide/deployment/provisioning.md
|
@coderabbitai pause |
✅ Action performedReviews 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).
… 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()
Summary
additionalDomains→trustedOrigins, env varADDITIONAL_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.hub.local,hub.local:8080), which expands to both its http and https origin viaexpandToOrigins. An entry with an explicit protocol contributes exactly that origin — the way to restrict a host to https only.normalizeConfigexpands + dedupes the list, soConfig['trustedOrigins']always holds bare origins (scheme://host[:port]) and the dev-origin seeding can't duplicate.parseConfig's plain zod object schema moved to the project-standardConfigValidator(validup container +@validup/zod), makingparseConfig/normalizeConfigasync.ConfigModulenow also accepts a lazy config factory so the test app factory stays sync.webclient'sredirect_uriallowlist (<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.configuration-server-core,provisioning,configuration-client-web) and.agents/architecture.mdupdated.Test plan
expandToOrigins(full URL, bare host+port, invalid),parseConfig(mixed shapes, rejection, unknown-key stripping),normalizeConfig(canonicalization, dev-origin idempotency).apps/server-coresuite: 89 files / 877 tests passing.Summary by CodeRabbit
New Features
Documentation
additionalDomains→trustedOrigins.ADDITIONAL_DOMAINS→TRUSTED_ORIGINS.