(host: string | undefined)
| 7 | } |
| 8 | |
| 9 | export function isAllowedWorkspaceHostHeader(host: string | undefined): boolean { |
| 10 | if (!host) return false; |
| 11 | if (host.startsWith('[')) { |
| 12 | const close = host.indexOf(']'); |
| 13 | if (close < 0) return false; |
| 14 | const inner = host.slice(1, close); |
| 15 | const trailing = host.slice(close + 1); |
| 16 | if (trailing !== '' && !/^:\d+$/.test(trailing)) return false; |
| 17 | return inner === '::1'; |
| 18 | } |
| 19 | const colon = host.lastIndexOf(':'); |
| 20 | const hostname = colon >= 0 ? host.slice(0, colon) : host; |
| 21 | const portPart = colon >= 0 ? host.slice(colon + 1) : null; |
| 22 | if (portPart !== null && !/^\d+$/.test(portPart)) return false; |
| 23 | if (hostname === 'localhost') return true; |
| 24 | if (/^127\.\d{1,3}\.\d{1,3}\.\d{1,3}$/.test(hostname)) return true; |
| 25 | return false; |
| 26 | } |
no outgoing calls
no test coverage detected