Skip to content

pi-permission-system: untyped wire ingestion in readForwardedPermissionRequest and unsafe event object assertions #1069

Open

Description

@mxr576

Package

pi-permission-system

Package version

40.2.0

What happened?

  1. In src/handlers/permission-gate-handler.ts (lines 64–66), toolCallId is extracted using an unsafe double assertion:
const toolCallId =
  typeof (event as Record<string, unknown>).toolCallId === "string"
    ? ((event as Record<string, unknown>).toolCallId as string)
    : "";
  1. In src/authority/forwarding-io.ts (lines 507–535), readForwardedPermissionRequest casts raw JSON.parse output directly to Partial<ForwardedPermissionRequest> and performs manual typeof checks on a subset of fields. Unvalidated fields are passed directly into internal domain models.

Expected behavior

  1. Pi lifecycle events should be inspected with proper type guards (isRecord(event) or standard narrowing).
  2. Wire-level JSON files loaded from the filesystem should be validated with runtime schemas (such as Zod, which is already a core project dependency for config validation) rather than unchecked type assertions.

Suggested remediation

  1. Replace double assertion with a type guard helper:
function hasToolCallId(event: unknown): event is { toolCallId: string } {
  return typeof event === "object" && event !== null && "toolCallId" in event && typeof (event as { toolCallId: unknown }).toolCallId === "string";
}
  1. Introduce a Zod schema for ForwardedPermissionRequest in forwarding-io.ts to guarantee payload integrity and type safety across IPC boundaries.

Additional context

Disclosure: This finding was identified as part of our internal Pi extension evaluation process using the Pi coding agent for review with the following prompt: https://gist.github.com/mxr576/95f403bb5e53bb8ca040f1ec69d83e32

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingpkg:pi-permission-systemIssues related to pi-permission-system

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions