From 05f8a8be8f12d503a13b1a0b79eaa0b89482303c Mon Sep 17 00:00:00 2001 From: Waleed Latif Date: Sat, 5 Dec 2026 04:23:32 -0600 Subject: [PATCH 1/2] fix(landing): hold homepage failures briefly, refuse framable website policies, and tidy what the website move left - With no homepage copy to serve, a fetch failure from the last ten seconds answers for itself, so a website that is down does not hold each visitor for the full timeout before the fallback page. - The website's page policy is refused if its frame-ancestors allows any origin but this one, since it would override the route's X-Frame-Options. - AuthLegal requires its Terms and Privacy links; its /terms and /privacy defaults pointed at pages the platform no longer serves. - The integration docs slug uses the shared stripVersionSuffix, and the docs compile cache and --watch also key on the @sim/utils modules the integration pages render from. - Comments that still described the removed landing now describe the root route and auth shell. --- apps/docs/lib/integrations/seo-overrides.ts | 5 +- apps/docs/lib/integrations/seo.ts | 4 +- apps/docs/scripts/compile-content.ts | 2 + apps/sim/app/desktop/connect/page.test.tsx | 2 +- apps/sim/lib/website/homepage.test.ts | 50 ++++++++++++++++++- apps/sim/lib/website/homepage.ts | 37 +++++++++++--- apps/sim/next.config.ts | 2 +- apps/sim/proxy.ts | 2 +- packages/auth-ui/src/compositions.tsx | 14 ++---- .../deployment-config/src/integration-docs.ts | 5 +- 10 files changed, 96 insertions(+), 27 deletions(-) diff --git a/apps/docs/lib/integrations/seo-overrides.ts b/apps/docs/lib/integrations/seo-overrides.ts index 79519e5dd51..f1670036fee 100644 --- a/apps/docs/lib/integrations/seo-overrides.ts +++ b/apps/docs/lib/integrations/seo-overrides.ts @@ -1,8 +1,7 @@ /** * Hand-authored search titles, descriptions and FAQs for integrations whose pages the previous - * website (`apps/sim/app/(landing)/integrations/data/seo-content.ts`, removed when the website moved - * to simstudioai/site) had tuned. Keyed by catalog slug; any integration absent here, or any field - * left out, uses the generated default in `@/lib/integrations/seo`. + * website had tuned. Keyed by catalog slug; any integration absent here, or any field left out, + * uses the generated default in `@/lib/integrations/seo`. */ interface IntegrationSeoOverride { diff --git a/apps/docs/lib/integrations/seo.ts b/apps/docs/lib/integrations/seo.ts index 86112867ebf..29ba2a2a7da 100644 --- a/apps/docs/lib/integrations/seo.ts +++ b/apps/docs/lib/integrations/seo.ts @@ -1,7 +1,7 @@ import { INTEGRATION_TOTALS } from '@sim/deployment-config/integration-totals' import integrationsJson from '@sim/deployment-config/integrations.json' import { formatLowerBound } from '@sim/utils/formatting' -import { compareStrings } from '@sim/utils/string' +import { compareStrings, stripVersionSuffix } from '@sim/utils/string' import type { DocsPage } from '@/lib/content/types' import { INTEGRATION_SEO_OVERRIDES } from '@/lib/integrations/seo-overrides' @@ -255,7 +255,7 @@ export function getIntegrationCatalogContent(): IntegrationCatalogContent { label: label(id), integrations: members.map((integration) => ({ name: integration.name, - path: `/integrations/${integration.type.replace(/_v\d+$/, '')}`, + path: `/integrations/${stripVersionSuffix(integration.type)}`, description: integration.description, })), })), diff --git a/apps/docs/scripts/compile-content.ts b/apps/docs/scripts/compile-content.ts index 9ae438350ca..d6611cf6088 100644 --- a/apps/docs/scripts/compile-content.ts +++ b/apps/docs/scripts/compile-content.ts @@ -43,6 +43,8 @@ const PIPELINE_FILES = [ path.join(DOCS_ROOT, 'lib/integrations/seo-overrides.ts'), path.join(DOCS_ROOT, '../../packages/deployment-config/src/integrations.json'), path.join(DOCS_ROOT, '../../packages/deployment-config/src/integration-totals.ts'), + path.join(DOCS_ROOT, '../../packages/utils/src/formatting.ts'), + path.join(DOCS_ROOT, '../../packages/utils/src/string.ts'), ] const CONTENT_ROOT = path.join(DOCS_ROOT, 'content/docs') const OUTPUT_ROOT = path.join(DOCS_ROOT, '.content') diff --git a/apps/sim/app/desktop/connect/page.test.tsx b/apps/sim/app/desktop/connect/page.test.tsx index 131b0214d39..aa7cd574073 100644 --- a/apps/sim/app/desktop/connect/page.test.tsx +++ b/apps/sim/app/desktop/connect/page.test.tsx @@ -6,7 +6,7 @@ import { beforeEach, describe, expect, it, vi } from 'vitest' vi.mock('@/lib/auth/client', () => authClientMock) -/** Keeps the landing-page barrel the real shell pulls in out of this graph. */ +/** Keeps the auth shell the real component pulls in out of this graph. */ vi.mock('@/app/desktop/components/desktop-handoff-shell', () => ({ DesktopHandoffShell: () => null, })) diff --git a/apps/sim/lib/website/homepage.test.ts b/apps/sim/lib/website/homepage.test.ts index dcd904682cd..2629493043a 100644 --- a/apps/sim/lib/website/homepage.test.ts +++ b/apps/sim/lib/website/homepage.test.ts @@ -5,7 +5,11 @@ import { createServer, type IncomingHttpHeaders, type ServerResponse } from 'node:http' import type { AddressInfo } from 'node:net' import { afterEach, beforeAll, describe, expect, it, vi } from 'vitest' -import { fetchWebsiteHomepage, type HomepageFetchLimits } from '@/lib/website/homepage' +import { + fetchWebsiteHomepage, + getWebsiteHomepage, + type HomepageFetchLimits, +} from '@/lib/website/homepage' const PAGE = 'Sim

