Skip to content

Commit 924992c

Browse files
fix: properly sanitize github url (#6)
1 parent 03d556f commit 924992c

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

scripts/build-index.cjs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
const fs = require('node:fs');
88
const path = require('node:path');
9+
const { URL } = require('node:url');
910
const { glob } = require('glob');
1011

1112
// Version constants
@@ -20,11 +21,17 @@ const MASTER_INDEX_VERSION = '0.1.0';
2021
* @returns {Promise<object|null>} Repository metadata or null if not available
2122
*/
2223
async function fetchGitHubMetadata(repoUrl) {
23-
if (!repoUrl?.includes('github.com')) {
24+
if (!repoUrl) {
2425
return null;
2526
}
2627

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

0 commit comments

Comments
 (0)