fix: validate SESSION_SECRET in production at runtime (build-safe) - #114
Closed
Inkcha wants to merge 2 commits into
Closed
fix: validate SESSION_SECRET in production at runtime (build-safe)#114Inkcha wants to merge 2 commits into
Inkcha wants to merge 2 commits into
Conversation
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.
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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Prevents the insecure dev fallback
SESSION_SECRETfrom 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=productionandSESSION_SECRETwas unset. CI runsnext buildwith 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 duringnext 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