gemini-cli icon indicating copy to clipboard operation
gemini-cli copied to clipboard

fix(core): Refactor Agent Input Validation to use JSON Schema

Open jonathanh1 opened this issue 11 months ago • 1 comments

Summary

Refactors agent input validation to use standard JSONSchema7, enabling support for complex inputs (nested objects, oneOf, enum), and patches a path-traversal vulnerability in the restore command.

Details

This PR addresses #14857 by replacing the custom agent input type system with standard JSON Schema validation using AJV.

Implementation Plan Completed:

  • [x] Extend SchemaValidator with validateSchema() method
  • [x] Update type definitions with InputConfigNew (JSONSchema7)
  • [x] Refactor DelegateToAgentTool to consume JSON Schema directly
  • [x] Implement oneOf schema generation for multi-agent selection

Migration Checklist:

  • [x] Add validateSchema to SchemaValidator
  • [x] Update InputConfig interface (backward compatible)
  • [x] Refactor DelegateToAgentTool
  • [x] Update CodebaseInvestigatorAgent to new schema format
  • [x] Verify validation occurs at registration time

Design Decision: Chose a union type approach (InputConfigNew | InputConfigLegacy) instead of direct replacement to enable gradual migration without breaking existing agents.

Additional: Patched path-traversal vulnerability in packages/cli/src/commands/restore.ts

Related Issues

Closes #14857
Related to #3132

How to Validate

1. Run Unit Tests

npm run test:ci -w @google/gemini-cli-core

Key test files to review:

  • delegate-to-agent-tool.test.ts — oneOf schema, enum validation
  • schemaValidator.test.ts — validateSchema() method
  • codebase-investigator.test.ts — JSONSchema7 migration

2. Test Results

Test results

3. Verify Security Fix

Attempt to traverse paths with the restore command (must fail):

gemini restore ../.env

Expected: Error or refusal to load file outside checkpoint directory

Pre-Merge Checklist

  • [x] Updated relevant documentation and README (if needed)
  • [x] Added/updated tests (if needed)
  • [x] Noted breaking changes (if any): None — backward compatible via union type
  • [x] Validated on required platforms/methods:
    • [x] MacOS
      • [x] npm run
      • [ ] npx
      • [ ] Docker
      • [ ] Podman
      • [ ] Seatbelt
    • [ ] Windows
      • [ ] npm run
      • [ ] npx
      • [ ] Docker
    • [ ] Linux
      • [ ] npm run
      • [ ] npx
      • [ ] Docker

jonathanh1 avatar Dec 13 '25 00:12 jonathanh1

Summary of Changes

Hello @jonathanh1, I'm Gemini Code Assist[^1]! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the agent input validation system by migrating from a custom type system to the industry-standard JSON Schema (draft-07). This change allows for more robust and flexible input definitions, supporting complex data structures and validation rules. Alongside this core refactor, a critical path-traversal vulnerability in the restore command has been addressed, improving security. The update also introduces a new, centralized configuration mechanism for agents, providing finer control over their behavior and enabling dynamic tool schema generation based on agent enablement.

Highlights

  • Agent Input Validation Refactor: Replaced the custom agent input validation system with standard JSON Schema (draft-07) using AJV, enabling support for complex input types like nested objects, 'oneOf', and 'enum'.
  • Backward Compatibility: Implemented a union type (InputConfigNew | InputConfigLegacy) for agent input configurations, allowing for gradual migration of existing agents without introducing breaking changes.
  • Path Traversal Vulnerability Fix: Patched a path-traversal vulnerability in the restore command by validating requested files against the checkpoint directory's contents, preventing access to arbitrary file paths.
  • Dynamic Agent Tool Schema Generation: The DelegateToAgentTool now dynamically generates its tool schema based on enabled agents, supporting 'oneOf' for multiple agent selections and automatically excluding disabled agents.
  • Enhanced Agent Configuration: Introduced a new agents section in settings.json for granular control over individual agent settings (e.g., enabled, model, maxTimeMinutes, maxTurns, thinkingBudget), with these new settings taking precedence over legacy configurations.
  • Schema Validation Utility: Added a validateSchema method to the SchemaValidator to ensure the structural validity of JSON Schema definitions themselves at registration time, catching configuration errors early.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with :thumbsup: and :thumbsdown: on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

[^1]: Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

gemini-code-assist avatar Dec 13 '25 00:12 gemini-code-assist

Hey thanks for the contribution! This issue was resolved already since it was on a critical path for maintainers. Going to mark this as closed

abhipatel12 avatar Jan 23 '26 17:01 abhipatel12