Skip to content

Commit 1c71d76

Browse files
fix: properly sanitize github url
1 parent 03d556f commit 1c71d76

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

scripts/build-index.cjs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,17 @@ const MASTER_INDEX_VERSION = '0.1.0';
2020
* @returns {Promise<object|null>} Repository metadata or null if not available
2121
*/
2222
async function fetchGitHubMetadata(repoUrl) {
23-
if (!repoUrl?.includes('github.com')) {
23+
if (!repoUrl) {
2424
return null;
2525
}
2626

2727
try {
28+
// Parse and validate the URL to prevent substring injection attacks
29+
const url = new URL(repoUrl);
30+
if (url.hostname !== 'github.com' && url.hostname !== 'www.github.com') {
31+
return null;
32+
}
33+
2834
// Extract owner/repo from URL
2935
const match = new RegExp(/github\.com\/([^/]+)\/([^/]+)/).exec(repoUrl);
3036
if (!match) {

0 commit comments

Comments
 (0)