Skip to content

Commit

Permalink
[wrangler] fix: listen on loopback for wrangler dev port check and login
Browse files Browse the repository at this point in the history
The `wrangler dev` port availability check triggers a firewall prompt on
macOS while it briefly opens and closes the listener. The OAuth callback
server from `wrangler login` has the same issue.

Fix both cases by listening on the loopback address only.

Relates to cloudflare#4430
  • Loading branch information
Lekensteyn committed Jan 24, 2024
1 parent d031e75 commit fe12800
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
10 changes: 10 additions & 0 deletions .changeset/smart-owls-jog.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
"wrangler": patch
---

fix: listen on loopback for wrangler dev port check and login

Avoid listening on the wildcard address to reduce the attacker's surface and
avoid firewall prompts on macOS.

Relates to #4430.
2 changes: 1 addition & 1 deletion packages/wrangler/src/dev/proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -686,7 +686,7 @@ export async function waitForPortToBeAvailable(
doReject(err);
}
});
server.listen(port, () =>
server.listen(port, "localhost", () =>
terminator
.terminate()
.then(doResolve, () =>
Expand Down
2 changes: 1 addition & 1 deletion packages/wrangler/src/user/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1014,7 +1014,7 @@ export async function login(
}
});

server.listen(8976);
server.listen(8976, "localhost");
});
if (props?.browser) {
logger.log(`Opening a link in your default browser: ${urlToOpen}`);
Expand Down

0 comments on commit fe12800

Please sign in to comment.