security: refuse to boot in production if secret env vars are unset#549
Open
xpoes123 wants to merge 1 commit into
Open
security: refuse to boot in production if secret env vars are unset#549xpoes123 wants to merge 1 commit into
xpoes123 wants to merge 1 commit into
Conversation
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.
The app silently falls back to publicly-known placeholder values (
'secret','salt','secretKey1','secretKey2') whenSECRET,SALT,SECRET_KEY_1, orSECRET_KEY_2are unset. Anyone who reads the source can forge session cookies and JWT tokens outright if the app is ever deployed without those variables set.Problem
server/authentication.jsusesprocess.env.SALT ? process.env.SALT : 'salt'and similar fallbacks for all four secrets. A production deployment missing any of these variables would run with trivially-known signing material while appearing healthy.Changes
app.js— adds a production-only startup guard immediately after imports. IfNODE_ENV === 'production'and any ofSECRET,SALT,SECRET_KEY_1, orSECRET_KEY_2is falsy, the process throws before the Express app is created. The existing?? 'default'fallbacks inserver/authentication.jsare left untouched sonpm run devcontinues to work without a local.env.Risk & testing
The guard only runs when
NODE_ENV === 'production', so local development and CI are unaffected.Before merging: confirm that all four variables —
SECRET,SALT,SECRET_KEY_1, andSECRET_KEY_2— are set in the production environment (e.g. Heroku config vars). If any one is absent, the dyno will refuse to start after this deploy.