mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 18:38:28 +00:00
fix(ssrf): unify ipv6 special-use blocking
This commit is contained in:
@@ -18,6 +18,7 @@ describe("fetchWithSsrFGuard hardening", () => {
|
||||
it("blocks private and legacy loopback literals before fetch", async () => {
|
||||
const blockedUrls = [
|
||||
"http://127.0.0.1:8080/internal",
|
||||
"http://[ff02::1]/internal",
|
||||
"http://0177.0.0.1:8080/internal",
|
||||
"http://0x7f000001/internal",
|
||||
];
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { blockedIpv6MulticastLiterals } from "../../shared/net/ip-test-fixtures.js";
|
||||
import { normalizeFingerprint } from "../tls/fingerprint.js";
|
||||
import { isBlockedHostnameOrIp, isPrivateIpAddress } from "./ssrf.js";
|
||||
|
||||
@@ -38,9 +39,7 @@ const privateIpCases = [
|
||||
"fe80::1%lo0",
|
||||
"fd00::1",
|
||||
"fec0::1",
|
||||
"ff02::1",
|
||||
"ff05::1:3",
|
||||
"[ff02::1]",
|
||||
...blockedIpv6MulticastLiterals,
|
||||
"2001:db8:1234::5efe:127.0.0.1",
|
||||
"2001:db8:1234:1:200:5efe:7f00:1",
|
||||
];
|
||||
|
||||
@@ -4,11 +4,11 @@ import { Agent, type Dispatcher } from "undici";
|
||||
import {
|
||||
extractEmbeddedIpv4FromIpv6,
|
||||
isBlockedSpecialUseIpv4Address,
|
||||
isBlockedSpecialUseIpv6Address,
|
||||
isCanonicalDottedDecimalIPv4,
|
||||
type Ipv4SpecialUseBlockOptions,
|
||||
isIpv4Address,
|
||||
isLegacyIpv4Literal,
|
||||
isPrivateOrLoopbackIpAddress,
|
||||
parseCanonicalIpAddress,
|
||||
parseLooseIpAddress,
|
||||
} from "../../shared/net/ip.js";
|
||||
@@ -120,7 +120,7 @@ export function isPrivateIpAddress(address: string, policy?: SsrFPolicy): boolea
|
||||
if (isIpv4Address(strictIp)) {
|
||||
return isBlockedSpecialUseIpv4Address(strictIp, blockOptions);
|
||||
}
|
||||
if (isPrivateOrLoopbackIpAddress(strictIp.toString())) {
|
||||
if (isBlockedSpecialUseIpv6Address(strictIp)) {
|
||||
return true;
|
||||
}
|
||||
const embeddedIpv4 = extractEmbeddedIpv4FromIpv6(strictIp);
|
||||
|
||||
Reference in New Issue
Block a user