Skip to content

fix(http): use single hop trust proxy to prevent rate limit bypass#1492

Merged
ClemRz merged 1 commit into
developfrom
fix/trust-proxy-hop-count
Mar 9, 2026
Merged

fix(http): use single hop trust proxy to prevent rate limit bypass#1492
ClemRz merged 1 commit into
developfrom
fix/trust-proxy-hop-count

Conversation

@ClemRz
Copy link
Copy Markdown
Contributor

@ClemRz ClemRz commented Mar 9, 2026

🤔 What

  • Change trustProxy from true to 1 in config/env/production.js

🤷‍♂️ Why

express-rate-limit v7+ rejects trustProxy: true because it trusts all proxies unconditionally, allowing attackers to spoof X-Forwarded-For and bypass IP-based rate limiting (ERR_ERL_PERMISSIVE_TRUST_PROXY).

Setting it to 1 tells Express to trust exactly one proxy hop (the Azure App Service load balancer), which still resolves req.ip to the real client IP while preventing spoofing.

🔍 How

Single-line change: trustProxy: truetrustProxy: 1. Express interprets the number as "trust the nth hop from the front-facing proxy," which is the correct setting for Azure App Service's single LB architecture.

🧪 Testing

After deployment, verify:

  1. Logs show real client IPs (not 169.254.129.1)
  2. The ERR_ERL_PERMISSIVE_TRUST_PROXY validation error is gone
  3. Rate limiting still works correctly

📸 Previews

N/A

@ClemRz ClemRz requested review from bsoufflet and vmarseguerra March 9, 2026 16:24
@ClemRz ClemRz self-assigned this Mar 9, 2026
@ClemRz ClemRz merged commit 8def293 into develop Mar 9, 2026
3 checks passed
@ClemRz ClemRz deleted the fix/trust-proxy-hop-count branch March 9, 2026 16:29
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.

1 participant