MCPcopy
hub / github.com/inkeep/open-knowledge / isAllowedWorkspaceHostHeader

Function isAllowedWorkspaceHostHeader

packages/server/src/loopback.ts:9–26  ·  view source on GitHub ↗
(host: string | undefined)

Source from the content-addressed store, hash-verified

7}
8
9export 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}

Callers 14

handlePrincipalFunction · 0.90
handleEmbedDetectFunction · 0.90
handleWorkspaceFunction · 0.90
handleApiConfigFunction · 0.90
onRequestFunction · 0.90
onRequestFunction · 0.90
loopback.test.tsFile · 0.90
onRequestFunction · 0.90
runContentFunction · 0.90
onUpgradeFunction · 0.90
onAuthenticateFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected