security: Apply Security Middleware Stack#3
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| // Security middleware - Applied in order of execution | ||
| app.use(configureHelmet()); // Security headers (CSP, HSTS, X-Frame-Options) | ||
| app.use(configureCors()); // CORS with origin validation | ||
| app.use(generalRateLimiter); // Rate limiting for all endpoints | ||
| app.use(express.json()); // JSON body parser |
There was a problem hiding this comment.
Trust proxy before applying rate limiters
The new global generalRateLimiter counts requests by req.ip, but the app still uses Express’s default trust proxy = false. Architecture.md documents the backend sitting behind an Nginx reverse proxy, so every request will appear to come from the proxy’s IP and all clients will share the same bucket, causing 429s even under moderate multi-user traffic. Set app.set('trust proxy', true) (or use the forwarded header) before installing the rate limiters so each client is limited independently.
Useful? React with 👍 / 👎.
Summary
This PR addresses a critical security vulnerability by applying the existing security middleware stack that was previously defined but never used. The backend now enforces CORS origin validation, security headers, rate limiting, input sanitization, and request validation.
Changes
cors()withconfigureCors()for origin whitelist validationconfigureHelmet()for security headers (CSP, HSTS, X-Frame-Options)generalRateLimiterglobally to prevent API abusemissionRateLimiterto POST /api/missions endpointsanitizeInputmiddleware for XSS protectionvalidateContentTypeandvalidateRequestSizemiddlewarenotFoundHandleranderrorHandlerfor proper error handlingType of Change
Testing
Checklist
Related Issues
Addresses Feature #1 from FEATURE_OPPORTUNITIES.md - Priority Score: 3.0 ⭐