fix: fail closed on malformed tool confirmation payloads#4644
fix: fail closed on malformed tool confirmation payloads#4644yuvrajangadsingh wants to merge 3 commits intogoogle:mainfrom
Conversation
Use strict=True in ToolConfirmation.model_validate() so that non-boolean values like "yes", 1, or "true" for the confirmed field are rejected instead of silently coerced to True. Malformed or unparseable payloads now fall through to a catch block that logs a warning and defaults to confirmed=False. Fixes google#4576
Summary of ChangesHello, I'm Gemini Code Assist1! 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 addresses a potential security vulnerability where lax Pydantic validation could inadvertently allow tool execution due to silent coercion of malformed boolean confirmation payloads. By enforcing strict validation and implementing robust error handling, the system now defaults to denying tool execution for any invalid confirmation input, ensuring a "fail-closed" security posture and preventing unintended actions. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
Using Gemini Code AssistThe 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
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 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 👍 and 👎 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. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request addresses a security concern by enforcing strict validation on tool confirmation payloads, preventing accidental tool execution from malformed data. The change to use strict=True with Pydantic's model_validate and wrapping the parsing in a try/except block to fail-closed is a solid improvement. The new tests effectively cover various malformed payload scenarios. I have one suggestion to make the exception handling more specific to improve maintainability.
|
@gemini-code-assist addressed your review, narrowed the except to |
There was a problem hiding this comment.
Code Review
This pull request correctly addresses a security vulnerability by enforcing strict validation on tool confirmation payloads, preventing type coercion that could lead to unintended tool execution. The implementation adds strict=True to Pydantic's model_validate and introduces a try/except block to gracefully handle malformed data, defaulting to a safe "fail-closed" state. The accompanying tests are thorough and cover the relevant edge cases. I've provided one suggestion to refactor the payload validation logic for improved readability and maintainability.
|
/gemini review |
There was a problem hiding this comment.
Code Review
The pull request effectively addresses the identified vulnerability where Pydantic's lax mode could lead to accidental tool execution due to malformed confirmation payloads. By introducing "strict=True" in "model_validate()" and wrapping the parsing in a try/except block, the system now correctly rejects invalid inputs and defaults to "confirmed=False", ensuring a "fail closed" approach. The addition of comprehensive parameterized tests further strengthens the robustness of this fix.
Fixes #4576
ToolConfirmation.model_validate()was running in Pydantic's default lax mode, which silently coerces values like"yes",1, and"true"toTruefor boolean fields. This means a malformed confirmation payload could accidentally grant tool execution permission.This PR adds
strict=Trueto bothmodel_validate()call sites and wraps the parsing in a try/except. If the payload is malformed or can't be parsed, it logs a warning and defaults toconfirmed=False— fail closed instead of fail open.Changes
request_confirmation.py: addedstrict=Truetomodel_validate(), wrapped in try/except with fallback toconfirmed=Falsetest_request_confirmation.py: added 6 parametrized test cases covering"yes",1,"true"(both wrapped in JSON response key and direct), and invalid JSONTest plan