From 524600830c5456c96a37f5c813bce47af1aba3bd Mon Sep 17 00:00:00 2001 From: Waleed Latif Date: Thu, 26 Nov 2026 11:17:27 -0800 Subject: [PATCH] improvement(config): one resolver for projected server switches, plus audit follow-ups - env-flags: the five server-only switches share resolveServerSwitch instead of five copies of the server/projection branch. - deployment-shape: isSameDeploymentShape compares every top-level field, so a new shape field cannot be missed and its reseed silently dropped; covered by a test that flips each switch. - Docs: drop the stale NEXT_PUBLIC pairs sentence in authentication, fix the Slack trigger variable count and wording, and point the upgrade note at the right reference. - Contract comment and a test mock message describe current behavior. --- apps/docs/content/docs/integrations/slack.mdx | 2 +- .../platform/self-hosting/authentication.mdx | 2 - .../self-hosting/integrations-oauth.mdx | 2 +- .../docs/platform/self-hosting/upgrades.mdx | 2 +- apps/sim/lib/api/contracts/workspaces.ts | 2 +- .../core/organization-activity.integration.ts | 2 +- .../core/config/deployment-shape.dom.test.tsx | 20 ++++++ apps/sim/lib/core/config/deployment-shape.ts | 16 +---- apps/sim/lib/core/config/env-flags.ts | 67 +++++++++---------- scripts/generate-docs.ts | 2 +- 10 files changed, 61 insertions(+), 56 deletions(-) diff --git a/apps/docs/content/docs/integrations/slack.mdx b/apps/docs/content/docs/integrations/slack.mdx index d97664d897d..3c029019b66 100644 --- a/apps/docs/content/docs/integrations/slack.mdx +++ b/apps/docs/content/docs/integrations/slack.mdx @@ -78,7 +78,7 @@ Sim requests these scopes when someone connects a Slack account. For a self-host | `reactions:write` | Add emoji reactions to messages | | `reactions:read` | View emoji reactions on messages | -Requested only when `SLACK_EXTENDED_SCOPES` is enabled. Enable them only after Slack approves the app for these scopes: +Requested only when `SLACK_EXTENDED_SCOPES` is enabled. Enable it only after Slack approves the app for these scopes: | Scope | Description | | ----- | ----------- | diff --git a/apps/docs/content/docs/platform/self-hosting/authentication.mdx b/apps/docs/content/docs/platform/self-hosting/authentication.mdx index 9cfd8b2d04a..fe9794be1b7 100644 --- a/apps/docs/content/docs/platform/self-hosting/authentication.mdx +++ b/apps/docs/content/docs/platform/self-hosting/authentication.mdx @@ -193,8 +193,6 @@ Requests use a shared anonymous session. | `DISABLE_PUBLIC_API=true` | Disable the public API globally. | | `ADMIN_API_KEY` | Enables Admin API GitOps operations and organization provisioning. | -Set both server and `NEXT_PUBLIC_` flags where a pair is listed. The server flag enforces the restriction; its counterpart controls the UI. - ## Verify authentication Sign out and sign back in at the public origin, then open a workflow in two browser windows and confirm edits propagate. Test each enabled login method. If verification is required, create a test account and confirm the message arrives and the verification succeeds. Use [Verify your install](/platform/self-hosting/verify) for deployment checks. diff --git a/apps/docs/content/docs/platform/self-hosting/integrations-oauth.mdx b/apps/docs/content/docs/platform/self-hosting/integrations-oauth.mdx index 51b0d71f48d..2c207c5c8f5 100644 --- a/apps/docs/content/docs/platform/self-hosting/integrations-oauth.mdx +++ b/apps/docs/content/docs/platform/self-hosting/integrations-oauth.mdx @@ -479,7 +479,7 @@ Webhook triggers receive callbacks from the provider and must be able to verify | `SLACK_SIGNING_SECRET` | Verifying Slack event and slash-command signatures | | `SLACK_EXTENDED_SCOPES` | Enabling the native Sim-app trigger and its broader Slack scope set | -When enabling the native Sim Slack trigger, configure all three variables together. Enable the extended-scope flags only after Slack approves the app for `assistant:write`, `app_mentions:read`, and `im:history`; otherwise Slack rejects OAuth authorization. Slack OAuth actions can use `SLACK_CLIENT_ID` and `SLACK_CLIENT_SECRET` without enabling the native trigger or supplying a signing secret. +When enabling the native Sim Slack trigger, configure both variables together. Enable `SLACK_EXTENDED_SCOPES` only after Slack approves the app for `assistant:write`, `app_mentions:read`, and `im:history`; otherwise Slack rejects OAuth authorization. Slack OAuth actions can use `SLACK_CLIENT_ID` and `SLACK_CLIENT_SECRET` without enabling the native trigger or supplying a signing secret. Your deployment must also be reachable from the provider's servers for webhook triggers to fire — a Sim instance on a private network can use polling triggers but not webhook triggers. Polling triggers additionally require the scheduler; see [Background Jobs](/platform/self-hosting/background-jobs). diff --git a/apps/docs/content/docs/platform/self-hosting/upgrades.mdx b/apps/docs/content/docs/platform/self-hosting/upgrades.mdx index f4e9cecda22..8704bb88d48 100644 --- a/apps/docs/content/docs/platform/self-hosting/upgrades.mdx +++ b/apps/docs/content/docs/platform/self-hosting/upgrades.mdx @@ -75,7 +75,7 @@ Check the changes for every release between your current version and the target |---|---| | **Redis is required.** Sim refuses to start without `REDIS_URL`; there is no PostgreSQL or in-memory fallback. | Keep the bundled Redis, or point `REDIS_URL` at a managed instance before upgrading. App and realtime must reach the same Redis. See [Redis](/platform/self-hosting/redis). | | **`REGISTRATION_MODE` replaces `DISABLE_REGISTRATION`, `DISABLE_EMAIL_SIGNUP`, and `EMAIL_PASSWORD_SIGNUP_ENABLED`** (and its `NEXT_PUBLIC_` twin). The old variables are still honored as deprecated aliases, and the most restrictive setting wins. `NEXT_PUBLIC_EMAIL_PASSWORD_SIGNUP_ENABLED=false` now also disables email/password sign-in on the server. | Move to `REGISTRATION_MODE`. See [Control registration and sign-in](/platform/self-hosting/authentication#controlling-who-can-sign-up). | -| **Enterprise `NEXT_PUBLIC_*` flags and `NEXT_PUBLIC_SANDBOXES_ENABLED` are no longer read, nor are `NEXT_PUBLIC_BILLING_ENABLED`, `NEXT_PUBLIC_E2B_ENABLED`, `NEXT_PUBLIC_SLACK_EXTENDED_SCOPES`, `NEXT_PUBLIC_DISABLE_INVITATIONS`, and `NEXT_PUBLIC_DISABLE_PUBLIC_API`.** The browser reads the server's resolved settings. | Set the server variable for each feature (`BILLING_ENABLED`, `E2B_ENABLED`, `SLACK_EXTENDED_SCOPES`, `DISABLE_INVITATIONS`, `DISABLE_PUBLIC_API`, …). See the [feature flag reference](/platform/enterprise/self-hosted#feature-flag-reference). | +| **Enterprise `NEXT_PUBLIC_*` flags and `NEXT_PUBLIC_SANDBOXES_ENABLED` are no longer read, nor are `NEXT_PUBLIC_BILLING_ENABLED`, `NEXT_PUBLIC_E2B_ENABLED`, `NEXT_PUBLIC_SLACK_EXTENDED_SCOPES`, `NEXT_PUBLIC_DISABLE_INVITATIONS`, and `NEXT_PUBLIC_DISABLE_PUBLIC_API`.** The browser reads the server's resolved settings. | Set the server variable of the same name without the `NEXT_PUBLIC_` prefix (`BILLING_ENABLED`, `E2B_ENABLED`, `DISABLE_INVITATIONS`, …). The enterprise flags are listed in the [feature flag reference](/platform/enterprise/self-hosted#feature-flag-reference). | | **`ALLOW_PRIVATE_DATABASE_HOSTS` was removed.** The app logs an error at startup if it is still set. | Name your database, cache, and mail hosts in the egress allowlists. See [Upgrading from an earlier release](/platform/self-hosting/security#upgrading-from-an-earlier-release). | | **White-labeling was removed.** `NEXT_PUBLIC_BRAND_*`, `NEXT_PUBLIC_CUSTOM_CSS_URL`, `NEXT_PUBLIC_SUPPORT_EMAIL`, `NEXT_PUBLIC_DOCUMENTATION_URL`, `NEXT_PUBLIC_TERMS_URL`, `NEXT_PUBLIC_PRIVACY_URL`, `WHITELABELING_ENABLED`, and `NEXT_PUBLIC_WHITELABELING_ENABLED` are ignored. | Remove them at your convenience; leaving them set is harmless. | | **`docker-compose.ollama.yml` is now an overlay on `docker-compose.prod.yml`.** | A stack started from the previous standalone file needs its project name carried over, or it starts on an empty database. See [Migrating from the previous Ollama stack](/platform/self-hosting/docker#migrating-from-the-previous-ollama-stack). | diff --git a/apps/sim/lib/api/contracts/workspaces.ts b/apps/sim/lib/api/contracts/workspaces.ts index 36b4586ef60..be22578691b 100644 --- a/apps/sim/lib/api/contracts/workspaces.ts +++ b/apps/sim/lib/api/contracts/workspaces.ts @@ -274,7 +274,7 @@ export const deploymentShapeSchema = z.object({ */ registrationMode: z.enum(REGISTRATION_MODES).optional(), /** - * Server-only switches the browser used to read from `NEXT_PUBLIC_*` twins. Optional + * Server-only switches, resolved on the server and projected for the browser. Optional * for rolling compatibility with app versions that predate projecting them; readers * treat absent as `false`. */ diff --git a/apps/sim/lib/billing/core/organization-activity.integration.ts b/apps/sim/lib/billing/core/organization-activity.integration.ts index 6cf512780dd..3d771e0513f 100644 --- a/apps/sim/lib/billing/core/organization-activity.integration.ts +++ b/apps/sim/lib/billing/core/organization-activity.integration.ts @@ -10,7 +10,7 @@ const databaseUrl = readTestDatabaseUrl() vi.mock('@sim/db', () => ({ dbReplica: { execute, select } })) vi.mock('@/lib/core/config/redis', () => ({ getRedisClient: () => { - throw new Error('Redis is not used by this suite; the usage cache reads the ledger') + throw new Error('Redis is unavailable in this suite; the usage cache falls back to the ledger') }, })) diff --git a/apps/sim/lib/core/config/deployment-shape.dom.test.tsx b/apps/sim/lib/core/config/deployment-shape.dom.test.tsx index 99e0892aedc..bd208b86fae 100644 --- a/apps/sim/lib/core/config/deployment-shape.dom.test.tsx +++ b/apps/sim/lib/core/config/deployment-shape.dom.test.tsx @@ -141,6 +141,26 @@ describe('seeded server shape', () => { expect(apiKeyFieldShown('custom/model')).toBe(true) }) + it('takes a reseed that changes any top-level switch', () => { + const switches = (Object.keys(HOSTED) as (keyof DeploymentShape)[]).filter( + (key) => typeof HOSTED[key] === 'boolean' + ) + expect(switches.length).toBeGreaterThan(0) + for (const key of switches) { + seedDeploymentShape(HOSTED) + const changed = { ...HOSTED, [key]: !HOSTED[key] } + seedDeploymentShape(changed) + expect(getDeploymentShape(), key).toBe(changed) + } + }) + + it('keeps the current seed for an equal shape', () => { + seedDeploymentShape(HOSTED) + seedDeploymentShape({ ...HOSTED, features: { ...HOSTED.features } }) + + expect(getDeploymentShape()).toBe(HOSTED) + }) + it('is ignored when the server predates deployment projection', () => { seedDeploymentShape(undefined) diff --git a/apps/sim/lib/core/config/deployment-shape.ts b/apps/sim/lib/core/config/deployment-shape.ts index 213034da8bd..5fb25fc01b2 100644 --- a/apps/sim/lib/core/config/deployment-shape.ts +++ b/apps/sim/lib/core/config/deployment-shape.ts @@ -137,19 +137,9 @@ export function resolveDeploymentShape(): DeploymentShape { function isSameDeploymentShape(seeded: DeploymentShape | null, next: DeploymentShape): boolean { if (seeded === null) return false - if ( - seeded.hosted !== next.hosted || - seeded.billingEnabled !== next.billingEnabled || - seeded.chatEnabled !== next.chatEnabled || - seeded.azureConfigured !== next.azureConfigured || - seeded.cohereConfigured !== next.cohereConfigured || - seeded.registrationMode !== next.registrationMode || - seeded.e2bEnabled !== next.e2bEnabled || - seeded.slackExtendedScopes !== next.slackExtendedScopes || - seeded.invitationsDisabled !== next.invitationsDisabled || - seeded.publicApiDisabled !== next.publicApiDisabled - ) { - return false + const keys = new Set([...Object.keys(seeded), ...Object.keys(next)]) as Set + for (const key of keys) { + if (key !== 'features' && seeded[key] !== next[key]) return false } const featureKeys = Object.keys(next.features) as (keyof DeploymentFeatures)[] return featureKeys.every((key) => seeded.features[key] === next.features[key]) diff --git a/apps/sim/lib/core/config/env-flags.ts b/apps/sim/lib/core/config/env-flags.ts index af913c6d1eb..cf428dc0b6b 100644 --- a/apps/sim/lib/core/config/env-flags.ts +++ b/apps/sim/lib/core/config/env-flags.ts @@ -121,16 +121,23 @@ export const isCopilotToolPermissionsEnabled = isTruthy(env.COPILOT_TOOL_PERMISS export const isMothershipBenchmarkEnabled = isTruthy(env.MOTHERSHIP_BENCHMARK_ENABLED) /** - * Is billing enforcement enabled. - * - * Server code reads `BILLING_ENABLED`. The browser never sees that variable and - * takes the server's answer from the deployment-shape projection on `` - * (`./deployment-projection`); a document without one reads it as off. + * A server-only switch: `serverValue` on the server; in the browser, which never + * sees server variables, the server's answer from the deployment-shape projection + * on `` (`./deployment-projection`), off on a document without one. + */ +function resolveServerSwitch( + serverValue: Parameters[0], + projectedKey: string +): boolean { + return typeof window === 'undefined' + ? isTruthy(serverValue) + : (readProjectedBoolean(projectedKey) ?? false) +} + +/** + * Is billing enforcement enabled (`BILLING_ENABLED`). */ -export const isBillingEnabled = - typeof window === 'undefined' - ? isTruthy(env.BILLING_ENABLED) - : (readProjectedBoolean('billingEnabled') ?? false) +export const isBillingEnabled = resolveServerSwitch(env.BILLING_ENABLED, 'billingEnabled') /** * Is email verification enabled @@ -296,15 +303,14 @@ export const isAppConfigEnabled = * off there until review lands; a self-hosted deployment pointing at its own * (unlisted) Slack app can opt in. * - * Server code reads `SLACK_EXTENDED_SCOPES`; the browser reads the server's answer - * from the deployment-shape projection (see {@link isBillingEnabled}). The server - * value decides the grant; the browser value only decides what the credential - * pickers advertise and treat as missing. + * Read from `SLACK_EXTENDED_SCOPES`. The server value decides the grant; the + * browser value only decides what the credential pickers advertise and treat as + * missing. */ -export const isSlackExtendedScopesEnabled = - typeof window === 'undefined' - ? isTruthy(env.SLACK_EXTENDED_SCOPES) - : (readProjectedBoolean('slackExtendedScopes') ?? false) +export const isSlackExtendedScopesEnabled = resolveServerSwitch( + env.SLACK_EXTENDED_SCOPES, + 'slackExtendedScopes' +) /** * Is Trigger.dev enabled for async job processing @@ -553,33 +559,24 @@ export const isAzureConfigured = isTruthy(getEnv('NEXT_PUBLIC_AZURE_CONFIGURED') export const isCohereConfigured = isTruthy(getEnv('NEXT_PUBLIC_COHERE_CONFIGURED')) /** - * Are workspace invitations disabled for every user (`DISABLE_INVITATIONS`). The - * browser reads the server's answer from the deployment-shape projection. + * Are workspace invitations disabled for every user (`DISABLE_INVITATIONS`). */ -export const isInvitationsDisabled = - typeof window === 'undefined' - ? isTruthy(env.DISABLE_INVITATIONS) - : (readProjectedBoolean('invitationsDisabled') ?? false) +export const isInvitationsDisabled = resolveServerSwitch( + env.DISABLE_INVITATIONS, + 'invitationsDisabled' +) /** * Is public API access disabled for every workspace (`DISABLE_PUBLIC_API`): the - * public API toggle is hidden and public API access is blocked. The browser reads - * the server's answer from the deployment-shape projection. + * public API toggle is hidden and public API access is blocked. */ -export const isPublicApiDisabled = - typeof window === 'undefined' - ? isTruthy(env.DISABLE_PUBLIC_API) - : (readProjectedBoolean('publicApiDisabled') ?? false) +export const isPublicApiDisabled = resolveServerSwitch(env.DISABLE_PUBLIC_API, 'publicApiDisabled') /** * Is the E2B code-execution provider switched on (`E2B_ENABLED`). Pi's cloud modes - * run in an E2B sandbox and stay hidden without it. The browser reads the server's - * answer from the deployment-shape projection. + * run in an E2B sandbox and stay hidden without it. */ -export const isE2bEnabled = - typeof window === 'undefined' - ? isTruthy(env.E2B_ENABLED) - : (readProjectedBoolean('e2bEnabled') ?? false) +export const isE2bEnabled = resolveServerSwitch(env.E2B_ENABLED, 'e2bEnabled') /** * Is Google OAuth login disabled diff --git a/scripts/generate-docs.ts b/scripts/generate-docs.ts index 6dbd8049786..4fedd266762 100755 --- a/scripts/generate-docs.ts +++ b/scripts/generate-docs.ts @@ -4937,7 +4937,7 @@ async function buildOAuthScopesSection( if (gatedScopes.length) { section += - 'Requested only when `SLACK_EXTENDED_SCOPES` is enabled. Enable them only after Slack approves the app for these scopes:\n\n' + 'Requested only when `SLACK_EXTENDED_SCOPES` is enabled. Enable it only after Slack approves the app for these scopes:\n\n' section += scopeTable(gatedScopes, describe) }