mirror of
https://github.com/openclaw/openclaw.git
synced 2026-07-21 02:06:43 +00:00
fix(net-policy): restore ipaddr typing compatibility
Repair main CI by preserving newer ipaddr range labels across merged declarations and narrowing CIDR match operands by address family.
This commit is contained in:
@@ -17,7 +17,9 @@ function normalizeLowercaseStringOrEmpty(value: unknown): string {
|
||||
export type ParsedIpAddress = ipaddr.IPv4 | ipaddr.IPv6;
|
||||
type Ipv4Range = ReturnType<ipaddr.IPv4["range"]>;
|
||||
type Ipv6Range = ReturnType<ipaddr.IPv6["range"]>;
|
||||
type BlockedIpv6Range = Ipv6Range | "discard";
|
||||
// Older co-installed ipaddr.js declarations can merge with 2.4's ambient module and
|
||||
// omit newer runtime ranges from ReturnType, so preserve the policy's known labels.
|
||||
type BlockedIpv6Range = Ipv6Range | "benchmarking" | "discard" | "orchid2";
|
||||
type Ipv6Hextets = readonly [number, number, number, number, number, number, number, number];
|
||||
|
||||
// ipaddr.js guarantees 8 hextets; throw loudly on an impossible shape instead of
|
||||
@@ -362,10 +364,13 @@ export function isIpInCidr(ip: string, cidr: string): boolean {
|
||||
try {
|
||||
const [baseAddress, prefixLength] = ipaddr.parseCIDR(candidate);
|
||||
const comparableBase = normalizeIpv4MappedAddress(baseAddress);
|
||||
return (
|
||||
comparableIp.kind() === comparableBase.kind() &&
|
||||
comparableIp.match([comparableBase, prefixLength])
|
||||
);
|
||||
if (isIpv4Address(comparableIp) && isIpv4Address(comparableBase)) {
|
||||
return comparableIp.match([comparableBase, prefixLength]);
|
||||
}
|
||||
if (isIpv6Address(comparableIp) && isIpv6Address(comparableBase)) {
|
||||
return comparableIp.match([comparableBase, prefixLength]);
|
||||
}
|
||||
return false;
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user