Skip to content

fix: validate SESSION_SECRET in production at runtime (build-safe) - #114

Closed
Inkcha wants to merge 2 commits into
profullstack:masterfrom
Inkcha:fix/session-secret-validation
Closed

fix: validate SESSION_SECRET in production at runtime (build-safe)#114
Inkcha wants to merge 2 commits into
profullstack:masterfrom
Inkcha:fix/session-secret-validation

Conversation

@Inkcha

@Inkcha Inkcha commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

Description

Prevents the insecure dev fallback SESSION_SECRET from reaching production. If the env var is missing at production runtime, the app now throws instead of silently using a hardcoded fallback.

Why the previous attempt failed

The first version threw at module load whenever NODE_ENV=production and SESSION_SECRET was unset. CI runs next build with NODE_ENV=production (and no SESSION_SECRET), so page-data collection (e.g. /robots.txt route importing env.ts) crashed the build.

Fix

Skip validation when NEXT_PHASE=phase-production-build (set by Next.js during next build), still hard-fail at production runtime when the secret is missing. Follows the existing lazy-init convention in lib/db.ts ("next build doesn't open the runtime volume DB").

Related

Fixes #88

Inkcha added 2 commits July 27, 2026 19:30
…ecure

The sessionSecret defaulted to a hardcoded dev-only value if
SESSION_SECRET env var was not set. In production this means
anyone knowing the default can forge session tokens.

This change throws a startup error in production if SESSION_SECRET
is missing, while preserving the dev fallback for local development.

Fixes the HIGH severity issue reported in profullstack#88
The previous IIFE threw during 'next build' because CI builds with
NODE_ENV=production but no SESSION_SECRET (page-data collection imports
env.ts). Now the validation is skipped when NEXT_PHASE equals
phase-production-build (Next.js sets this during builds) and still
hard-fails at actual production runtime when the secret is missing.
@Inkcha

Inkcha commented Jul 31, 2026

Copy link
Copy Markdown
Contributor Author

Superseded by #103 (merged) — Zino's getter-based approach achieves the same runtime hard-fail without the NEXT_PHASE build-phase check, and it's cleaner. No further action needed; closing this to avoid duplicate fixes.

@Inkcha Inkcha closed this Jul 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

HIGH: Dev fallback SESSION_SECRET forgeable in production (env.ts:22)

1 participant