Agents for the work that runs itself

' const LIMITS: HomepageFetchLimits = { timeoutMs: 300, maxBytes: 64 * 1024 } @@ -50,6 +54,7 @@ beforeAll(() => { }) afterEach(async () => { + vi.restoreAllMocks() await Promise.all(closers.splice(0).map((close) => close())) }) @@ -152,6 +157,31 @@ describe('fetchWebsiteHomepage', () => { }) }) + it.each([ + "default-src 'none'; script-src 'self'; frame-ancestors *", + "default-src 'none'; script-src 'self'; frame-ancestors https://example.com", + "default-src 'none'; script-src 'self'; frame-ancestors 'self' https:", + ])('refuses a page policy that lets other sites frame the page: %s', async (policy) => { + const upstream = await startUpstream((response) => + html(response, { 'Content-Security-Policy': policy }) + ) + expect(await fetchWebsiteHomepage(upstream.origin, 'html', LIMITS)).toEqual({ + ok: false, + reason: 'unsafe_policy', + }) + }) + + it('accepts a page policy that lets only this origin frame the page', async () => { + const policy = "default-src 'none'; script-src 'self'; frame-ancestors 'self'" + const upstream = await startUpstream((response) => + html(response, { 'Content-Security-Policy': policy }) + ) + expect(await fetchWebsiteHomepage(upstream.origin, 'html', LIMITS)).toMatchObject({ + ok: true, + contentSecurityPolicy: policy, + }) + }) + it('refuses a response with more than one page policy', async () => { const upstream = await startUpstream((response) => { response.setHeader('Content-Type', 'text/html') @@ -288,3 +318,21 @@ describe('fetchWebsiteHomepage', () => { }) }) }) + +describe('getWebsiteHomepage', () => { + it('answers from a recent failure, without asking the website again, while it has no copy', async () => { + const upstream = await startUpstream((response) => { + response.writeHead(500, { 'Content-Type': 'text/html' }) + response.end('

upstream failure

