Skip to content

Commit b2da0d8

Browse files
authored
Merge pull request #9 from akabarki76/alert-autofix-2
Potential fix for code scanning alert no. 2: Incomplete URL substring sanitization
2 parents c895b24 + 6507c78 commit b2da0d8

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)