Skip to content

Commit 0345463

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. Changes: - Add HOST environment variable support to client (prod mode) - Configure Vite dev server to bind to localhost by default - Update browser auto-open URLs to use actual host instead of hardcoded 127.0.0.1 - Fix missing cancelled parameter in startProdClient function 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent 698d245 commit 0345463

File tree

2 files changed

+15
-11
lines changed

2 files changed

+15
-11
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: 11 additions & 8 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(() => {
@@ -139,7 +141,7 @@ async function startDevClient(clientOptions) {
139141
}
140142

141143
async function startProdClient(clientOptions) {
142-
const { CLIENT_PORT, authDisabled, sessionToken, abort } = clientOptions;
144+
const { CLIENT_PORT, authDisabled, sessionToken, abort, cancelled } = clientOptions;
143145
const inspectorClientPath = resolve(
144146
__dirname,
145147
"../..",
@@ -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)