| 123456789101112131415161718 |
- /**
- * Browser-safe, zero-dependency loopback classification shared by the `/api`
- * Host fence and the package's `ctx.connection` state. The predicate stays
- * package-internal; client plugins consume the derived state through Cordis.
- */
- /**
- * Whether a normalized URL hostname names the local loopback authority.
- * @param hostname - WHATWG URL hostname (IPv6 literals retain brackets).
- * @returns true for localhost, IPv6 loopback, or any IPv4 address in 127/8.
- */
- export function isLoopbackHostname(hostname: string): boolean {
- if (hostname === 'localhost' || hostname === '[::1]') return true
- const parts = hostname.split('.')
- return parts.length === 4
- && parts[0] === '127'
- && parts.every(part => /^\d{1,3}$/.test(part) && Number(part) <= 255)
- }
|