fix: strip cf-connecting-ip header in forward_export_request#1824
fix: strip cf-connecting-ip header in forward_export_request#1824alexmojaki merged 1 commit intopydantic:mainfrom
cf-connecting-ip header in forward_export_request#1824Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
| 'trailer', | ||
| 'upgrade', | ||
| 'cookie', | ||
| 'cf-connecting-ip', | ||
| } |
There was a problem hiding this comment.
🚩 Other spoofable IP/proxy headers are not stripped
The PR adds cf-connecting-ip to the removal set, which is a good security fix. However, other headers commonly used for IP identification — such as x-forwarded-for, x-real-ip, true-client-ip, and cf-ipcountry — are also not stripped. A client could set these to spoof identity information forwarded to the upstream Logfire API. Whether this matters depends on how the Logfire backend uses these headers, but it may be worth considering stripping additional headers for defense in depth.
(Refers to lines 72-86)
Was this helpful? React with 👍 or 👎 to provide feedback.
|
Thanks! |
Summary
logfire_proxyforwardscf-connecting-ipto Logfire's API when the app runs behind Cloudflare, causing a 403 response. By addingcf-connecting-iptoheaders_to_removeinforward_export_requestthe issue disappears.Problem
When using
logfire_proxyto forward browser telemetry from an app deployed behind Cloudflare (e.g. Railway + Cloudflare as in my use case), Logfire's API returns 403 when trying to send telemetry from the browser like it is done like in the docs. Locally it works but in a server behind Cloudflare it adds acf-connecting-ipheader to the requests passed to the backend, andlogfire_proxyforwards it in the server-to-server request to Logfire's API which results in the 403. Claude says it raises a 403 because Logfire's server also sits behinds Cloudflare.Testing
Tested by injecting a bunch of production headers individually into the request locally before calling
logfire_proxy:cf-connecting-ipalonecf-connecting-ipv6alonecf-ipcountryalonecf-rayalonecf-visitoraloneThen I just removed the
cf-connecting-ipfrom the request object directly before calling the logfire_proxy (see below) and it also worked when deployed to Railway + CloudflareFix
It is a small issue but since (according to Claude inference) Logfire uses Cloudflare it is just a one-liner that can help all other users that also use Cloudflare, as it is not clear from the docs that it could fail thanks to this specific reason.
Environment
@pydantic/logfire-browservia esm.sh