Skip to content

Commit 0aa1a8f

Browse files
committed
fixup! feat(nextjs): Add @sentry/nextjs/cloudflare
1 parent d24902e commit 0aa1a8f

2 files changed

Lines changed: 6 additions & 2 deletions

File tree

‎packages/core/src/utils/clientIPAddress.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ const IP_HEADER_NAMES = new Set(ipHeaderNames.map(name => name.toLowerCase()));
99
* normalized first. Some proxies (for example Azure App Service) add the client port,
1010
* and RFC 7239 allows a quoted `Forwarded` value and any case for `for=`.
1111
*/
12-
export function getClientIPAddress(headers: { [key: string]: string | string[] | undefined }): string | null {
12+
export function getClientIPAddress(headers: { [key: string]: string | string[] | null | undefined }): string | null {
1313
const normalized: { [key: string]: string } = {};
1414

1515
for (const [key, value] of Object.entries(headers)) {
1616
const name = key.toLowerCase();
17-
if (value === undefined || !IP_HEADER_NAMES.has(name)) {
17+
if (value == null || !IP_HEADER_NAMES.has(name)) {
1818
continue;
1919
}
2020

‎packages/core/test/lib/utils/clientIPAddress.test.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ describe('getClientIPAddress', () => {
3131
expect(getClientIPAddress({ 'x-forwarded-for': ['unknown', '203.0.113.7:4711'] })).toBe('203.0.113.7');
3232
});
3333

34+
it('skips headers whose value is null', () => {
35+
expect(getClientIPAddress({ 'x-forwarded-for': null, 'x-real-ip': '198.51.100.1' })).toBe('198.51.100.1');
36+
});
37+
3438
it('keeps the header priority order', () => {
3539
expect(getClientIPAddress({ 'X-Real-IP': '198.51.100.1', 'X-Forwarded-For': '203.0.113.7:4711' })).toBe(
3640
'203.0.113.7',

0 commit comments

Comments
 (0)