Something went wrong. Try again.
Monorepo for the nibling.run platform
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930/** How long any one call to a relay, PDS, PLC, or Slingshot may take. */export const FETCH_TIMEOUT_MS = 10_000;
const PRIVATE_SUFFIXES = ['.localhost', '.internal', '.local'];
function isPrivateIPv4(host: string): boolean { const parts = host.split('.'); if (parts.length !== 4 || !parts.every((p) => /^\d{1,3}$/.test(p))) return false; const [a, b] = parts.map(Number) as [number, number]; return a === 0 || a === 10 || a === 127 || (a === 169 && b === 254) || (a === 172 && b >= 16 && b <= 31) || (a === 192 && b === 168);}
function isPrivateIPv6(host: string): boolean { if (!host.startsWith('[')) return false; const addr = host.slice(1, -1); return addr === '::1' || addr === '::' || addr.startsWith('fc') || addr.startsWith('fd') || addr.startsWith('fe80:') || addr.startsWith('::ffff:');}
/** Whether a PDS endpoint (or any URL named by a DID document) is safe to fetch: `https:`, and * not a host that obviously points inside a network. `URL` canonicalizes IPv4 spellings such as * `2130706433` or `0x7f.1` to dotted decimal, so the checks below see the real address. */export function isPublicHttpsUrl(value: string): boolean { if (!URL.canParse(value)) return false; const url = new URL(value); if (url.protocol !== 'https:' || url.username || url.password) return false; const host = url.hostname.toLowerCase().replace(/\.$/, ''); if (host === 'localhost' || PRIVATE_SUFFIXES.some((suffix) => host.endsWith(suffix))) return false; return !isPrivateIPv4(host) && !isPrivateIPv6(host);}