Skip to content

[codex] Harden IPC payload validation - #96

Open
bendsp wants to merge 2 commits into
codex/editor-quality-passfrom
codex/feature-ipc-path-hardening
Open

[codex] Harden IPC payload validation#96
bendsp wants to merge 2 commits into
codex/editor-quality-passfrom
codex/feature-ipc-path-hardening

Conversation

@bendsp

@bendsp bendsp commented May 9, 2026

Copy link
Copy Markdown
Owner

Summary

  • add pure validation for save/export IPC payloads before main-process handlers act on renderer input
  • reject malformed save paths, unsupported export formats, and oversized content consistently
  • sanitize export default filenames down to safe base names and cover validation behavior with unit tests

Validation

  • pnpm lint
  • pnpm typecheck
  • pnpm test:unit
  • pnpm test:e2e

Copilot AI review requested due to automatic review settings May 9, 2026 14:33

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.ts with size checks, payload normalizers, and export filename sanitization.
  • Updated main-process IPC handlers (file:save, file:export) to accept unknown and 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 thread src/main/index.ts Outdated
Comment on lines 282 to 285
const payload = normalizeSaveFilePayload(args);
if (!payload) {
throw new Error("Invalid save payload.");
}
Comment thread src/main/index.ts
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 thread src/main/index.ts Outdated
Comment on lines 399 to 402
const payload = normalizeExportFilePayload(args);
if (!payload) {
throw new Error("Invalid export payload.");
}
Comment thread src/main/index.ts
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 thread src/main/ipcValidation.ts
Comment on lines +29 to +35
if (
"filePath" in payload &&
payload.filePath !== undefined &&
(typeof payload.filePath !== "string" || payload.filePath.trim() === "")
) {
return null;
}
Comment thread src/main/ipcValidation.ts
Comment on lines +58 to +64
if (
"defaultFileName" in payload &&
payload.defaultFileName !== undefined &&
typeof payload.defaultFileName !== "string"
) {
return null;
}
Comment thread src/main/ipcValidation.ts Outdated
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");
});
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.

2 participants