[codex] Harden IPC payload validation - #96
Open
bendsp wants to merge 2 commits into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR introduces a dedicated IPC payload validation layer for file save/export operations in the Electron main process, aiming to prevent malformed or oversized renderer-provided input from reaching filesystem/export logic.
Changes:
- Added
src/main/ipcValidation.tswith size checks, payload normalizers, and export filename sanitization. - Updated main-process IPC handlers (
file:save,file:export) to acceptunknownand validate before use. - Added unit tests for IPC validation and wired them into the unit test entrypoint.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 8 comments.
| File | Description |
|---|---|
| tests/ipcValidation.test.ts | Adds unit tests for the new IPC validation helpers. |
| tests/index.ts | Registers the new IPC validation test module in the unit test suite. |
| src/main/ipcValidation.ts | Implements payload normalization/validation and export filename sanitization helpers. |
| src/main/index.ts | Routes IPC inputs through the new validation helpers before performing save/export work. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
282
to
285
| const payload = normalizeSaveFilePayload(args); | ||
| if (!payload) { | ||
| throw new Error("Invalid save payload."); | ||
| } |
Comment on lines
315
to
319
| const message = | ||
| error instanceof Error ? error.message : "An unknown error occurred."; | ||
| captureMainTelemetryException(error, { | ||
| operation: "file:save", | ||
| filePath: args?.filePath, | ||
| }); |
Comment on lines
399
to
402
| const payload = normalizeExportFilePayload(args); | ||
| if (!payload) { | ||
| throw new Error("Invalid export payload."); | ||
| } |
Comment on lines
495
to
500
| } catch (error) { | ||
| const message = | ||
| error instanceof Error ? error.message : "An unknown error occurred."; | ||
| captureMainTelemetryException(error, { | ||
| operation: "file:export", | ||
| format: args?.format, | ||
| }); |
Comment on lines
+29
to
+35
| if ( | ||
| "filePath" in payload && | ||
| payload.filePath !== undefined && | ||
| (typeof payload.filePath !== "string" || payload.filePath.trim() === "") | ||
| ) { | ||
| return null; | ||
| } |
Comment on lines
+58
to
+64
| if ( | ||
| "defaultFileName" in payload && | ||
| payload.defaultFileName !== undefined && | ||
| typeof payload.defaultFileName !== "string" | ||
| ) { | ||
| return null; | ||
| } |
Comment on lines
+85
to
+90
| const sanitized = [...withoutExtension] | ||
| .map((char) => | ||
| char.charCodeAt(0) < 32 || reservedCharacters.includes(char) ? "-" : char | ||
| ) | ||
| .join(""); | ||
| return sanitized || "Exported"; |
Comment on lines
+41
to
+51
| runTest("export payload validation rejects unsupported formats", () => { | ||
| assert.equal( | ||
| normalizeExportFilePayload({ content: "<p>ok</p>", format: "docx" }), | ||
| null | ||
| ); | ||
| }); | ||
|
|
||
| runTest("export default names are sanitized to a base filename", () => { | ||
| assert.equal(safeExportBaseName("../notes:bad?.html"), "notes-bad-"); | ||
| assert.equal(safeExportBaseName(""), "Exported"); | ||
| }); |
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
Validation