Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/review/visual/shot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,12 @@ export async function captureShot(env: Env, url: string, viewport: Viewport = VI
console.log(JSON.stringify({ ev: "render_screenshot_auth_walled", url, final: page.url().slice(0, 200) }));
return { png: null, authWalled: true };
}
const shot = (await page.screenshot({ type: "png", fullPage: false })) as Uint8Array;
// Full-page (not just the viewport): before/after must show the SAME position on the page for any
// change, however far down it is. A viewport-only shot only captures whatever happens to be in frame at
// load time, which for a change midway down a long page would silently miss it in both cells. Capturing
// the whole scrollable height means the changed region is always present in both images at the same
// relative offset, with no need to locate/scroll to it first.
const shot = (await page.screenshot({ type: "png", fullPage: true })) as Uint8Array;
return { png: shot, authWalled: false };
} catch (error) {
// Log before degrading to null — otherwise a networkidle0 timeout, a binding quota error, or a render
Expand Down
8 changes: 8 additions & 0 deletions test/unit/visual-shot.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,14 @@ describe("visual screenshot on-demand SSRF guard", () => {
expect(mocks.screenshot).toHaveBeenCalled();
});

it("captures the FULL page, not just the viewport — before/after must show the same page position for a change however far down it is", async () => {
mocks.finalUrl = "https://preview.pages.dev/page";

await handleShot(request("https://preview.pages.dev/page"), env());

expect(mocks.screenshot).toHaveBeenCalledWith({ type: "png", fullPage: true });
});

it("captureShot rejects an unsafe target before launching the browser (defense-in-depth)", async () => {
const result = await captureShot(env(), "http://127.0.0.1/admin");
expect(result).toEqual({ png: null, authWalled: false });
Expand Down
Loading