Skip to content

[Security] Validate input length on content field in AI tool calls #522

Description

@Somil450

Problem

The content field passed to edit_file and edit_multiple_files AI tools in app/api/chat/route.ts has no length validation. An adversarial or runaway AI response could craft an unbounded payload, causing high memory usage, slow response times, or triggering provider timeouts.

Proposed Fix

Add Zod schema validation before processing tool calls:

const editSchema = z.object({
  path: z.string().max(500),
  content: z.string().max(500_000), // 500KB max per file
});

Also consider:

  • Rejecting requests with a total body size above a configurable threshold (e.g., 2MB)
    • Returning a 413 Payload Too Large status when limits are exceeded

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions