const FORBIDDEN_PORT = 8788; export function parseExternalE2eOrigin(value) { if (value === undefined) return undefined; if (value === '') throw new Error('E2E_ORIGIN must not be empty when set.'); let url; try { url = new URL(value); } catch { throw new Error('E2E_ORIGIN must be a valid absolute URL.'); } if ( url.protocol !== 'http:' || url.hostname !== '127.0.0.1' || !url.port || url.username || url.password || url.pathname !== '/' || url.search || url.hash ) { throw new Error( 'E2E_ORIGIN must be an HTTP origin on numeric loopback with an explicit port (for example http://127.0.0.1:8789).', ); } if (Number(url.port) === FORBIDDEN_PORT) { throw new Error(`E2E_ORIGIN must not use forbidden legacy port ${FORBIDDEN_PORT}.`); } return url.origin; }