Skip to content

feat: add Helmet security headers and restrict CORS to known origin#116

Open
GitAddRemote wants to merge 1 commit intomainfrom
fix/ISSUE-94-helmet-cors
Open

feat: add Helmet security headers and restrict CORS to known origin#116
GitAddRemote wants to merge 1 commit intomainfrom
fix/ISSUE-94-helmet-cors

Conversation

@GitAddRemote
Copy link
Copy Markdown
Owner

Summary

  • Installs helmet package for comprehensive HTTP security headers (CSP, HSTS, X-Frame-Options, etc.)
  • Applies app.use(helmet()) as the first middleware in the bootstrap pipeline, before all other middleware
  • Replaces app.enableCors() wildcard with origin-restricted CORS using ALLOWED_ORIGIN env variable
  • Retrieves config via ConfigService (consistent with rest of app) instead of raw process.env
  • Added ALLOWED_ORIGIN=http://localhost:5173 to .env.example with production comment (https://station.drdnt.org)

Test plan

  • Run pnpm install to install the helmet package
  • Start backend with pnpm dev:backend
  • Check response headers — should include X-Frame-Options, Strict-Transport-Security, X-Content-Type-Options, etc.
  • Make a cross-origin request from http://localhost:5173 — should succeed
  • Make a request from a different origin — should be rejected with CORS error
  • Set ALLOWED_ORIGIN=https://example.com and verify only that origin is allowed

Closes #94

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
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.

Tech Story: Add Helmet and restrict CORS to known origin

1 participant