Browser: normalize localhost absolute-form CDP hosts (#59236)

* Browser: normalize localhost absolute-form CDP hosts

* CHANGELOG: note localhost absolute-form CDP fix

---------

Co-authored-by: Jacob Tomlinson <jtomlinson@nvidia.com>
This commit is contained in:
mappel-nv
2026-04-02 08:34:55 -04:00
committed by GitHub
parent e48ee8ae9e
commit 9c22d63669
4 changed files with 22 additions and 2 deletions

View File

@@ -3,6 +3,7 @@ import { afterEach, describe, expect, it, vi } from "vitest";
import { makeNetworkInterfacesSnapshot } from "../test-helpers/network-interfaces.js";
import {
isLocalishHost,
isLoopbackHost,
isPrivateOrLoopbackAddress,
isPrivateOrLoopbackHost,
isSecureWebSocketUrl,
@@ -28,6 +29,7 @@ describe("isLocalishHost", () => {
it("accepts loopback and tailscale serve/funnel host headers", () => {
const accepted = [
"localhost",
"localhost.:18789",
"127.0.0.1:18789",
"[::1]:18789",
"[::ffff:127.0.0.1]:18789",
@@ -46,6 +48,13 @@ describe("isLocalishHost", () => {
});
});
describe("isLoopbackHost", () => {
it("accepts localhost absolute-form hostnames", () => {
expect(isLoopbackHost("localhost.")).toBe(true);
expect(isLoopbackHost("LOCALHOST...")).toBe(true);
});
});
describe("isTrustedProxyAddress", () => {
it.each([
{
@@ -394,6 +403,7 @@ describe("isPrivateOrLoopbackAddress", () => {
describe("isPrivateOrLoopbackHost", () => {
it("accepts localhost", () => {
expect(isPrivateOrLoopbackHost("localhost")).toBe(true);
expect(isPrivateOrLoopbackHost("localhost.")).toBe(true);
});
it("accepts loopback addresses", () => {

View File

@@ -400,8 +400,9 @@ function parseHostForAddressChecks(
return null;
}
const normalizedHost = host.trim().toLowerCase();
if (normalizedHost === "localhost") {
return { isLocalhost: true, unbracketedHost: normalizedHost };
const canonicalHost = normalizedHost.replace(/\.+$/, "");
if (canonicalHost === "localhost") {
return { isLocalhost: true, unbracketedHost: canonicalHost };
}
return {
isLocalhost: false,