-
Notifications
You must be signed in to change notification settings - Fork 0
Tech Story: Add Helmet and restrict CORS to known origin #94
Copy link
Copy link
Open
Labels
backendBackend services and logicBackend services and logicconfigConfiguration and feature flagsConfiguration and feature flagssecuritySecurity, auth, and permissionsSecurity, auth, and permissionstech-storyTechnical implementation storyTechnical implementation story
Milestone
Description
Tech Story
As a platform engineer, I want the API to send standard security response headers and only accept requests from known origins so that common browser-based attacks (clickjacking, MIME sniffing, protocol downgrade) are mitigated by default.
Context
app.enableCors() with no options defaults to origin: '*', allowing any origin to make cross-origin requests. No security headers (Content-Security-Policy, X-Frame-Options, X-Content-Type-Options, Strict-Transport-Security, etc.) are set anywhere. Both are table-stakes for any public-facing API.
Acceptance Criteria
-
helmet()applied globally inmain.tsbefore route handlers - CORS restricted to
ALLOWED_ORIGINenv var (required — app fails to start if missing) - CORS configured with
credentials: trueto support httpOnly cookie auth (see Tech Story: Switch auth tokens to httpOnly cookies #93) -
Strict-Transport-Securityheader present in production responses -
X-Frame-Options: DENYpresent in all responses -
X-Content-Type-Options: nosniffpresent in all responses -
ALLOWED_ORIGINdocumented in.env.example
Technical Elaboration
- Install
helmet; callapp.use(helmet())inmain.ts - Replace
app.enableCors()with:app.enableCors({ origin: configService.get('ALLOWED_ORIGIN'), credentials: true, methods: ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'OPTIONS'], });
- Helmet defaults cover most headers; no custom CSP needed at this stage
- CORS
originmust be a string/array, not*, whencredentials: true(browsers reject credentialed requests to wildcard origins)
Notes
- Depends on or should land alongside Tech Story: Switch auth tokens to httpOnly cookies #93 (cookie auth) since
credentials: trueis required for cookies to be sent cross-origin - For local dev,
ALLOWED_ORIGIN=http://localhost:5173in.env
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
backendBackend services and logicBackend services and logicconfigConfiguration and feature flagsConfiguration and feature flagssecuritySecurity, auth, and permissionsSecurity, auth, and permissionstech-storyTechnical implementation storyTechnical implementation story