Skip to content

Commit

Permalink
[proxy] Ensure that socket.remoteAddress is a string (#178)
Browse files Browse the repository at this point in the history
It's possible that this value is `undefined`, so skip adding it to the
`x-forwarded-for` header in that case.
  • Loading branch information
TooTallNate authored May 18, 2023
1 parent 65baebf commit 25e0c93
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .changeset/shiny-badgers-obey.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"proxy": patch
---

Ensure that `socket.remoteAddress` is a string
16 changes: 9 additions & 7 deletions packages/proxy/src/proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,14 @@ async function onrequest(
// append to existing "X-Forwarded-For" header
// http://en.wikipedia.org/wiki/X-Forwarded-For
hasXForwardedFor = true;
value += ', ' + socket.remoteAddress;
debug.proxyRequest(
'appending to existing "%s" header: "%s"',
key,
value
);
if (typeof socket.remoteAddress === 'string') {
value += ', ' + socket.remoteAddress;
debug.proxyRequest(
'appending to existing "%s" header: "%s"',
key,
value
);
}
}

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

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

1 comment on commit 25e0c93

@vercel
Copy link

@vercel vercel bot commented on 25e0c93 May 18, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

proxy-agents – ./

proxy-agents.vercel.app
proxy-agents-git-main-tootallnate.vercel.app
proxy-agents-tootallnate.vercel.app

Please sign in to comment.