Skip to content

fix(server): restrict trusted proxy headers - #16

Merged
NateIsern merged 1 commit into
mainfrom
codex/fix-x-forwarded-for-rate-limit-bypass
Jun 25, 2026
Merged

fix(server): restrict trusted proxy headers#16
NateIsern merged 1 commit into
mainfrom
codex/fix-x-forwarded-for-rate-limit-bypass

Conversation

@NateIsern

Copy link
Copy Markdown
Member

Motivation

  • A previous change unconditionally enabled one-hop trust proxy, allowing direct clients to spoof X-Forwarded-For and evade per-IP HTTP and WebSocket rate limits.
  • The server must treat forwarded headers as authoritative only when the TCP peer is a known, configured reverse proxy so limits remain effective when the backend is directly reachable.

Description

  • Replace the hard-coded trust proxy = 1 with an explicit TRUSTED_PROXY_CIDRS allowlist parsed from process.env.TRUSTED_PROXY_CIDRS and used as the Express trust predicate via app.set('trust proxy', isTrustedProxy).
  • Add robust IP normalization and CIDR parsing/bitmask logic (IPv4 and IPv6) to build TRUSTED_PROXY_RANGES and the isTrustedProxy check.
  • Update WebSocket client IP resolution in resolveClientIp to consult the same isTrustedProxy policy and ignore X-Forwarded-For unless the TCP peer is a trusted proxy.
  • Document the new TRUSTED_PROXY_CIDRS setting in .env.example and add the necessary net import in server/index.ts.

Testing

  • Ran TypeScript checks with npx tsc -p server/tsconfig.json --noEmit, which completed successfully.
  • Executed the test suite with npm test, which completed successfully (all tests passed).
  • An alternate npm test -- --runInBand invocation failed because Vitest does not accept the Jest --runInBand flag, but the suite was re-run with npm test and passed.

Codex Task

@NateIsern
NateIsern force-pushed the codex/fix-x-forwarded-for-rate-limit-bypass branch from 36c9af3 to f92d7b0 Compare June 25, 2026 19:19
@NateIsern
NateIsern merged commit ee6a374 into main Jun 25, 2026
1 check passed
@NateIsern
NateIsern deleted the codex/fix-x-forwarded-for-rate-limit-bypass branch June 25, 2026 19:22
NateIsern added a commit that referenced this pull request Jun 25, 2026
Document the merged hardening PRs and bump version:
- restrict trusted proxy headers via TRUSTED_PROXY_CIDRS (#16)
- redact public peer topology from /api/peers (#17)
- single bounded price-history query (no findOne fan-out) (#15)

Also note the TRUSTED_PROXY_CIDRS deployment requirement in the README.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
NateIsern added a commit that referenced this pull request Jun 25, 2026
Document the merged hardening PRs and bump version:
- sanitize /api/validate-address response + input (#18)
- limit /api/network-info to public fields (#19)
- cap WebSocket frame size via maxPayload (#20)

Note: #20's TCP-peer WS-IP change was dropped on merge (would break the per-IP
WS cap behind the proxy); #16's trusted-proxy resolution is kept.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant