Skip to content

Commit d27047c

Browse files
fix: incomplete URL substring sanitization (#206)
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
1 parent 00f6809 commit d27047c

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/utils/index.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,18 @@ const logger = pinoInit({
3434
level: process.env.NODE_ENV === 'test' ? 'silent' : 'info'
3535
})
3636

37-
const validateGithubUrl = (url) => isURL(url, { protocols: ['https'], require_protocol: true }) && url.includes('github.com')
37+
const validateGithubUrl = (url) => {
38+
if (!isURL(url, { protocols: ['https'], require_protocol: true })) {
39+
return false
40+
}
41+
try {
42+
const parsedUrl = new URL(url)
43+
const allowedHosts = ['github.com', 'www.github.com']
44+
return allowedHosts.includes(parsedUrl.host)
45+
} catch (error) {
46+
return false
47+
}
48+
}
3849

3950
const ensureGithubToken = () => {
4051
if (!process.env.GITHUB_TOKEN) {

0 commit comments

Comments
 (0)