Skip to content

Commit dd7760b

Browse files
authored
chore: warn about insecure httpHost usage - MCP-184 (#541)
1 parent 008ad6b commit dd7760b

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

src/common/logger.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ export const LogId = {
5656
streamableHttpTransportCloseFailure: mongoLogId(1_006_006),
5757
streamableHttpTransportKeepAliveFailure: mongoLogId(1_006_007),
5858
streamableHttpTransportKeepAlive: mongoLogId(1_006_008),
59+
streamableHttpTransportHttpHostWarning: mongoLogId(1_006_009),
5960

6061
exportCleanupError: mongoLogId(1_007_001),
6162
exportCreationError: mongoLogId(1_007_002),

src/transports/streamableHttp.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,15 @@ export class StreamableHttpRunner extends TransportRunnerBase {
205205
message: `Server started on ${this.serverAddress}`,
206206
noRedaction: true,
207207
});
208+
209+
if (this.shouldWarnAboutHttpHost(this.userConfig.httpHost)) {
210+
this.logger.warning({
211+
id: LogId.streamableHttpTransportHttpHostWarning,
212+
context: "streamableHttpTransport",
213+
message: `Binding to ${this.userConfig.httpHost} can expose the MCP Server to the entire local network, which allows other devices on the same network to potentially access the MCP Server. This is a security risk and could allow unauthorized access to your database context.`,
214+
noRedaction: true,
215+
});
216+
}
208217
}
209218

210219
async closeTransport(): Promise<void> {
@@ -243,4 +252,10 @@ export class StreamableHttpRunner extends TransportRunnerBase {
243252
});
244253
};
245254
}
255+
256+
private shouldWarnAboutHttpHost(httpHost: string): boolean {
257+
const host = httpHost.trim();
258+
const safeHosts = new Set(["127.0.0.1", "localhost", "::1"]);
259+
return host === "0.0.0.0" || host === "::" || (!safeHosts.has(host) && host !== "");
260+
}
246261
}

0 commit comments

Comments
 (0)