Skip to content

Commit a958c14

Browse files
committed
fix: isJustnContact url validation
Signed-off-by: Mouad BANI <mouad-mb@outlook.com>
1 parent 8f3669f commit a958c14

1 file changed

Lines changed: 15 additions & 6 deletions

File tree

  • services/apps/packages_worker/src/security-contacts

services/apps/packages_worker/src/security-contacts/reconcile.ts

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,27 @@ const PLACEHOLDER_EMAIL_DOMAINS = new Set([
3232
// project-specific contact, unlike an actual github.com/<owner>/<repo>/... URL.
3333
const GENERIC_URL_HOSTS = new Set(['docs.github.com', 'dependabot.com', 'www.dependabot.com'])
3434

35+
const HAS_SCHEME_RE = /^[a-z][a-z0-9+.-]*:\/\//i
36+
37+
// Some upstream sources (e.g. SECURITY-INSIGHTS {type:"url"} entries) don't enforce a scheme —
38+
// only add one to resolve the host, never mutate the stored contact value.
39+
function urlHost(value: string): string | null {
40+
const candidate = HAS_SCHEME_RE.test(value) ? value : `https://${value}`
41+
try {
42+
return new URL(candidate).hostname.toLowerCase()
43+
} catch {
44+
return null
45+
}
46+
}
47+
3548
function isJunkContact(c: RawContact): boolean {
3649
if (c.channel === 'email') {
3750
const domain = c.value.split('@')[1]?.toLowerCase().trim()
3851
return domain != null && PLACEHOLDER_EMAIL_DOMAINS.has(domain)
3952
}
4053
if (c.channel === 'url' || c.channel === 'web-form') {
41-
let host: string
42-
try {
43-
host = new URL(c.value).hostname.toLowerCase()
44-
} catch {
45-
return true
46-
}
54+
const host = urlHost(c.value)
55+
if (host == null) return true
4756
return GENERIC_URL_HOSTS.has(host) || host === 'localhost' || host.startsWith('127.')
4857
}
4958
return false

0 commit comments

Comments
 (0)