Phase 16: CI dependency audit & security checks #15

Merged
luckberg merged 40 commits from gsd/phase-16-ci-dependency-audit-and-security-checks into main 2026-06-13 10:01:01 -04:00
2 changed files with 38 additions and 0 deletions
Showing only changes of commit c2ffd1c1b2 - Show all commits
+4
View File
@@ -15,6 +15,7 @@ import { persistSessionCookie } from './auth/persistSessionCookie.js';
import { startBrokerPoller } from './broker/poller.js';
import { startOutboxWorker, initOutboxTrigger } from './broker/outboxWorker.js';
import { startReminderScheduler } from './broker/reminderScheduler.js';
import { assertNotDevBypassInProduction } from './lib/bootGuards.js';
import webpush from 'web-push';
export const app = new Hono();
@@ -110,6 +111,9 @@ function isMainModule(): boolean {
// (not imported in tests). WR-04: gating the cron schedules here keeps them out of the
// test process.
if (isMainModule()) {
// D-08: Production safety guard — must be FIRST, before VAPID config, workers, or serve().
assertNotDevBypassInProduction();
// Configure VAPID credentials for web-push before starting background workers.
// VAPID_SUBJECT must be a mailto: or https: URL identifying the operator.
// The private key is NEVER served to clients; it signs push requests server-side only.
+34
View File
@@ -0,0 +1,34 @@
/**
* Boot-time production safety guards (D-08).
*
* Exported as a standalone function so it can be unit-tested without
* forking a process or importing the full app module graph.
*
* Call assertNotDevBypassInProduction() as the FIRST statement inside
* the isMainModule() block in index.ts, before VAPID config, workers,
* or serve(). Placement after any network/DB calls would allow a misconfigured
* production container to partially start before the guard fires.
*/
/**
* Refuses to start the process when NODE_ENV==='production' AND
* DEV_AUTH_BYPASS==='true'.
*
* Rationale (D-07 + D-08): The production Dockerfile bakes NODE_ENV=production,
* engaging the devBypass.ts hard guard. This boot guard is defense-in-depth — it
* converts a silent misconfiguration (operator accidentally sets DEV_AUTH_BYPASS=true
* in the production compose) into an immediate, loud, non-zero-exit failure instead
* of a silently bypassed auth layer.
*
* The function evaluates env vars at call time (when the app starts), not at import
* time, so the test suite can set env vars before calling it without module-cache tricks.
*/
export function assertNotDevBypassInProduction(): void {
if (process.env.NODE_ENV === 'production' && process.env.DEV_AUTH_BYPASS === 'true') {
console.error(
'[FATAL] DEV_AUTH_BYPASS=true is set in a production environment. ' +
'This configuration is forbidden. Refusing to start.',
);
process.exit(1);
}
}