mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 23:48:28 +00:00
refactor: centralize isPlainObject, isRecord, isErrno, isLoopbackHost utilities (#12926)
This commit is contained in:
@@ -255,6 +255,20 @@ function isValidIPv4(host: string): boolean {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a hostname or IP refers to the local machine.
|
||||
* Handles: localhost, 127.x.x.x, ::1, [::1], ::ffff:127.x.x.x
|
||||
* Note: 0.0.0.0 and :: are NOT loopback - they bind to all interfaces.
|
||||
*/
|
||||
export function isLoopbackHost(host: string): boolean {
|
||||
return isLoopbackAddress(host);
|
||||
if (!host) {
|
||||
return false;
|
||||
}
|
||||
const h = host.trim().toLowerCase();
|
||||
if (h === "localhost") {
|
||||
return true;
|
||||
}
|
||||
// Handle bracketed IPv6 addresses like [::1]
|
||||
const unbracket = h.startsWith("[") && h.endsWith("]") ? h.slice(1, -1) : h;
|
||||
return isLoopbackAddress(unbracket);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user