Skip to content

Commit 6d79702

Browse files
committed
Add support for DNS-rebinding attack protection in config.json and remote-server.ts
1 parent e7000f7 commit 6d79702

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

config/config.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
"TLS_CERT_PATH": "",
1414
"TLS_KEY_PASSPHRASE": "",
1515
"MCP_SERVER_CORS_ORIGINS": ["*"],
16+
"MCP_SERVER_DNS_REBINDING_PROTECTION_ALLOWED_HOSTS": [],
17+
"MCP_SERVER_DNS_REBINDING_PROTECTION_ALLOWED_ORIGINS": [],
1618
"SCOPES_SUPPORTED": ["mcp:call-tools"],
1719
"MCP_SERVER_CLIENT_ID": "",
1820
"MCP_SERVER_CLIENT_SECRET": "",

src/server-remote.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ const BACKEND_API_AUDIENCE = configData.BACKEND_API_AUDIENCE;
3838
const BACKEND_API_RESOURCE = configData.BACKEND_API_RESOURCE;
3939
const BACKEND_AUTH_TOKEN = () => getConfigData().BACKEND_AUTH_TOKEN;
4040
const MCP_SERVER_BASE_URL = configData.MCP_SERVER_BASE_URL;
41+
const MCP_SERVER_DNS_REBINDING_PROTECTION_ALLOWED_HOSTS =
42+
configData.MCP_SERVER_DNS_REBINDING_PROTECTION_ALLOWED_HOSTS || [];
43+
const MCP_SERVER_DNS_REBINDING_PROTECTION_ALLOWED_ORIGINS =
44+
configData.MCP_SERVER_DNS_REBINDING_PROTECTION_ALLOWED_ORIGINS || [];
4145
const AUTHZ_SERVER_BASE_URL = configData.AUTHZ_SERVER_BASE_URL;
4246
const SCOPES_SUPPORTED = configData.SCOPES_SUPPORTED;
4347
const MCP_SERVER_CLIENT_ID = configData.MCP_SERVER_CLIENT_ID;
@@ -286,19 +290,18 @@ const handleMcpRequest = async (req: express.Request, res: express.Response) =>
286290
// Reuse existing transport
287291
transport = getTransport(sessionId)!;
288292
} else if (!sessionId && isInitializeRequest(req.body)) {
293+
const enableDnsRebindingProtection =
294+
MCP_SERVER_DNS_REBINDING_PROTECTION_ALLOWED_HOSTS.length > 0;
289295
// New initialization request
290296
transport = new StreamableHTTPServerTransport({
291297
sessionIdGenerator: () => randomUUID(),
292298
onsessioninitialized: (sessionId) => {
293299
// Store the transport by session ID
294300
addSession(sessionId, transport);
295301
},
296-
// FIXME:
297-
// DNS rebinding protection is disabled by default for backwards compatibility. If you are running this server
298-
// locally, make sure to set:
299-
// enableDnsRebindingProtection: true,
300-
// allowedHosts: ['127.0.0.1'],
301-
// allowedOrigins: []
302+
enableDnsRebindingProtection: enableDnsRebindingProtection,
303+
allowedHosts: MCP_SERVER_DNS_REBINDING_PROTECTION_ALLOWED_HOSTS,
304+
allowedOrigins: MCP_SERVER_DNS_REBINDING_PROTECTION_ALLOWED_ORIGINS,
302305
});
303306

304307
// Clean up transport when closed

0 commit comments

Comments
 (0)