ClawWork icon indicating copy to clipboard operation
ClawWork copied to clipboard

[Bug] debug:renderer-event accepts arbitrary domain via lying type assertion

Open samzong opened this issue 7 months ago • 2 comments

Problem

The debug:renderer-event IPC handler accepts a domain field from the renderer and forwards it to the logger via a type assertion as 'renderer'. The cast is a lie — at runtime, payload.domain is whatever string the renderer sent, not necessarily 'renderer'. This means a renderer can inject debug events under any domain name ('db', 'gateway', 'ws', etc.), polluting main-process debug logs and the getRecentEvents({ domain: [...] }) filter result with events that never actually came from that subsystem. Breaks the trust boundary between main and renderer and makes debugging upstream bugs harder.

Location

File: packages/desktop/src/main/ipc/debug-handlers.ts:9-30

ipcMain.on(
  'debug:renderer-event',
  (_event, payload: {
    domain: string;
    event: string;
    // ...
  }) => {
    const logger = getDebugLogger();
    logger.info({
      domain: (payload.domain || 'renderer') as 'renderer',  // ← lie
      event: payload.event,
      traceId: payload.traceId,
      feature: payload.feature,
      data: payload.data,
    });
  },
);

Fix Approach

Two options:

  1. Simplest: hard-code domain: 'renderer', drop the payload.domain field entirely. The channel name already tells us where the event came from.
  2. If sub-domains within renderer are wanted: keep an explicit whitelist of renderer sub-domains (e.g. 'renderer', 'renderer.settings', 'renderer.chat') and validate against it; otherwise coerce to 'renderer'.

Either way, drop the as 'renderer' cast — it is masking a real runtime contract violation.

Verification

  1. Run pnpm check — must pass.
  2. Unit test: call the IPC with payload.domain = 'db'; assert the persisted event's domain is 'renderer' (or the validated fallback), not 'db'.

Context

  • WG: Observability & DX (security — trust boundary)
  • Priority: Low (good first issue)
  • Estimated effort: 15-20 minutes

samzong avatar Apr 15 '26 09:04 samzong

Hi @samzong, Thanks for opening an issue! We will look into it as soon as possible.

Details

Instructions for interacting with me using comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the gh-ci-bot repository.

github-actions[bot] avatar Apr 15 '26 09:04 github-actions[bot]

The as 'renderer' cast is masking runtime input — I'd just hard-code domain: 'renderer' and drop payload.domain entirely, since the IPC channel name already tells us where the event came from. Sending a fix.

JasmineLCY avatar Apr 15 '26 10:04 JasmineLCY