Refresh HiveGrid Cloud reference snapshot
This commit is contained in:
1 parent
5e99e14772
commit
7f88026f79
5955 files changed
+1177325
-188362
No files matched your search
+111
-8
@@ -83,6 +83,32 @@ describe("validateOutboundHttpUrl IPv6 SSRF ranges", () => {
|
||||
});
|
||||
|
||||
describe("fetchOutboundHttpWithRedirects redirect handling", () => {
|
||||
test("applies a feature-specific URL policy before every redirect hop", async () => {
|
||||
const fetchImpl = vi.fn(async () => new Response(null, { status: 302, headers: { location: "https://hooks.example.com:8443/private" } }));
|
||||
const urlValidator = vi.fn((value: string) => {
|
||||
const url = new URL(validateOutboundHttpUrl(value));
|
||||
if (url.port) throw new Error("feature policy rejected non-default port");
|
||||
return url.toString();
|
||||
});
|
||||
|
||||
await expect(
|
||||
fetchOutboundHttpWithRedirects("https://api.example.com/start", { method: "GET" }, { fetchImpl, addressResolver: publicResolver, urlValidator })
|
||||
).rejects.toThrow("feature policy rejected non-default port");
|
||||
|
||||
expect(fetchImpl).toHaveBeenCalledTimes(1);
|
||||
expect(urlValidator).toHaveBeenNthCalledWith(1, "https://api.example.com/start");
|
||||
expect(urlValidator).toHaveBeenNthCalledWith(2, "https://hooks.example.com:8443/private");
|
||||
});
|
||||
|
||||
test("does not let a feature-specific validator weaken the foundation SSRF policy", async () => {
|
||||
const fetchImpl = vi.fn(async () => new Response("unexpected", { status: 200 }));
|
||||
|
||||
await expect(fetchOutboundHttpWithRedirects("http://127.0.0.1/private", { method: "GET" }, { fetchImpl, urlValidator: (value) => value })).rejects.toThrow(
|
||||
"Outbound HTTP endpoint host is not allowed."
|
||||
);
|
||||
expect(fetchImpl).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
test("returns the redirect response unchanged when no location header is present", async () => {
|
||||
const fetchImpl = vi.fn(async () => new Response("redirect-without-location", { status: 302 }));
|
||||
const result = await fetchOutboundHttpWithRedirects("https://api.example.com/start", { method: "GET" }, { fetchImpl, addressResolver: publicResolver });
|
||||
@@ -95,7 +121,7 @@ describe("fetchOutboundHttpWithRedirects redirect handling", () => {
|
||||
const fetchImpl = vi.fn(async () => new Response(null, { status: 302, headers: { location: "https://hooks.example.com/loop" } }));
|
||||
|
||||
await expect(
|
||||
fetchOutboundHttpWithRedirects("https://api.example.com/start", { method: "GET" }, { fetchImpl, addressResolver: publicResolver, redirectLimit: 0 }),
|
||||
fetchOutboundHttpWithRedirects("https://api.example.com/start", { method: "GET" }, { fetchImpl, addressResolver: publicResolver, redirectLimit: 0 })
|
||||
).rejects.toThrow("Outbound HTTP redirect limit exceeded.");
|
||||
expect(fetchImpl).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
@@ -110,8 +136,8 @@ describe("fetchOutboundHttpWithRedirects redirect handling", () => {
|
||||
fetchOutboundHttpWithRedirects(
|
||||
"https://api.example.com/start",
|
||||
{ method: "POST", body: "payload", headers: { "content-type": "application/json", "content-length": "7", "x-trace": "keep" } },
|
||||
{ fetchImpl, addressResolver: publicResolver },
|
||||
),
|
||||
{ fetchImpl, addressResolver: publicResolver }
|
||||
)
|
||||
).resolves.toMatchObject({ status: 200 });
|
||||
|
||||
const secondInit = fetchImpl.mock.calls[1][1] as RequestInit & { headers: Headers };
|
||||
@@ -135,12 +161,89 @@ describe("fetchOutboundHttpWithRedirects redirect handling", () => {
|
||||
expect(secondInit.body).toBe("payload");
|
||||
});
|
||||
|
||||
test.each([307, 308])("strips target-bound credentials on a cross-origin %s redirect", async (status) => {
|
||||
const fetchImpl = vi
|
||||
.fn()
|
||||
.mockResolvedValueOnce(new Response(null, { status, headers: { location: "https://receiver.example/again" } }))
|
||||
.mockResolvedValueOnce(new Response("ok", { status: 200 }));
|
||||
|
||||
await fetchOutboundHttpWithRedirects(
|
||||
"https://hooks.example.com/start",
|
||||
{
|
||||
method: "POST",
|
||||
body: "payload",
|
||||
headers: {
|
||||
authorization: "Bearer auth-secret",
|
||||
cookie: "session=cookie-secret",
|
||||
"proxy-authorization": "Basic proxy-secret",
|
||||
"x-api-key": "api-secret",
|
||||
"x-client-credential": "client-secret",
|
||||
"x-custom-secret": "custom-secret",
|
||||
"x-hook-hmac": "hook-secret",
|
||||
"x-hivegrid-signature": "webhook-secret",
|
||||
"x-webhook-key": "opaque-secret",
|
||||
"content-type": "application/json",
|
||||
"x-idempotency-key": "delivery-1",
|
||||
"x-trace-id": "trace-1",
|
||||
},
|
||||
},
|
||||
{ fetchImpl, addressResolver: publicResolver }
|
||||
);
|
||||
|
||||
const secondInit = fetchImpl.mock.calls[1][1] as RequestInit;
|
||||
const redirectedHeaders = new Headers(secondInit.headers);
|
||||
expect(secondInit.method).toBe("POST");
|
||||
expect(secondInit.body).toBe("payload");
|
||||
expect(redirectedHeaders.get("authorization")).toBeNull();
|
||||
expect(redirectedHeaders.get("cookie")).toBeNull();
|
||||
expect(redirectedHeaders.get("proxy-authorization")).toBeNull();
|
||||
expect(redirectedHeaders.get("x-api-key")).toBeNull();
|
||||
expect(redirectedHeaders.get("x-client-credential")).toBeNull();
|
||||
expect(redirectedHeaders.get("x-custom-secret")).toBeNull();
|
||||
expect(redirectedHeaders.get("x-hook-hmac")).toBeNull();
|
||||
expect(redirectedHeaders.get("x-hivegrid-signature")).toBeNull();
|
||||
expect(redirectedHeaders.get("x-webhook-key")).toBeNull();
|
||||
expect(redirectedHeaders.get("content-type")).toBe("application/json");
|
||||
expect(redirectedHeaders.get("x-idempotency-key")).toBe("delivery-1");
|
||||
expect(redirectedHeaders.get("x-trace-id")).toBe("trace-1");
|
||||
});
|
||||
|
||||
test("keeps target-bound credentials on a same-origin redirect", async () => {
|
||||
const fetchImpl = vi
|
||||
.fn()
|
||||
.mockResolvedValueOnce(new Response(null, { status: 307, headers: { location: "/again" } }))
|
||||
.mockResolvedValueOnce(new Response("ok", { status: 200 }));
|
||||
|
||||
await fetchOutboundHttpWithRedirects(
|
||||
"https://hooks.example.com/start",
|
||||
{ method: "POST", body: "payload", headers: { authorization: "Bearer secret", "x-hivegrid-signature": "sha256=secret" } },
|
||||
{ fetchImpl, addressResolver: publicResolver }
|
||||
);
|
||||
|
||||
const redirectedHeaders = new Headers(fetchImpl.mock.calls[1][1]?.headers);
|
||||
expect(redirectedHeaders.get("authorization")).toBe("Bearer secret");
|
||||
expect(redirectedHeaders.get("x-hivegrid-signature")).toBe("sha256=secret");
|
||||
});
|
||||
|
||||
test("can reject cross-origin redirects before target-bound credentials are forwarded", async () => {
|
||||
const fetchImpl = vi.fn(async () => new Response(null, { status: 307, headers: { location: "https://attacker.example/steal" } }));
|
||||
|
||||
await expect(
|
||||
fetchOutboundHttpWithRedirects(
|
||||
"https://hooks.example.com/start",
|
||||
{ method: "POST", headers: { "x-hivegrid-signature": "secret" }, body: "payload" },
|
||||
{ fetchImpl, addressResolver: publicResolver, allowCrossOriginRedirects: false }
|
||||
)
|
||||
).rejects.toThrow("cross-origin redirect is not allowed");
|
||||
expect(fetchImpl).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
test("rejects a redirect to a literal private IPv4 target", async () => {
|
||||
const fetchImpl = vi.fn(async () => new Response(null, { status: 301, headers: { location: "http://192.168.0.5/internal" } }));
|
||||
|
||||
await expect(fetchOutboundHttpWithRedirects("https://api.example.com/start", { method: "GET" }, { fetchImpl, addressResolver: publicResolver })).rejects.toThrow(
|
||||
"Outbound HTTP endpoint host is not allowed.",
|
||||
);
|
||||
await expect(
|
||||
fetchOutboundHttpWithRedirects("https://api.example.com/start", { method: "GET" }, { fetchImpl, addressResolver: publicResolver })
|
||||
).rejects.toThrow("Outbound HTTP endpoint host is not allowed.");
|
||||
});
|
||||
|
||||
test("surfaces a resolver failure as an unresolved-host error", async () => {
|
||||
@@ -150,7 +253,7 @@ describe("fetchOutboundHttpWithRedirects redirect handling", () => {
|
||||
});
|
||||
|
||||
await expect(fetchOutboundHttpWithRedirects("https://api.example.com/start", { method: "GET" }, { fetchImpl, addressResolver })).rejects.toThrow(
|
||||
"Outbound HTTP endpoint host could not be resolved.",
|
||||
"Outbound HTTP endpoint host could not be resolved."
|
||||
);
|
||||
expect(fetchImpl).not.toHaveBeenCalled();
|
||||
});
|
||||
@@ -160,7 +263,7 @@ describe("fetchOutboundHttpWithRedirects redirect handling", () => {
|
||||
const addressResolver = vi.fn(async () => []);
|
||||
|
||||
await expect(fetchOutboundHttpWithRedirects("https://api.example.com/start", { method: "GET" }, { fetchImpl, addressResolver })).rejects.toThrow(
|
||||
"Outbound HTTP endpoint host could not be resolved.",
|
||||
"Outbound HTTP endpoint host could not be resolved."
|
||||
);
|
||||
});
|
||||
|
||||
|
||||
Reference in new issue
Block a user