mirror of https://github.com/openclaw/openclaw.git
test: simplify ssrf hostname coverage
This commit is contained in:
parent
3e8d9bc6ea
commit
f3d4bb4103
|
|
@ -111,19 +111,23 @@ describe("normalizeFingerprint", () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("isBlockedHostnameOrIp", () => {
|
describe("isBlockedHostnameOrIp", () => {
|
||||||
it("blocks localhost.localdomain and metadata hostname aliases", () => {
|
it.each([
|
||||||
expect(isBlockedHostnameOrIp("localhost.localdomain")).toBe(true);
|
"localhost.localdomain",
|
||||||
expect(isBlockedHostnameOrIp("metadata.google.internal")).toBe(true);
|
"metadata.google.internal",
|
||||||
|
"api.localhost",
|
||||||
|
"svc.local",
|
||||||
|
"db.internal",
|
||||||
|
])("blocks reserved hostname %s", (hostname) => {
|
||||||
|
expect(isBlockedHostnameOrIp(hostname)).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("blocks private transition addresses via shared IP classifier", () => {
|
it.each([
|
||||||
expect(isBlockedHostnameOrIp("2001:db8:1234::5efe:127.0.0.1")).toBe(true);
|
["2001:db8:1234::5efe:127.0.0.1", true],
|
||||||
expect(isBlockedHostnameOrIp("2001:db8::1")).toBe(false);
|
["2001:db8::1", false],
|
||||||
});
|
["198.18.0.1", true],
|
||||||
|
["198.20.0.1", false],
|
||||||
it("blocks IPv4 special-use ranges but allows adjacent public ranges", () => {
|
])("returns %s => %s", (value, expected) => {
|
||||||
expect(isBlockedHostnameOrIp("198.18.0.1")).toBe(true);
|
expect(isBlockedHostnameOrIp(value)).toBe(expected);
|
||||||
expect(isBlockedHostnameOrIp("198.20.0.1")).toBe(false);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("supports opt-in policy to allow RFC2544 benchmark range", () => {
|
it("supports opt-in policy to allow RFC2544 benchmark range", () => {
|
||||||
|
|
@ -134,10 +138,15 @@ describe("isBlockedHostnameOrIp", () => {
|
||||||
expect(isBlockedHostnameOrIp("198.51.100.1", policy)).toBe(true);
|
expect(isBlockedHostnameOrIp("198.51.100.1", policy)).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("blocks legacy IPv4 literal representations", () => {
|
it.each(["0177.0.0.1", "8.8.2056", "127.1", "2130706433"])(
|
||||||
expect(isBlockedHostnameOrIp("0177.0.0.1")).toBe(true);
|
"blocks legacy IPv4 literal %s",
|
||||||
expect(isBlockedHostnameOrIp("8.8.2056")).toBe(true);
|
(address) => {
|
||||||
expect(isBlockedHostnameOrIp("127.1")).toBe(true);
|
expect(isBlockedHostnameOrIp(address)).toBe(true);
|
||||||
expect(isBlockedHostnameOrIp("2130706433")).toBe(true);
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
it("does not block ordinary hostnames", () => {
|
||||||
|
expect(isBlockedHostnameOrIp("example.com")).toBe(false);
|
||||||
|
expect(isBlockedHostnameOrIp("api.example.net")).toBe(false);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue