Skip to content

Commit e2d35a2

Browse files
authored
fix(core): Ensure ip address headers are stripped when lower case (#20484)
This was flagged by a claude security review and makes sense IMHO, we should make sure to also strip IP headers when they are lower case. While looking at that I noticed we have no tests at all for this rather critical thing 😬 so I added some here.
1 parent a548013 commit e2d35a2

2 files changed

Lines changed: 613 additions & 5 deletions

File tree

packages/core/src/integrations/requestdata.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -106,12 +106,16 @@ function extractNormalizedRequestData(
106106
delete (headers as { cookie?: string }).cookie;
107107
}
108108

109-
// Remove IP headers in case IP data should not be included in the event
109+
// Remove IP headers in case IP data should not be included in the event.
110+
// Match case-insensitively — same as getClientIPAddress — so lowercase keys are stripped too.
110111
if (!include.ip) {
111-
ipHeaderNames.forEach(ipHeaderName => {
112-
// eslint-disable-next-line @typescript-eslint/no-dynamic-delete
113-
delete (headers as Record<string, unknown>)[ipHeaderName];
114-
});
112+
const ipHeaderNamesLower = new Set(ipHeaderNames.map(name => name.toLowerCase()));
113+
for (const key of Object.keys(headers)) {
114+
if (ipHeaderNamesLower.has(key.toLowerCase())) {
115+
// eslint-disable-next-line @typescript-eslint/no-dynamic-delete
116+
delete (headers as Record<string, unknown>)[key];
117+
}
118+
}
115119
}
116120
}
117121

0 commit comments

Comments
 (0)