mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-11 00:34:33 +00:00
fix(security): harden session export image data-url handling
This commit is contained in:
@@ -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=");
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user