fix(browser): handle IPv6 loopback auth and dedupe fetch auth tests

This commit is contained in:
Peter Steinberger
2026-02-18 13:15:00 +00:00
parent eb775ff24b
commit 28b8101eef
2 changed files with 30 additions and 25 deletions

View File

@@ -21,7 +21,11 @@ function isAbsoluteHttp(url: string): boolean {
function isLoopbackHttpUrl(url: string): boolean {
try {
const host = new URL(url).hostname.trim().toLowerCase();
return host === "127.0.0.1" || host === "localhost" || host === "::1";
// URL hostnames may keep IPv6 brackets (for example "[::1]"); normalize before checks.
const normalizedHost = host.startsWith("[") && host.endsWith("]") ? host.slice(1, -1) : host;
return (
normalizedHost === "127.0.0.1" || normalizedHost === "localhost" || normalizedHost === "::1"
);
} catch {
return false;
}