security: add startup security configuration verification#665
Open
mmcintosh wants to merge 1 commit intoSonicJs-Org:mainfrom
Open
security: add startup security configuration verification#665mmcintosh wants to merge 1 commit intoSonicJs-Org:mainfrom
mmcintosh wants to merge 1 commit intoSonicJs-Org:mainfrom
Conversation
Validates security-critical environment variables (JWT_SECRET, CORS_ORIGINS, ENVIRONMENT) on first request. Logs warnings in development, throws a hard error in production when JWT_SECRET is missing or uses the default value. Runs once per worker instance inside the bootstrap middleware.
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.
Security: Add Startup Security Configuration Verification
Summary
Validates security-critical environment variables (
JWT_SECRET,CORS_ORIGINS,ENVIRONMENT) on first request. Logs warnings in development, throws a hard error in production whenJWT_SECRETis missing or uses the default value.Changes
1. Security Configuration Verification
verifySecurityConfig()function in bootstrap middleware[SonicJS Security]warnings to consoleJWT_SECRETis missing or still the default value2. Verification Logic
JWT_SECRETnot setJWT_SECRET= defaultCORS_ORIGINSnot setENVIRONMENTnot set3. Unit Tests
Technical Details
packages/core/src/middleware/bootstrap.tsverifySecurityConfig(), extendedBindingstype with security env vars, called after bootstrap completes (outside try/catch so production errors propagate)packages/core/src/middleware/index.tsverifySecurityConfigpackages/core/src/__tests__/middleware/bootstrap-security.test.tsTesting
Performance Impact
None — runs once per worker instance, only string comparisons.
Breaking Changes
JWT_SECRETwill fail on first request with a clear error message. This is intentional — preventing insecure deployments from running silently.Migration Notes
JWT_SECRETis set viawrangler secret put JWT_SECRETbefore deploying.CORS_ORIGINSandENVIRONMENT=productionin wrangler.toml[vars].Known Issues
None.
Related Issues
Implements the aspirational
verifySecurityConfig()described in upstream security documentation.Checklist