test(web): add SSRF guard cases
This commit is contained in:
@@ -163,6 +163,28 @@ describe("web media loading", () => {
|
||||
fetchMock.mockRestore();
|
||||
});
|
||||
|
||||
it("blocks private network URL fetches (SSRF guard)", async () => {
|
||||
const fetchMock = vi.spyOn(globalThis, "fetch");
|
||||
|
||||
await expect(loadWebMedia("http://127.0.0.1:8080/internal-api", 1024 * 1024)).rejects.toThrow(
|
||||
/blocked|private|internal/i,
|
||||
);
|
||||
expect(fetchMock).not.toHaveBeenCalled();
|
||||
|
||||
fetchMock.mockRestore();
|
||||
});
|
||||
|
||||
it("blocks cloud metadata hostnames (SSRF guard)", async () => {
|
||||
const fetchMock = vi.spyOn(globalThis, "fetch");
|
||||
|
||||
await expect(
|
||||
loadWebMedia("http://metadata.google.internal/computeMetadata/v1/", 1024 * 1024),
|
||||
).rejects.toThrow(/blocked|private|internal|metadata/i);
|
||||
expect(fetchMock).not.toHaveBeenCalled();
|
||||
|
||||
fetchMock.mockRestore();
|
||||
});
|
||||
|
||||
it("respects maxBytes for raw URL fetches", async () => {
|
||||
const fetchMock = vi.spyOn(globalThis, "fetch").mockResolvedValueOnce({
|
||||
ok: true,
|
||||
|
||||
Reference in New Issue
Block a user