mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 19:10:58 +00:00
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:
@@ -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", () => {
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user