From a925ac56fa02b61417003ce5640d229f94ed192e Mon Sep 17 00:00:00 2001 From: tanzhenxin Date: Fri, 15 Aug 2025 17:10:20 +0800 Subject: [PATCH] Potential fix for code scanning alert no. 24: Incomplete URL substring sanitization Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com> --- packages/core/src/tools/web-fetch.ts | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/packages/core/src/tools/web-fetch.ts b/packages/core/src/tools/web-fetch.ts index dedff244..739745a5 100644 --- a/packages/core/src/tools/web-fetch.ts +++ b/packages/core/src/tools/web-fetch.ts @@ -174,10 +174,18 @@ ${textContent} // Perform GitHub URL conversion here to differentiate between user-provided // URL and the actual URL to be fetched. let url = params.url; - if (url.includes('github.com') && url.includes('/blob/')) { - url = url - .replace('github.com', 'raw.githubusercontent.com') - .replace('/blob/', '/'); + try { + const parsedUrl = new URL(url); + if ( + parsedUrl.hostname === 'github.com' && + parsedUrl.pathname.includes('/blob/') + ) { + url = url + .replace('github.com', 'raw.githubusercontent.com') + .replace('/blob/', '/'); + } + } catch (e) { + // If the URL is invalid, leave it unchanged (or handle as needed) } const confirmationDetails: ToolCallConfirmationDetails = {