* Normalize hostname for blocklist comparison: * - Strip trailing dot (DNS fully-qualified notation) * - Strip IPv6 brackets (URL.hostname includes [] for IPv6) * - Resolve hex (0xA9FEA9FE) and decimal (2852039166) IP representations
(hostname: string)
| 46 | * - Resolve hex (0xA9FEA9FE) and decimal (2852039166) IP representations |
| 47 | */ |
| 48 | function normalizeHostname(hostname: string): string { |
| 49 | // Strip IPv6 brackets |
| 50 | let h = hostname.startsWith('[') && hostname.endsWith(']') |
| 51 | ? hostname.slice(1, -1) |
| 52 | : hostname; |
| 53 | // Strip trailing dot |
| 54 | if (h.endsWith('.')) h = h.slice(0, -1); |
| 55 | return h; |
| 56 | } |
| 57 | |
| 58 | /** |
| 59 | * Check if a hostname resolves to the link-local metadata IP 169.254.169.254. |
no outgoing calls
no test coverage detected