Skip to content

test: cover rate-limit client IP header resolution - #37

Draft
cursor[bot] wants to merge 1 commit into
mainfrom
cursor/test-coverage-automation-7bfa
Draft

cursor[bot] wants to merge 1 commit into
mainfrom
cursor/test-coverage-automation-7bfa

Conversation

@cursor

@cursor cursor Bot commented Jul 21, 2026

Copy link
Copy Markdown

Description

Adds unit coverage for getRateLimitClientId, which resolves the Upstash rate-limit client identifier from trusted vs spoofable headers.

Risky behavior now covered

  • Pinned RATE_LIMIT_CLIENT_IP_HEADER wins over x-forwarded-for
  • Comma-split / trim of pinned and forwarded headers
  • Fallback chain: pinned → x-forwarded-for → x-real-ip → anonymous

Test files added/updated

  • tests/lib/rate-limit-client-ip.test.ts (new)

Why these tests materially reduce regression risk

Incorrect client-id resolution lets callers bypass or share rate-limit buckets. This is a security-sensitive edge path with no prior unit coverage on main.

How Has This Been Tested?

  • pnpm exec vitest run tests/lib/rate-limit-client-ip.test.ts (6 passed)
Open in Web View Automation 

Lock pinned trusted-header preference, comma-split parsing, and
anonymous/x-forwarded-for/x-real-ip fallbacks for Upstash client IDs.

Co-authored-by: esadrianno <esadrianno@gmail.com>

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