True if a Host header or URL hostname is a loopback name ("localhost", "127.0.0.1", "[::1]"), with or without port.
(host: string | undefined)
| 32 | |
| 33 | /** True if a Host header or URL hostname is a loopback name ("localhost", "127.0.0.1", "[::1]"), with or without port. */ |
| 34 | function isLoopbackHost(host: string | undefined): boolean { |
| 35 | if (!host) return false; |
| 36 | const name = host.startsWith("[") ? host.slice(0, host.indexOf("]") + 1) : host.replace(/:\d+$/, ""); |
| 37 | return name === "localhost" || name === "127.0.0.1" || name === "[::1]"; |
| 38 | } |
| 39 | |
| 40 | /** |
| 41 | * True if the request is plainly same-machine browser traffic (or a |