Skip to content

Commit 6507c78

Browse files
Potential fix for code scanning alert no. 2: Incomplete URL substring sanitization
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com> Signed-off-by: Mustapha BARKI <code4yo@gmail.com>
1 parent c895b24 commit 6507c78

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

packages/core/src/tools/web-fetch.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -188,10 +188,16 @@ ${textContent}
188188
// Perform GitHub URL conversion here to differentiate between user-provided
189189
// URL and the actual URL to be fetched.
190190
const urls = extractUrls(params.prompt).map((url) => {
191-
if (url.includes('github.com') && url.includes('/blob/')) {
192-
return url
193-
.replace('github.com', 'raw.githubusercontent.com')
194-
.replace('/blob/', '/');
191+
try {
192+
const parsedUrl = new URL(url);
193+
if (parsedUrl.hostname === 'github.com' && url.includes('/blob/')) {
194+
return url
195+
.replace('github.com', 'raw.githubusercontent.com')
196+
.replace('/blob/', '/');
197+
}
198+
} catch (e) {
199+
// If URL parsing fails, ignore this URL
200+
console.error(`Invalid URL encountered: ${url}`);
195201
}
196202
return url;
197203
});

0 commit comments

Comments
 (0)