MCPcopy Create free account
hub / github.com/UsefulSoftwareCo/executor / normalizeTrustedOrigin

Function normalizeTrustedOrigin

apps/host-selfhost/src/config.ts:316–339  ·  view source on GitHub ↗
(value: string)

Source from the content-addressed store, hash-verified

314// the other knobs here, a malformed value refuses to boot instead of quietly
315// leaving the browser locked out with an "Invalid origin" page.
316const normalizeTrustedOrigin = (value: string): string => {
317 if (!URL.canParse(value)) {
318 // oxlint-disable-next-line executor/no-try-catch-or-throw, executor/no-error-constructor -- boundary: refuse to boot on a malformed operator knob
319 throw new Error(
320 `EXECUTOR_TRUSTED_ORIGINS contains ${JSON.stringify(value)}, which is not a valid URL origin`,
321 );
322 }
323 const url = new URL(value);
324 if (
325 (url.protocol !== "http:" && url.protocol !== "https:") ||
326 url.username.length > 0 ||
327 url.password.length > 0 ||
328 url.hostname.includes("*") ||
329 (url.pathname !== "" && url.pathname !== "/") ||
330 url.search.length > 0 ||
331 url.hash.length > 0
332 ) {
333 // oxlint-disable-next-line executor/no-try-catch-or-throw, executor/no-error-constructor -- boundary: refuse to boot on a malformed operator knob
334 throw new Error(
335 `EXECUTOR_TRUSTED_ORIGINS entry ${JSON.stringify(value)} must be an exact http(s) origin (scheme, host, and optional port only)`,
336 );
337 }
338 return url.origin;
339};
340
341// The canonical origin always leads the list, so the unset case reproduces the
342// previous `[webBaseUrl]` exactly and an operator who repeats it in the env var

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected