Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions src/main/ipc/device.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@ import {

import { listDeviceProfiles, addDevice } from '@main/roms/romDatabase';
import { devices } from '@main/db/queries';
import type { Device } from '@/types/device';

export function registerDeviceIpc() {
ipcMain.handle('device:list', () => devices.list());
ipcMain.handle('device:listStorage', listStorage);
ipcMain.handle('device:listProfiles', listDeviceProfiles);
ipcMain.handle('device:create', (_, data) => addDevice(data));
ipcMain.handle('device:remove', (_, id) => removeDevice(id));
ipcMain.handle('device:update', (_, id, data) => updateDevice(id, data));
ipcMain.handle('device:checkDeviceMount', (_, deviceId) => checkDeviceMount(deviceId));
ipcMain.handle('device:create', (_, data: Device) => addDevice(data));
ipcMain.handle('device:remove', (_, id: string) => removeDevice(id));
ipcMain.handle('device:update', (_, id: string, data: Partial<Device>) => updateDevice(id, data));
ipcMain.handle('device:checkDeviceMount', (_, deviceId: string) => checkDeviceMount(deviceId));
Comment on lines +18 to +21

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.

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 / especially Partial<Device> is quite permissive for an externally-provided input.

Consider validating and narrowing IPC payloads (and ideally using input types like DeviceCreateInput / DeviceUpdateInput that 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:

  • Define schemas/types for IPC inputs (create/update) rather than using Device/Partial<Device>.
  • Parse inside the handler before calling services.
import { z } from 'zod';

const DeviceCreateSchema = z.object({
  // only the fields you actually accept from the renderer
  name: z.string(),
  // ...
});

type DeviceCreateInput = z.infer<typeof DeviceCreateSchema>;

ipcMain.handle('device:create', (_e, data: unknown) => {
  const input: DeviceCreateInput = DeviceCreateSchema.parse(data);
  return addDevice(input);
});

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.

ipcMain.handle('device:uploadProfile', uploadProfile);
}
2 changes: 1 addition & 1 deletion src/main/ipc/sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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

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.

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 startSync assumes invariants (non-empty tagIds, allowed option values, etc.), it’s safer to enforce them at the handler boundary and fail fast with a clear error.

Suggestion

Validate IPC inputs before calling startSync, even if it’s just minimal guards (or ideally a schema).

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 sync:start.

ipcMain.handle('sync:cancel', cancelSync);
Expand Down