Skip to content

Commit 08c2f49

Browse files
fix: Bind client to localhost by default to prevent DNS rebinding attacks
Complete the security hardening started in e8e9909 by also binding the client to localhost only. Previously only the server was protected while the client remained exposed to the network, allowing attackers to access the server through the client as a proxy. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent 698d245 commit 08c2f49

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

client/bin/client.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,18 +40,19 @@ const server = http.createServer((request, response) => {
4040
});
4141

4242
const port = process.env.PORT || 6274;
43+
const host = process.env.HOST || "127.0.0.1";
4344
server.on("listening", () => {
4445
console.log(
45-
`🔍 MCP Inspector is up and running at http://127.0.0.1:${port} 🚀`,
46+
`🔍 MCP Inspector is up and running at http://${host}:${port} 🚀`,
4647
);
4748
});
4849
server.on("error", (err) => {
4950
if (err.message.includes(`EADDRINUSE`)) {
5051
console.error(
51-
`❌ MCP Inspector PORT IS IN USE at http://127.0.0.1:${port} ❌ `,
52+
`❌ MCP Inspector PORT IS IN USE at http://${host}:${port} ❌ `,
5253
);
5354
} else {
5455
throw err;
5556
}
5657
});
57-
server.listen(port);
58+
server.listen(port, host);

client/bin/start.js

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,8 @@ async function startDevClient(clientOptions) {
102102
const { CLIENT_PORT, authDisabled, sessionToken, abort, cancelled } =
103103
clientOptions;
104104
const clientCommand = "npx";
105-
const clientArgs = ["vite", "--port", CLIENT_PORT];
105+
const host = process.env.HOST || "127.0.0.1";
106+
const clientArgs = ["vite", "--port", CLIENT_PORT, "--host", host];
106107

107108
const client = spawn(clientCommand, clientArgs, {
108109
cwd: resolve(__dirname, ".."),
@@ -113,9 +114,10 @@ async function startDevClient(clientOptions) {
113114

114115
// Auto-open browser after vite starts
115116
if (process.env.MCP_AUTO_OPEN_ENABLED !== "false") {
117+
const clientHost = process.env.HOST || "127.0.0.1";
116118
const url = authDisabled
117-
? `http://127.0.0.1:${CLIENT_PORT}`
118-
: `http://127.0.0.1:${CLIENT_PORT}/?MCP_PROXY_AUTH_TOKEN=${sessionToken}`;
119+
? `http://${clientHost}:${CLIENT_PORT}`
120+
: `http://${clientHost}:${CLIENT_PORT}/?MCP_PROXY_AUTH_TOKEN=${sessionToken}`;
119121

120122
// Give vite time to start before opening browser
121123
setTimeout(() => {
@@ -148,11 +150,12 @@ async function startProdClient(clientOptions) {
148150
"client.js",
149151
);
150152

151-
// Auto-open browser with token
152-
if (process.env.MCP_AUTO_OPEN_ENABLED !== "false") {
153+
// Only auto-open browser if not cancelled
154+
if (process.env.MCP_AUTO_OPEN_ENABLED !== "false" && !cancelled) {
155+
const clientHost = process.env.HOST || "127.0.0.1";
153156
const url = authDisabled
154-
? `http://127.0.0.1:${CLIENT_PORT}`
155-
: `http://127.0.0.1:${CLIENT_PORT}/?MCP_PROXY_AUTH_TOKEN=${sessionToken}`;
157+
? `http://${clientHost}:${CLIENT_PORT}`
158+
: `http://${clientHost}:${CLIENT_PORT}/?MCP_PROXY_AUTH_TOKEN=${sessionToken}`;
156159
open(url);
157160
}
158161

0 commit comments

Comments
 (0)