(host: string | undefined, opts: HostCheckOptions)
| 117 | * when `opts.disable` is set. |
| 118 | */ |
| 119 | export function isAllowedHost(host: string | undefined, opts: HostCheckOptions): boolean { |
| 120 | if (opts.disable === true) { |
| 121 | return true; |
| 122 | } |
| 123 | if (host === undefined || host.length === 0) { |
| 124 | return false; |
| 125 | } |
| 126 | const h = stripPort(host); |
| 127 | |
| 128 | if (h === 'localhost' || h === '127.0.0.1' || h === '::1' || h === '[::1]') { |
| 129 | return true; |
| 130 | } |
| 131 | if (h.endsWith('.localhost')) { |
| 132 | return true; |
| 133 | } |
| 134 | if (net.isIP(h) !== 0) { |
| 135 | return true; |
| 136 | } |
| 137 | if (opts.boundHost !== undefined && h === stripPort(opts.boundHost)) { |
| 138 | return true; |
| 139 | } |
| 140 | if (opts.extra !== undefined) { |
| 141 | for (const entry of opts.extra) { |
| 142 | if (entry.startsWith('.')) { |
| 143 | const base = entry.slice(1); |
| 144 | if (h === base || h.endsWith(entry)) { |
| 145 | return true; |
| 146 | } |
| 147 | } else if (h === entry) { |
| 148 | return true; |
| 149 | } |
| 150 | } |
| 151 | } |
| 152 | return false; |
| 153 | } |
| 154 | |
| 155 | /** |
| 156 | * Build the Fastify `onRequest` hook and the reusable `isAllowed` predicate. |
no test coverage detected