📌 Description
middleware/rateLimiter.ts keys buckets per client IP. If the service runs behind a load balancer, the effective client IP typically comes from X-Forwarded-For, which is trivially spoofable unless the app validates how many proxy hops it trusts and strips/ignores attacker-supplied prefix entries.
🧩 Requirements and context
- Add a
trustProxyDepth (or reuse Express's trust proxy setting) so only the last N hops of X-Forwarded-For are honored.
- Document in
config.ts/README how to configure this correctly for the deployment topology.
- Default to a safe, conservative setting (e.g. direct connection IP only) when unconfigured.
🛠️ Suggested execution
- Extend
RateLimitOptions in middleware/rateLimiter.ts and loadConfig() in src/config.ts with the new setting.
- Add tests in
middleware/rateLimiter.test.ts simulating spoofed X-Forwarded-For headers with and without the trust setting.
- Update README's rate-limiting section with a deployment note.
✅ Acceptance criteria
🔒 Security notes
Closes a rate-limit bypass vector where a client behind an untrusted proxy chain can forge its apparent IP to reset its own bucket.
📋 Guidelines
- Minimum 95% test coverage
- Clear documentation
- Timeframe: 96 hours
📌 Description
middleware/rateLimiter.tskeys buckets per client IP. If the service runs behind a load balancer, the effective client IP typically comes fromX-Forwarded-For, which is trivially spoofable unless the app validates how many proxy hops it trusts and strips/ignores attacker-supplied prefix entries.🧩 Requirements and context
trustProxyDepth(or reuse Express'strust proxysetting) so only the last N hops ofX-Forwarded-Forare honored.config.ts/README how to configure this correctly for the deployment topology.🛠️ Suggested execution
RateLimitOptionsinmiddleware/rateLimiter.tsandloadConfig()insrc/config.tswith the new setting.middleware/rateLimiter.test.tssimulating spoofedX-Forwarded-Forheaders with and without the trust setting.✅ Acceptance criteria
X-Forwarded-Forvalues beyond the trusted depth don't bypass per-client limits.🔒 Security notes
Closes a rate-limit bypass vector where a client behind an untrusted proxy chain can forge its apparent IP to reset its own bucket.
📋 Guidelines