MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / isAllowedOrigin

Function isAllowedOrigin

src/ui-server/security.ts:176–193  ·  view source on GitHub ↗
(origin: string | undefined, port: number)

Source from the content-addressed store, hash-verified

174 * the literal `null` origin (sandboxed iframe, `file://` page) is refused.
175 */
176export function isAllowedOrigin(origin: string | undefined, port: number): boolean {
177 if (origin === undefined) return true;
178 const trimmed = origin.trim();
179 if (trimmed === '') return true;
180 if (trimmed === 'null') return false;
181
182 let url: URL;
183 try {
184 url = new URL(trimmed);
185 } catch {
186 return false;
187 }
188 if (url.protocol !== 'http:' && url.protocol !== 'https:') return false;
189 // WHATWG keeps IPv6 hostnames bracketed; the allowlist stores them bare.
190 const hostname = url.hostname.replace(/^\[/, '').replace(/\]$/, '').toLowerCase();
191 if (!LOOPBACK_HOSTNAMES.has(hostname)) return false;
192 return url.port === '' || Number(url.port) === port;
193}
194
195/**
196 * Whether a raw request path is worth resolving at all.

Callers 2

handleRequestFunction · 0.90
ui-server.test.tsFile · 0.90

Calls 2

NumberInterface · 0.85
hasMethod · 0.80

Tested by

no test coverage detected