fix(security): harden session export image data-url handling

This commit is contained in:
Peter Steinberger
2026-02-24 02:52:33 +00:00
parent fefc414576
commit e578521ef4
8 changed files with 138 additions and 15 deletions

View File

@@ -113,3 +113,42 @@ describe("base64 size guards", () => {
fromSpy.mockRestore();
});
});
describe("input image base64 validation", () => {
it("rejects malformed base64 payloads", async () => {
await expect(
extractImageContentFromSource(
{
type: "base64",
data: 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8/x8AAwMCAO2N4j8AAAAASUVORK5CYII=" onerror="alert(1)',
mediaType: "image/png",
},
{
allowUrl: false,
allowedMimes: new Set(["image/png"]),
maxBytes: 1024 * 1024,
maxRedirects: 0,
timeoutMs: 1,
},
),
).rejects.toThrow("invalid 'data' field");
});
it("normalizes whitespace in valid base64 payloads", async () => {
const image = await extractImageContentFromSource(
{
type: "base64",
data: " aGVs bG8= \n",
mediaType: "image/png",
},
{
allowUrl: false,
allowedMimes: new Set(["image/png"]),
maxBytes: 1024 * 1024,
maxRedirects: 0,
timeoutMs: 1,
},
);
expect(image.data).toBe("aGVsbG8=");
});
});