MCPcopy
hub / github.com/garrytan/gstack / normalizeHostname

Function normalizeHostname

browse/src/url-validation.ts:48–56  ·  view source on GitHub ↗

* 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)

Source from the content-addressed store, hash-verified

46 * - Resolve hex (0xA9FEA9FE) and decimal (2852039166) IP representations
47 */
48function 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.

Callers 1

validateNavigationUrlFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected