Skip to content

fix: address trust proxy bypass and noisy 404s#507

Merged
marcoscaceres merged 2 commits into
mainfrom
worktree-fix-trust-proxy
Apr 28, 2026
Merged

fix: address trust proxy bypass and noisy 404s#507
marcoscaceres merged 2 commits into
mainfrom
worktree-fix-trust-proxy

Conversation

@marcoscaceres

@marcoscaceres marcoscaceres commented Apr 28, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Trust proxy: express-rate-limit v8.4+ throws ERR_ERL_PERMISSIVE_TRUST_PROXY because app.enable("trust proxy") sets it to true, allowing anyone to spoof X-Forwarded-For and bypass rate limiting. The production proxy chain is Client → Cloudflare → nginx → Express (PM2) (2 hops), so this changes trust proxy from true to 2.
  • Static files: Adds robots.txt and favicon.ico to static/. These two paths account for ~100 of the last 1000 error log entries from legitimate crawlers and browsers. The favicon is generated from the existing respec-logo-square.png at 32x32.

Test plan

  • pnpm build passes
  • pnpm test — 40 specs, 0 failures
  • Deploy and verify the ValidationError no longer appears in server logs
  • Verify req.ip / :remote-addr still logs real client IPs (not proxy IPs)
  • Verify /robots.txt and /favicon.ico return 200

express-rate-limit v8.4+ rejects `trust proxy = true` because it allows
anyone to spoof X-Forwarded-For and bypass rate limiting
(ERR_ERL_PERMISSIVE_TRUST_PROXY). Setting it to 2 trusts exactly the two
known proxy hops (Cloudflare → nginx → Express) while still resolving
the correct client IP for logging and rate limiting.
@marcoscaceres
marcoscaceres merged commit 935166f into main Apr 28, 2026
2 checks passed
@marcoscaceres
marcoscaceres deleted the worktree-fix-trust-proxy branch April 28, 2026 12:28
@marcoscaceres marcoscaceres changed the title fix: set trust proxy to 2 for Cloudflare + nginx chain fix: address trust proxy bypass and noisy 404s Apr 28, 2026
marcoscaceres added a commit that referenced this pull request May 4, 2026
express-rate-limit v8.4+ rejects `trust proxy = true` because it allows
anyone to spoof X-Forwarded-For and bypass rate limiting
(ERR_ERL_PERMISSIVE_TRUST_PROXY). Setting it to 2 trusts exactly the two
known proxy hops (Cloudflare → nginx → Express) while still resolving
the correct client IP for logging and rate limiting.
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