Skip to content

fix: validate MCP batch handler array elements at boundary#463

Merged
xiaolai merged 1 commit intomainfrom
fix/459-validate-mcp-batch-casts
Mar 18, 2026
Merged

fix: validate MCP batch handler array elements at boundary#463
xiaolai merged 1 commit intomainfrom
fix/459-validate-mcp-batch-casts

Conversation

@claude
Copy link
Contributor

@claude claude bot commented Mar 18, 2026

Summary

  • Add requireTypedArray<T> helper to validateArgs.ts that validates each array element with a custom validator function, producing clear indexed error messages (e.g., "invalid operation at index 2: missing required field 'type'")
  • Replace unsafe as BatchOperation[], as TableOperation[], and as ListOperation[] casts in batchEditHandler.ts and batchOpHandlers.ts with element-level validation
  • Replace requireString(...) as ParagraphOperation in paragraphHandlers.ts with requireEnum for proper enum validation
  • Update existing tests to match the new earlier-rejection behavior

Closes #459

Test plan

  • New requireTypedArray tests pass (valid input, invalid element, non-array input, empty array)
  • Updated batchOpHandlers tests verify malformed operations are rejected with clear error messages
  • Updated paragraphHandlers test verifies invalid operation enum is rejected
  • pnpm check:all passes (lint + coverage + build)

🤖 Generated with Claude Code

Replace unsafe `as` casts on external MCP input with runtime element
validation using a new `requireTypedArray` helper. Also replace
`requireString(...) as ParagraphOperation` with `requireEnum` for
proper enum validation.

Closes #459

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@claude claude bot enabled auto-merge (squash) March 18, 2026 09:51
@xiaolai xiaolai merged commit 6fde9fb into main Mar 18, 2026
3 checks passed
@xiaolai xiaolai deleted the fix/459-validate-mcp-batch-casts branch March 20, 2026 22:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[audit] type-safety: unvalidated as casts on external MCP input in batch handlers

1 participant