feat: add Helmet security headers and restrict CORS to known origin#116
Open
GitAddRemote wants to merge 1 commit intomainfrom
Open
feat: add Helmet security headers and restrict CORS to known origin#116GitAddRemote wants to merge 1 commit intomainfrom
GitAddRemote wants to merge 1 commit intomainfrom
Conversation
Install helmet for security headers, apply before all other middleware. Restrict CORS from wildcard to configurable ALLOWED_ORIGIN env variable. CORS allows credentials and standard HTTP methods. Production CORS origin should be set to https://station.drdnt.org. Development default: http://localhost:5173 (see .env.example). Closes #94
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.
Summary
helmetpackage for comprehensive HTTP security headers (CSP, HSTS, X-Frame-Options, etc.)app.use(helmet())as the first middleware in the bootstrap pipeline, before all other middlewareapp.enableCors()wildcard with origin-restricted CORS usingALLOWED_ORIGINenv variableConfigService(consistent with rest of app) instead of rawprocess.envALLOWED_ORIGIN=http://localhost:5173to.env.examplewith production comment (https://station.drdnt.org)Test plan
pnpm installto install thehelmetpackagepnpm dev:backendX-Frame-Options,Strict-Transport-Security,X-Content-Type-Options, etc.http://localhost:5173— should succeedALLOWED_ORIGIN=https://example.comand verify only that origin is allowedCloses #94