Add support for Cloudflare cf-connecting-ip header#1614
Conversation
Add Cloudflare's cf-connecting-ip as the highest priority header when resolving client IP addresses, ahead of x-forwarded-for and x-real-ip. https://claude.ai/code/session_01GSXb76ipr99cDh7zBnavAu
|
🚅 Deployed to the simon.dev-pr-1614 environment in simon.dev
|
|
Claude finished @simonkberg's task in 52s —— View job Code Review
The change is minimal, focused, and correct. A single line addition in Implementation ( The priority chain is clean and idiomatic: ip:
headersList.get("cf-connecting-ip") ??
headersList.get("x-forwarded-for")?.split(",")[0] ??
headersList.get("x-real-ip") ??
undefined,
One security note worth keeping in mind: Tests ( The two new tests cover exactly what they need to:
The existing tests for No issues to flag. LGTM. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1614 +/- ##
=======================================
Coverage 97.81% 97.81%
=======================================
Files 49 49
Lines 916 916
Branches 161 161
=======================================
Hits 896 896
Misses 8 8
Partials 12 12 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Summary
Updated the IP address detection logic to prioritize the Cloudflare
cf-connecting-ipheader over other IP headers, with corresponding test coverage.Key Changes
identifiers()function to checkcf-connecting-ipheader first before falling back tox-forwarded-forandx-real-ipcf-connecting-ipheadercf-connecting-iptakes precedence when multiple IP headers are presentImplementation Details
The IP detection now follows this priority order:
cf-connecting-ip(Cloudflare)x-forwarded-for(takes first value from comma-separated list)x-real-ipundefined(fallback)This change ensures that when running behind Cloudflare, the actual client IP is correctly identified from Cloudflare's header rather than potentially stale forwarded headers.
https://claude.ai/code/session_01GSXb76ipr99cDh7zBnavAu