From 978b6ccaeaa6ca561e6f1f07874d09b02d754f98 Mon Sep 17 00:00:00 2001 From: Max Isbey <224885523+maxisbey@users.noreply.github.com> Date: Tue, 24 Feb 2026 14:34:46 +0000 Subject: [PATCH] fix: prevent command injection in example URL opening --- src/examples/client/elicitationUrlExample.ts | 20 +++----------------- src/examples/client/simpleOAuthClient.ts | 20 +------------------- 2 files changed, 4 insertions(+), 36 deletions(-) diff --git a/src/examples/client/elicitationUrlExample.ts b/src/examples/client/elicitationUrlExample.ts index b57927e3f..5e31fdaa7 100644 --- a/src/examples/client/elicitationUrlExample.ts +++ b/src/examples/client/elicitationUrlExample.ts @@ -25,7 +25,6 @@ import { } from '../../types.js'; import { getDisplayName } from '../../shared/metadataUtils.js'; import { OAuthClientMetadata } from '../../shared/auth.js'; -import { exec } from 'node:child_process'; import { InMemoryOAuthClientProvider } from './simpleOAuthClientProvider.js'; import { UnauthorizedError } from '../../client/auth.js'; import { createServer } from 'node:http'; @@ -45,8 +44,7 @@ const clientMetadata: OAuthClientMetadata = { scope: 'mcp:tools' }; oauthProvider = new InMemoryOAuthClientProvider(OAUTH_CALLBACK_URL, clientMetadata, (redirectUrl: URL) => { - console.log(`🌐 Opening browser for OAuth redirect: ${redirectUrl.toString()}`); - openBrowser(redirectUrl.toString()); + console.log(`\nšŸ”— Please open this URL in your browser to authorize:\n ${redirectUrl.toString()}`); }); // Create readline interface for user input @@ -259,17 +257,6 @@ async function elicitationLoop(): Promise { } } -async function openBrowser(url: string): Promise { - const command = `open "${url}"`; - - exec(command, error => { - if (error) { - console.error(`Failed to open browser: ${error.message}`); - console.log(`Please manually open: ${url}`); - } - }); -} - /** * Enqueues an elicitation request and returns the result. * @@ -402,9 +389,8 @@ async function handleURLElicitation(params: ElicitRequestURLParams): Promise { - console.log(`🌐 Opening browser for authorization: ${url}`); - - const command = `open "${url}"`; - - exec(command, error => { - if (error) { - console.error(`Failed to open browser: ${error.message}`); - console.log(`Please manually open: ${url}`); - } - }); - } /** * Example OAuth callback handler - in production, use a more robust approach * for handling callbacks and storing tokens @@ -166,9 +150,7 @@ class InteractiveOAuthClient { CALLBACK_URL, clientMetadata, (redirectUrl: URL) => { - console.log(`šŸ“Œ OAuth redirect handler called - opening browser`); - console.log(`Opening browser to: ${redirectUrl.toString()}`); - this.openBrowser(redirectUrl.toString()); + console.log(`\nšŸ”— Please open this URL in your browser to authorize:\n ${redirectUrl.toString()}`); }, this.clientMetadataUrl );