-
-
Notifications
You must be signed in to change notification settings - Fork 4
Add type annotations to IPC handler parameters #179
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,7 +19,7 @@ let syncCancelled = false; | |
|
|
||
| //=== PUBLIC API === | ||
| export function registerSyncIpc() { | ||
| ipcMain.handle('sync:start', (_, tagIds, deviceId, options) => | ||
| ipcMain.handle('sync:start', (_, tagIds: string[], deviceId: string, options: SyncOptions) => | ||
| startSync(tagIds, deviceId, options) | ||
| ); | ||
|
Comment on lines
+22
to
24
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same concern here: the new types improve readability and catch mistakes in main-process call sites, but they don’t validate what arrives over IPC. If SuggestionValidate IPC inputs before calling ipcMain.handle('sync:start', (_e, tagIds: unknown, deviceId: unknown, options: unknown) => {
if (!Array.isArray(tagIds) || !tagIds.every((t) => typeof t === 'string')) throw new Error('Invalid tagIds');
if (typeof deviceId !== 'string') throw new Error('Invalid deviceId');
// validate options similarly (or use a schema)
return startSync(tagIds, deviceId, options as SyncOptions);
});Reply with "@CharlieHelps yes please" if you'd like me to add a commit that introduces a small schema/guard layer for |
||
| ipcMain.handle('sync:cancel', cancelSync); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These annotations help at compile time, but they don’t protect the IPC trust boundary at runtime. A compromised/buggy renderer can still send arbitrary payloads, and
Device/ especiallyPartial<Device>is quite permissive for an externally-provided input.Consider validating and narrowing IPC payloads (and ideally using input types like
DeviceCreateInput/DeviceUpdateInputthat only include fields you actually accept) before forwarding into the service layer.Suggestion
Add runtime validation (e.g., Zod) + tighten accepted input shapes. For example:
Device/Partial<Device>.Reply with "@CharlieHelps yes please" if you'd like me to add a commit with a minimal validation + input-type tightening pass for these handlers.