Skip to content

fix(server): trim X-Real-IP in rate limit client key resolution - #231

Open
aymanmali wants to merge 1 commit into
CopilotKit:mainfrom
aymanmali:fix/rate-limit-real-ip-trim
Open

aymanmali wants to merge 1 commit into
CopilotKit:mainfrom
aymanmali:fix/rate-limit-real-ip-trim

Conversation

@aymanmali

Copy link
Copy Markdown

Summary

In resolveClientKey() (apps/server/src/rate-limit.ts), X-Forwarded-For was trimmed before checking truthiness, whereas X-Real-IP was used raw. As a result, a whitespace-only X-Real-IP header created a proxy: bucket instead of falling back to the connection address, and padded X-Real-IP values did not normalize to the same bucket as X-Forwarded-For.

Changes

  • Trimmed input.realIp in resolveClientKey() in apps/server/src/rate-limit.ts before checking non-emptiness.
  • Added a regression test in tests/rate-limit.test.ts verifying padded X-Real-IP trimming and whitespace-only fallback.

Verification

  • pnpm format
  • pnpm lint
  • pnpm typecheck
  • pnpm test (524/524 passed)

This branch has not been deployed

No deployments
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