Skip to content

Commit 25e0c93

Browse files
authoredMay 18, 2023
[proxy] Ensure that socket.remoteAddress is a string (#178)
It's possible that this value is `undefined`, so skip adding it to the `x-forwarded-for` header in that case.
1 parent 65baebf commit 25e0c93

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed
 

‎.changeset/shiny-badgers-obey.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"proxy": patch
3+
---
4+
5+
Ensure that `socket.remoteAddress` is a string

‎packages/proxy/src/proxy.ts

+9-7
Original file line numberDiff line numberDiff line change
@@ -116,12 +116,14 @@ async function onrequest(
116116
// append to existing "X-Forwarded-For" header
117117
// http://en.wikipedia.org/wiki/X-Forwarded-For
118118
hasXForwardedFor = true;
119-
value += ', ' + socket.remoteAddress;
120-
debug.proxyRequest(
121-
'appending to existing "%s" header: "%s"',
122-
key,
123-
value
124-
);
119+
if (typeof socket.remoteAddress === 'string') {
120+
value += ', ' + socket.remoteAddress;
121+
debug.proxyRequest(
122+
'appending to existing "%s" header: "%s"',
123+
key,
124+
value
125+
);
126+
}
125127
}
126128

127129
if (!hasVia && 'via' === keyLower) {
@@ -151,7 +153,7 @@ async function onrequest(
151153

152154
// add "X-Forwarded-For" header if it's still not here by now
153155
// http://en.wikipedia.org/wiki/X-Forwarded-For
154-
if (!hasXForwardedFor) {
156+
if (!hasXForwardedFor && typeof socket.remoteAddress === 'string') {
155157
headers['X-Forwarded-For'] = socket.remoteAddress;
156158
debug.proxyRequest(
157159
'adding new "X-Forwarded-For" header: "%s"',

1 commit comments

Comments
 (1)

vercel[bot] commented on May 18, 2023

@vercel[bot]
Please sign in to comment.