') + }) + const failure = { ok: false, reason: 'bad_status' } + expect(await getWebsiteHomepage(upstream.origin, 'html')).toEqual(failure) + expect(await getWebsiteHomepage(upstream.origin, 'html')).toEqual(failure) + expect(upstream.requests).toHaveLength(1) + + const later = Date.now() + 11_000 + vi.spyOn(Date, 'now').mockReturnValue(later) + expect(await getWebsiteHomepage(upstream.origin, 'html')).toEqual(failure) + expect(upstream.requests).toHaveLength(2) + }) +}) diff --git a/apps/sim/lib/website/homepage.ts b/apps/sim/lib/website/homepage.ts index f715b233008..827e4a1e48a 100644 --- a/apps/sim/lib/website/homepage.ts +++ b/apps/sim/lib/website/homepage.ts @@ -30,6 +30,11 @@ const HOMEPAGE_FETCH_LIMITS: HomepageFetchLimits = { const HOMEPAGE_FRESH_MS = 60_000 /** How long a fetched homepage may still be served while the website keeps failing. */ const HOMEPAGE_STALE_LIMIT_MS = 60 * 60_000 +/** + * How long a failed fetch answers for itself while there is no copy to serve, so a website that is + * down does not hold each visitor for the full timeout before the fallback page. + */ +const HOMEPAGE_FAILURE_HOLD_MS = 10_000 type HomepageFetchFailure = | 'invalid_origin' @@ -156,10 +161,14 @@ function isSafeScriptSource(source: string): boolean { /** Script directives that override `script-src` for elements and attributes when present. */ const ELEMENT_SCRIPT_DIRECTIVES = ['script-src-elem', 'script-src-attr'] as const +/** Who may frame the page, if the policy says: it overrides the route's `X-Frame-Options: DENY`. */ +const SAFE_FRAME_ANCESTORS = new Set(["'none'", "'self'"]) + /** * Whether a page policy restricts script to safe sources: `script-src`, or `default-src` when it * is absent, must exist, and it and every `script-src-elem` / `script-src-attr` present may name - * no unsafe keyword, bare scheme or wildcard host. + * no unsafe keyword, bare scheme or wildcard host. A `frame-ancestors` it names may allow only + * this origin, or none. */ function isSafePolicy(policy: string): boolean { const directives = new Map() @@ -169,6 +178,10 @@ function isSafePolicy(policy: string): boolean { directives.set(name.toLowerCase(), sources) } } + const frameAncestors = directives.get('frame-ancestors') + if (frameAncestors?.some((source) => !SAFE_FRAME_ANCESTORS.has(source.toLowerCase()))) { + return false + } const scriptSources = directives.get('script-src') ?? directives.get('default-src') if (!scriptSources) return false return [ @@ -260,8 +273,10 @@ interface CachedHomepage extends WebsiteHomepage { fetchedAt: number } -/** Why the last refresh of each cached format failed, until one succeeds. */ -const lastRefreshFailure = new LRUCache({ max: 2 }) +/** Why and when the last refresh of each cached format failed, until one succeeds. */ +const lastRefreshFailure = new LRUCache({ + max: 2, +}) /** * The last good homepage, one entry per format of the one configured origin. Concurrent misses @@ -287,7 +302,7 @@ const homepageCache = new LRUCache fetchMethod: async (key, _stale, { context }) => { const result = await fetchWebsiteHomepage(context.origin, context.format) if (!result.ok) { - lastRefreshFailure.set(key, result.reason) + lastRefreshFailure.set(key, { reason: result.reason, at: Date.now() }) throw new HomepageFetchError(result.reason) } lastRefreshFailure.delete(key) @@ -312,13 +327,21 @@ function failureReason(error: unknown): HomepageFetchFailure { * The website's homepage for `/` in the requested format: fresh for a minute, then served while * the next refresh runs in the background. While the website keeps failing, the last good copy is * served for up to an hour (with the failed refresh's reason); past that, the visitor waits for a - * refresh. Not tied to any visitor's request signal, since one fetch serves every waiting visitor. + * refresh. With no copy to serve, a failure from the last ten seconds is the answer without + * another fetch. Not tied to any visitor's request signal, since one fetch serves every waiting + * visitor. */ export async function getWebsiteHomepage( origin: string, format: HomepageFormat ): Promise { const key = `${format} ${origin}` + const failure = lastRefreshFailure.get(key) + const copy = homepageCache.peek(key, { allowStale: true }) + const usable = copy !== undefined && Date.now() - copy.fetchedAt <= HOMEPAGE_STALE_LIMIT_MS + if (!usable && failure && Date.now() - failure.at < HOMEPAGE_FAILURE_HOLD_MS) { + return { ok: false, reason: failure.reason } + } const context: HomepageCacheContext = { origin, format } const status: LRUCache.Status = {} let cached: CachedHomepage | undefined @@ -332,9 +355,9 @@ export async function getWebsiteHomepage( } if (!cached) return { ok: false, reason: failureReason(status.fetchError) } if (Date.now() - cached.fetchedAt > HOMEPAGE_STALE_LIMIT_MS) { - return { ok: false, reason: lastRefreshFailure.get(key) ?? 'stale_expired' } + return { ok: false, reason: lastRefreshFailure.get(key)?.reason ?? 'stale_expired' } } - const refreshFailure = lastRefreshFailure.get(key) + const refreshFailure = lastRefreshFailure.get(key)?.reason return { ok: true, ...(refreshFailure ? { refreshFailure } : {}), diff --git a/apps/sim/next.config.ts b/apps/sim/next.config.ts index 2dfa2359cdc..55537624a98 100644 --- a/apps/sim/next.config.ts +++ b/apps/sim/next.config.ts @@ -351,7 +351,7 @@ const nextConfig: NextConfig = { ], }, // Apply security headers to routes not handled by middleware runtime CSP - // Middleware handles: /, /login, /signup, /workspace/* + // Middleware handles /login, /signup and /workspace/*; the root route sets its own headers // Exclude chat routes which have their own permissive embed headers { source: '/((?!workspace|chat|extension(?:/|$)|login|signup|$).*)', diff --git a/apps/sim/proxy.ts b/apps/sim/proxy.ts index 35847fdbc9e..b14617eb14b 100644 --- a/apps/sim/proxy.ts +++ b/apps/sim/proxy.ts @@ -473,7 +473,7 @@ function applyIndexingPolicy(request: NextRequest, response: NextResponse): Next export const config = { matcher: [ - '/', // Root path for self-hosted redirect logic + '/', // Session hint and self-hosted sign-in redirects; the root route serves the rest '/w', // Legacy /w redirect '/w/:path*', // Legacy /w/* redirects '/workspace/:path*', // New workspace routes diff --git a/packages/auth-ui/src/compositions.tsx b/packages/auth-ui/src/compositions.tsx index 5e95cb63951..5e8ae920c69 100644 --- a/packages/auth-ui/src/compositions.tsx +++ b/packages/auth-ui/src/compositions.tsx @@ -238,17 +238,13 @@ export function AuthSection({ title, children, className, description }: AuthSec interface AuthLegalProps { action: string - /** Terms of Service page; defaults to the host's `/terms`. */ - termsHref?: string - /** Privacy Policy page; defaults to the host's `/privacy`. */ - privacyHref?: string + /** Terms of Service page. */ + termsHref: string + /** Privacy Policy page. */ + privacyHref: string } /** Links the Terms of Service and Privacy Policy, opening them separately without losing form state. */ -export function AuthLegal({ - action, - termsHref = '/terms', - privacyHref = '/privacy', -}: AuthLegalProps) { +export function AuthLegal({ action, termsHref, privacyHref }: AuthLegalProps) { return (

By {action}, you agree to our{' '} diff --git a/packages/deployment-config/src/integration-docs.ts b/packages/deployment-config/src/integration-docs.ts index 2c4731b862f..d9f47c89c22 100644 --- a/packages/deployment-config/src/integration-docs.ts +++ b/packages/deployment-config/src/integration-docs.ts @@ -1,4 +1,5 @@ import { INTEGRATION_METADATA } from '@sim/deployment-config/integration-metadata' +import { stripVersionSuffix } from '@sim/utils/string' /** * Slugs the previous website's integration pages once had, each with the catalog slug that @@ -23,10 +24,10 @@ const RETIRED_INTEGRATION_SLUGS: Readonly> = { export const INTEGRATION_DOCS_PATHS: ReadonlyMap = (() => { const paths = new Map() for (const integration of INTEGRATION_METADATA) { - paths.set(integration.slug, `/integrations/${integration.type.replace(/_v\d+$/, '')}`) + paths.set(integration.slug, `/integrations/${stripVersionSuffix(integration.type)}`) } for (const integration of INTEGRATION_METADATA) { - const docsSlug = integration.type.replace(/_v\d+$/, '') + const docsSlug = stripVersionSuffix(integration.type) if (!paths.has(docsSlug)) paths.set(docsSlug, `/integrations/${docsSlug}`) } for (const [retired, current] of Object.entries(RETIRED_INTEGRATION_SLUGS)) { From d8efecc69056314aef1216d4a276ff2c7b374a32 Mon Sep 17 00:00:00 2001 From: Waleed Latif Date: Sat, 5 Dec 2026 04:36:00 -0600 Subject: [PATCH 2/2] test(landing): drop a mock restore the shared Vitest config already makes --- apps/sim/lib/website/homepage.test.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/apps/sim/lib/website/homepage.test.ts b/apps/sim/lib/website/homepage.test.ts index 2629493043a..ec32505ad54 100644 --- a/apps/sim/lib/website/homepage.test.ts +++ b/apps/sim/lib/website/homepage.test.ts @@ -54,7 +54,6 @@ beforeAll(() => { }) afterEach(async () => { - vi.restoreAllMocks() await Promise.all(closers.splice(0).map((close) => close())) })