From 2cf7080b411f8e7b7dcad4eaf62a7fc2e14cd82a Mon Sep 17 00:00:00 2001 From: "Liam Verdejo (ES)" Date: Thu, 12 Nov 2026 08:46:38 +0100 Subject: [PATCH 1/5] Fix: Resolve bug security and sidebar --- .github/copilot-instructions.md | 8 ++++++++ CLAUDE.md | 8 ++++++++ src/hooks.server.ts | 18 ++++++++++++++++-- src/lib/page-store.ts | 17 +++++++++++++++-- 4 files changed, 47 insertions(+), 4 deletions(-) diff --git a/.github/copilot-instructions.md b/.github/copilot-instructions.md index fad4150a..27828a8a 100644 --- a/.github/copilot-instructions.md +++ b/.github/copilot-instructions.md @@ -111,3 +111,11 @@ Usar los patrones existentes (`*.domain.ts`, `*.service.ts`, `*.repository.ts`, inyeccion de dependencias y fakes en memoria. Los handlers API validan permisos primero y normalizan errores. Ejecutar `bun run check`, `bun run lint`, `bun run test` y `bun run format:check` antes de terminar cambios relevantes. + +## Comportamiento conocido + +**Startup y readiness del servidor:** El auth guard en `hooks.server.ts` espera a que `serverReady` +complete antes de procesar cualquier request. Si el startup falla, todos los requests reciben +503 Service Unavailable (JSON para API calls, texto plano para otros). Aplica tanto en dev +(Vite carga el módulo en la primera request) como en producción. La bootstrap state solo es +válida después de que startup termina. diff --git a/CLAUDE.md b/CLAUDE.md index 3df4eef2..e2ee9e25 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -192,3 +192,11 @@ permission-first and normalize errors consistently. Before finishing a change, run the relevant checks. Do not silently fix unrelated bugs or rewrite generated files. Update `README.md`, `CONTRIBUTING.md`, and this file when architecture or public commands change. + +## Known behavior + +**Server startup and readiness:** The auth guard in `hooks.server.ts` waits for `serverReady` before +processing any request. If startup fails, all requests receive a 503 Service Unavailable response +(JSON for API calls, plain text for others). This applies in both development (where Vite loads +the module on the first request) and production (where no infrastructure probe guarantees traffic +will be held back during startup). The bootstrap state is only meaningful after startup completes. diff --git a/src/hooks.server.ts b/src/hooks.server.ts index b3cf628c..1115d851 100644 --- a/src/hooks.server.ts +++ b/src/hooks.server.ts @@ -63,8 +63,22 @@ const authGuard: Handle = async ({ event, resolve }) => { return resolve(event); } - // readiness gating happens at the infrastructure level: Cloud Run's startup probe - // polls /health and only routes traffic once the server reports ready + // the bootstrap state is only meaningful once startup has finished: before that it reads as + // "pending" and every request would be sent to (and allowed into) the unauthenticated wizard. + // Vite dev loads this module on the first request, and in production nothing guarantees an + // infrastructure probe holds traffic back, so the guard waits here instead of trusting either. + try { + await serverReady; + } catch { + const message = 'Server failed to start'; + return isApiRequest + ? new Response(JSON.stringify({ error: message }), { + status: 503, + headers: { 'content-type': 'application/json' }, + }) + : new Response(message, { status: 503, headers: { 'content-type': 'text/plain' } }); + } + if (pathname.startsWith('/bootstrap')) { if (isBootstrapCompleted()) { return new Response(null, { status: 302, headers: { location: '/' } }); diff --git a/src/lib/page-store.ts b/src/lib/page-store.ts index 5df05d8b..2c0fc76d 100644 --- a/src/lib/page-store.ts +++ b/src/lib/page-store.ts @@ -1,6 +1,19 @@ import { page } from '$app/state'; import { toStore } from 'svelte/store'; +// `page` is a single long-lived object whose fields are reactive getters. Returning it as-is +// (`toStore(() => page)`) reads none of those getters, so the store never re-emits after a +// client-side navigation and `$page.url` stays frozen at the first page that was rendered. +// Reading each field here registers them as dependencies and yields a fresh snapshot per change. export function createPageStore() { - return toStore(() => page); -} \ No newline at end of file + return toStore(() => ({ + url: page.url, + params: page.params, + route: page.route, + status: page.status, + error: page.error, + data: page.data, + form: page.form, + state: page.state, + })); +} From 4f3a9405546abcd336fa3f50b9b622de60b8f577 Mon Sep 17 00:00:00 2001 From: "Liam Verdejo (ES)" Date: Thu, 12 Nov 2026 12:27:21 +0100 Subject: [PATCH 2/5] Fix: Resolve bug security and sidebar --- eslint.config.js | 7 ++++++- src/lib/code-report/vulnerability-format.test.ts | 16 ++++++++++++++++ src/lib/code-report/vulnerability-format.ts | 7 +++++++ .../components/code-report/CveDetailView.svelte | 1 + .../infrastructure/crypto/secret-cipher.test.ts | 2 +- 5 files changed, 31 insertions(+), 2 deletions(-) diff --git a/eslint.config.js b/eslint.config.js index d8cc6609..c539e1a3 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -31,7 +31,11 @@ export default [ ...tseslint.configs.recommended.rules, '@typescript-eslint/no-explicit-any': 'off', 'no-unused-vars': 'off', - '@typescript-eslint/no-unused-vars': ['error', { argsIgnorePattern: '^_' }], + 'no-undef': 'off', + '@typescript-eslint/no-unused-vars': [ + 'error', + { argsIgnorePattern: '^_', ignoreRestSiblings: true }, + ], }, }, { @@ -55,6 +59,7 @@ export default [ 'svelte/require-each-key': 'off', 'svelte/prefer-svelte-reactivity': 'off', 'no-useless-assignment': 'off', + 'svelte/no-useless-mustaches': ['error', { ignoreStringEscape: true }], }, }, prettier, diff --git a/src/lib/code-report/vulnerability-format.test.ts b/src/lib/code-report/vulnerability-format.test.ts index b0a02233..eab7c795 100644 --- a/src/lib/code-report/vulnerability-format.test.ts +++ b/src/lib/code-report/vulnerability-format.test.ts @@ -25,4 +25,20 @@ describe('vulnerability format', () => { expect(rendered).not.toContain('` + : ''; + + const html = ` + + + + + +${title} +${poll} + + + +
+
GitOps
+ ${starting ? '' : ''} +

${title}

+

${body}

+
+ +`; + + return new Response(html, { + status: 503, + headers: { + 'content-type': 'text/html; charset=utf-8', + 'cache-control': 'no-store', + ...(starting ? { 'retry-after': String(RETRY_AFTER_SECONDS) } : {}), + }, + }); +}