Skip to content

OpenPanel is an open-source web and product analytics platform, an open-source alternative to Mixpanel with optional self-hosting.

fix: test re-order ip headers (since we're behind orange cloud now)

Carl-Gerhard Lindesvärda63b944f83b5
diff --git a/packages/common/server/get-client-ip.ts b/packages/common/server/get-client-ip.ts
index f564004da..b5edadc76 100644
--- a/packages/common/server/get-client-ip.ts
+++ b/packages/common/server/get-client-ip.ts
@@ -5,11 +5,16 @@
* Example: IP_HEADER_ORDER="cf-connecting-ip,x-real-ip,x-forwarded-for"
*/
+// Order matters: client-forwarded headers (set explicitly by SDKs/upstream
+// servers) must come before infrastructure headers like `cf-connecting-ip`.
+// Otherwise, when our API sits behind Cloudflare (orange cloud), Cloudflare
+// rewrites `cf-connecting-ip` to the SDK server's IP — losing the original
+// end-user IP that the SDK forwarded in `x-client-ip` / `openpanel-client-ip`.
export const DEFAULT_IP_HEADER_ORDER = [
'openpanel-client-ip',
- 'cf-connecting-ip',
'true-client-ip',
'x-client-ip',
+ 'cf-connecting-ip',
'x-forwarded-for',
'x-real-ip',
'fastly-client-ip',