64
return undefined;
65
}
67
>
// Support wildcard domain patterns like "*.example.com".
68
>
const hasWildcardPrefix = stripped.startsWith('*.');
69
const host = hasWildcardPrefix ? stripped.slice(2) : stripped;
70
if (!host) {
71
return undefined;
72
}
74
>
// Validate that the host part only contains valid hostname characters.
75
>
if (!/^[a-z0-9.-]+$/.test(host)) {
76
return undefined;
77
}
79
>
// Disallow patterns that look like file names with common extensions, as these are unlikely
80
>
// to be intended as network domains and may be false positives from the regex.
81
>
if (!fromUrl) {
82
const lastLabel = host.slice(host.lastIndexOf('.') + 1);
83
if (fileExtensionSuffixes.has(lastLabel)) {