Repository navigation
fix(electron): validate pigui:invoke sender and unit-test capture downsample - #321
Merged
Merged
Conversation
…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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
ipcMain.handle("pigui:invoke")had no sender validation (ADR-0029 gap). Extracted a pureisTrustedInvokeSenderseam (ipc-sender-guard.ts) and wired it in: only the main window's ownwebContentsmay invoke commands through this channel — an embeddedWebContentsViewbrowser tab, or any other sender, is now rejected with a thrown error.createBrowserView'scapture(maxWidth)had anativeImage.resizedownsample branch only reachable on a real HiDPI display (CI's 1x runners never hit it). Extracted it intodownsampleToCssWidth(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.browser-annotation.ts/browser-annotation-preload.tsthat saidpigui: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 passingbun run typecheck— clean