Skip to content

fix(electron): validate pigui:invoke sender and unit-test capture downsample - #321

Merged
bubbleptr merged 1 commit into
mainfrom
fix/electron-invoke-sender-and-capture-test
Sep 17, 2026
Merged

bubbleptr merged 1 commit into
mainfrom
fix/electron-invoke-sender-and-capture-test

Conversation

@bubbleptr

Copy link
Copy Markdown
Owner

Summary

  • ipcMain.handle("pigui:invoke") had no sender validation (ADR-0029 gap). Extracted a pure isTrustedInvokeSender seam (ipc-sender-guard.ts) and wired it in: only the main window's own webContents may invoke commands through this channel — an embedded WebContentsView browser tab, or any other sender, is now rejected with a thrown error.
  • createBrowserView's capture(maxWidth) had a nativeImage.resize downsample branch only reachable on a real HiDPI display (CI's 1x runners never hit it). Extracted it into downsampleToCssWidth (capture-downsample.ts), generic over the image type so it can be unit-tested with a fake image at both 1x (no resize) and 2x (resized to CSS width) scale.
  • Updated stale comments in browser-annotation.ts / browser-annotation-preload.ts that said pigui:invoke "has no sender check at all" — it now does, though annotations still get their own channel and validation.

Closes #160
Closes #161

Test plan

  • bunx vitest run apps/desktop/electron/ipc-sender-guard.test.ts apps/desktop/electron/capture-downsample.test.ts (new tests, written before implementation, watched fail then pass)
  • bun run test — 139 files / 1500 tests passing
  • bun run typecheck — clean

…nsample

- pigui:invoke had no sender check; extract a pure isTrustedInvokeSender
  seam and reject any sender that is not the main window's own webContents
  (e.g. an embedded WebContentsView browser tab), closing the gap noted in
  ADR-0029.
- Extract createBrowserView's HiDPI-only nativeImage.resize branch into
  downsampleToCssWidth so it is unit-testable with a fake image at both
  1x and 2x scale, instead of only reachable on a real HiDPI display.

Closes #160
Closes #161
@bubbleptr
bubbleptr merged commit ae3c7e7 into main Sep 17, 2026
@bubbleptr
bubbleptr deleted the fix/electron-invoke-sender-and-capture-test branch September 17, 2026 09:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

main.ts 的 capture 降采样加 fake nativeImage 单测 主进程 pigui:invoke 补 sender 校验

1 participant