background-agents icon indicating copy to clipboard operation
background-agents copied to clipboard

fix(types): validate session lifecycle boundaries

Open open-inspect opened this issue 4 months ago • 1 comments

This is an automated nightly unsafe-cast remediation sweep. It replaces uncovered high-risk control-plane session request-boundary assertions with parse-don't-assert validation, following the TypeScript Coding Standards unsafe-cast / parse-don't-assert guidance and the Zod boundary-validation pattern established in PR #807.

file:line risk cast removed how it was fixed
packages/control-plane/src/session/http/handlers/session-lifecycle.handler.ts:124 HIGH (await request.json()) as InitRequest for internal session initialization feeding session state, participant creation, repository context, and SCM token persistence Added a package-local Zod initRequestSchema with z.infer as the request type; nullable upstream fields are modeled with .nullable() and invalid bodies return the existing 400-style bad-request response.
packages/control-plane/src/session/http/handlers/session-lifecycle.handler.ts:264,306,333 HIGH parseUserIdBody(body) as { userId?: string } and (await request.json()) as { userId?: string; title?: string } for title/archive/unarchive authorization request bodies Added package-local Zod schemas and safeParse at the request boundary; invalid JSON still returns Invalid request body, while missing/invalid user IDs preserve the existing userId is required path.
packages/control-plane/src/session/http/handlers/child-sessions.handler.ts:140 HIGH `(await request.json()) as { childSessionId: string; status: SessionStatus; title: string null }` for child-session status broadcasts

Verification

command result
npm run format Passed
npm run build -w @open-inspect/shared Passed
npm run build -w @open-inspect/control-plane Passed
npm run typecheck Passed
npm run lint Passed after temporarily moving the unrelated pre-existing untracked .opencode/ tooling directory out of the workspace and restoring it immediately; without that, ESLint lints the untracked tooling and fails on its globals.
npm test -w @open-inspect/control-plane -- src/session/http/handlers/session-lifecycle.handler.test.ts src/session/http/handlers/child-sessions.handler.test.ts Passed: 2 files, 45 tests
npm test -w @open-inspect/control-plane Passed: 91 files, 1524 tests
npm run typecheck -w @open-inspect/control-plane Passed post-commit
npm run lint -w @open-inspect/control-plane Passed post-commit

References: TypeScript Coding Standards unsafe-cast / parse-don't-assert guidance; Zod boundary-validation pattern established in PR #807.


Created with Open-Inspect

open-inspect avatar Jul 07 '26 06:07 open-inspect

Terraform Validation Results

Step Status
Format ✅
Init ✅
Validate ✅

Note: Terraform plan was skipped because secrets are not configured. This is expected for external contributors. See docs/GETTING_STARTED.md for setup instructions.

Pushed by: @open-inspect[bot], Action: pull_request

github-actions[bot] avatar Jul 07 '26 06:07 github-actions[bot]