Skip to content

Add security headers, CORS, rate limiting, and API authentication#5

Open
super3 wants to merge 1 commit intomainfrom
claude/secure-api-endpoints-0FSID
Open

Add security headers, CORS, rate limiting, and API authentication#5
super3 wants to merge 1 commit intomainfrom
claude/secure-api-endpoints-0FSID

Conversation

@super3
Copy link
Copy Markdown
Owner

@super3 super3 commented Apr 2, 2026

Summary

This PR enhances the security posture of the PadTask server by implementing multiple security layers: HTTP security headers via Helmet, configurable CORS restrictions, rate limiting on API endpoints, and optional Bearer token authentication.

Key Changes

  • Security Headers: Added Helmet middleware to set security headers (X-Content-Type-Options, X-Frame-Options, etc.)
  • CORS Configuration: Replaced open CORS policy with configurable origin restrictions via ALLOWED_ORIGINS environment variable; defaults to same-origin only
  • Rate Limiting: Implemented express-rate-limit on /api/ endpoints (100 requests per 15 minutes per IP)
  • API Authentication: Added optional Bearer token authentication via API_SECRET_KEY environment variable; when configured, all API requests require Authorization: Bearer <token> header
  • Test Coverage: Added comprehensive test suites for security headers, CORS behavior, and authentication scenarios
  • Documentation: Updated .env.example with new configuration options

Implementation Details

  • Authentication middleware is applied to /api/chat and /api/clear endpoints and gracefully skips validation when API_SECRET_KEY is not set
  • CORS origin validation uses a callback function to allow same-origin requests (no Origin header) while restricting cross-origin requests to explicitly allowed origins
  • Rate limiter state is reset between tests to ensure test isolation
  • All new dependencies (helmet, express-rate-limit) are production dependencies

https://claude.ai/code/session_01757fV1nPvDZ7rviGSuYwp7

- Add helmet middleware for security headers (CSP, X-Frame-Options, etc.)
- Add express-rate-limit (100 req/15min) on /api/ endpoints
- Lock CORS to ALLOWED_ORIGINS env var; only same-origin allowed by default
- Add Bearer token auth middleware on /api/chat and /api/clear (via API_SECRET_KEY env)
- Update .env.example with new config options
- Add tests for all security features (100% coverage maintained)

https://claude.ai/code/session_01757fV1nPvDZ7rviGSuYwp7
@railway-app
Copy link
Copy Markdown

railway-app bot commented Apr 2, 2026

🚅 Deployed to the padtask-pr-5 environment in padtask

Service Status Web Updated (UTC)
padtask ✅ Success (View Logs) Web Apr 2, 2026 at 3:08 pm

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.

2 participants