File tree Expand file tree Collapse file tree
services/apps/packages_worker/src/security-contacts Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -32,18 +32,27 @@ const PLACEHOLDER_EMAIL_DOMAINS = new Set([
3232// project-specific contact, unlike an actual github.com/<owner>/<repo>/... URL.
3333const GENERIC_URL_HOSTS = new Set ( [ 'docs.github.com' , 'dependabot.com' , 'www.dependabot.com' ] )
3434
35+ const HAS_SCHEME_RE = / ^ [ a - z ] [ a - z 0 - 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+
3548function 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
You can’t perform that action at this time.
0 commit comments