Files
LivingDexTracker/tests/support/loopback.ts
T
2026-09-14 12:56:09 +01:00

16 lines
416 B
TypeScript

const LOOPBACK_HOSTS = new Set(['127.0.0.1', 'localhost', '[::1]']);
export function isLoopbackUrl(value: string): boolean {
try {
return LOOPBACK_HOSTS.has(new URL(value).hostname);
} catch {
return false;
}
}
export function requireLoopbackUrl(value: string, label: string): string {
if (!isLoopbackUrl(value))
throw new Error(`Refusing to send credentials to non-loopback ${label}`);
return value;
}