-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
fix(core): Find the correct IP address regardless their case #18880
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
| for (const key of Object.keys(headers)) { | ||
| lowerCaseHeaders[key.toLowerCase()] = headers[key]; | ||
| } | ||
|
|
||
| // This will end up being Array<string | string[] | undefined | null> because of the various possible values a header | ||
| // can take | ||
| const headerValues = ipHeaderNames.map((headerName: string) => { | ||
| const rawValue = headers[headerName]; | ||
| const rawValue = lowerCaseHeaders[headerName.toLowerCase()]; | ||
| const value = Array.isArray(rawValue) ? rawValue.join(';') : rawValue; | ||
|
|
||
| if (headerName === 'Forwarded') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: The new case-insensitive IP header reading is not matched by the deletion logic, which remains case-sensitive, potentially leaking IP headers when PII stripping is enabled.
Severity: CRITICAL
Suggested Fix
Modify the header deletion logic in extractNormalizedRequestData() to be case-insensitive. This can be achieved by iterating over the actual request headers, converting each to lowercase, and checking if it exists in a pre-computed set of lowercase IP header names before deletion. This ensures symmetry between reading and removing IP-related headers.
Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.
Location: packages/core/src/vendor/getIpAddress.ts#L52-L69
Potential issue: The pull request updates `getClientIPAddress()` to read IP-related
headers in a case-insensitive manner. However, the corresponding logic in
`extractNormalizedRequestData()` for removing these headers when `sendDefaultPii` is
`false` remains case-sensitive. It iterates through `ipHeaderNames` and performs an
exact-match deletion. This creates a situation where a header like `Cf-Connecting-Ip`
will be correctly identified as containing an IP address but will not be deleted if PII
stripping is enabled. This results in the unintended leakage of IP address information
in events.
Did we get this right? 👍 / 👎 to inform future reviews.
size-limit report 📦
|
node-overhead report 🧳Note: This is a synthetic benchmark with a minimal express app and does not necessarily reflect the real-world performance impact in an application.
|
closes FE-681
It seems that in some cases the headers do have a different casing. E.g. in Cloudflare Workers the
[CF-Connecting-IP](https://developers.cloudflare.com/fundamentals/reference/http-headers/#cf-connecting-ip)is actually send asCf-Connecting-Ip.According to RFC7540 8.1.2 the headers are case-insensitive, but for HTTP2 they must be lowercase. So theoretically this would fix also HTTP2 lower case headers