Conversation
Gates all /tasks routes behind x-api-key header. Key is read from API_KEY env var — skipped when unset (dev mode). Health endpoint remains public.
🩺 Dr. Concret.io — 🔴 Changes RequestedThis PR introduces API key authentication middleware for the Highlights
Findings (2)
Missing Coding StandardsThis repository has no coding standards files. Consider creating:
🩺 Dr. Concret.io · Model: gemini-2.5-flash · Tokens: 1810 in, 1226 out · Cost: ~$.0067 |
| const expectedKey = process.env.API_KEY; | ||
|
|
||
| if (!expectedKey) { | ||
| // Auth not configured — skip in development |
There was a problem hiding this comment.
🩺 [HIGH] security: Unsafe Authentication Bypass in Production
The if (!expectedKey) condition allows authentication to be completely bypassed if the API_KEY environment variable is not set. While intended for development, this is a critical security vulnerability if deployed to production without the variable configured, making all /tasks routes publicly accessible. Authentication should fail loudly in production if the key is missing.
Suggestion:
| // Auth not configured — skip in development | |
| if (!expectedKey) { | |
| if (process.env.NODE_ENV === 'production') { | |
| console.error('API_KEY environment variable is not set in production. Authentication is disabled.'); | |
| return res.status(500).json({ error: 'Server configuration error' }); | |
| } | |
| // Allow bypass in non-production environments for convenience | |
| return next(); | |
| } |
| } | ||
|
|
||
| if (!apiKey || apiKey !== expectedKey) { | ||
| return res.status(401).json({ error: 'Unauthorized' }); |
There was a problem hiding this comment.
🩺 [MEDIUM] security: Potential Timing Attack Vulnerability
The direct string comparison apiKey !== expectedKey could potentially be vulnerable to timing attacks, where an attacker might infer the API key character by character based on slight differences in response times. For sensitive comparisons like API keys, a constant-time string comparison function is recommended to mitigate this risk.
Adds x-api-key authentication to all task routes. Key is read from API_KEY env var, skipped when unset. Health endpoint stays public.