fix(security): validate resource IDs in docs, sheets, calendar, and drive helpers#677
Conversation
🦋 Changeset detectedLatest commit: 86b5efa The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
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 introduces security enhancements to the CLI by enforcing strict validation on resource identifiers before they are used in API requests. By integrating the existing Highlights
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. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request implements resource ID validation across several Google Workspace CLI helpers (Calendar, Docs, Drive, and Sheets) to mitigate path traversal and injection risks. The review feedback highlights the importance of using the validated (and potentially normalized) output from the validation function rather than the original input. Additionally, it is recommended to extend this validation to the range parameter in Sheets requests, as it is also utilized as a path segment in API calls.
|
bot: rescan |
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request implements resource ID validation across the Calendar, Docs, Drive, and Sheets helpers using validate_resource_name() to mitigate path traversal and injection risks. Feedback indicates that applying this specific validation to calendar_id and Sheets range parameters is likely to cause regressions, as these fields frequently contain characters (like "@", ".", "!", and ":") that the validator may reject.
…rive helpers Adds validate_resource_name() calls before embedding user-supplied IDs in API request params. Rejects path traversal, control characters, and URL injection via ?, #, and % characters — consistent with AGENTS.md requirements for AI-agent-safe input handling. Affected helpers: - docs +write: --document - sheets +append and +read: --spreadsheet - calendar +insert: --calendar - drive +upload: --parent Includes rejection tests for traversal and query injection in each helper.
…ange
- drive: use the &str returned by validate_resource_name(parent)? directly
in json! rather than the original untrusted input
- sheets: validate config.range in both build_append_request and
build_read_request, since the range is used as a URL path segment in the
Sheets API (spreadsheets/{id}/values/{range})
03c5706 to
c8a5fa1
Compare
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request implements resource ID validation across the Calendar, Docs, Drive, and Sheets helpers to mitigate risks from path traversal and injection attacks. The changes introduce calls to validate_resource_name before resource IDs are used in API requests and include corresponding unit tests. Review feedback highlights an inconsistency in the Sheets helper where the return values of the validation function are ignored, potentially bypassing normalization or sanitization steps that are correctly handled in the other service helpers.
…ressions; use validated spreadsheet_id - calendar_id can be an email address (user@example.com) so validate_resource_name would incorrectly reject valid inputs; revert to plain unwrap - range in Sheets A1 notation (e.g. Sheet1!A1) contains ! and : which are rejected by validate_resource_name; remove range validation from both build functions - capture and use the return value of validate_resource_name for spreadsheet_id so any normalization is applied to the actual request params
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces resource ID validation across the Docs, Sheets, Drive, and Calendar helpers to mitigate path traversal and injection risks. While the implementation and tests are present for most modules, the Calendar helper includes a new test case but lacks the actual validation logic in the build_insert_request function, which will lead to test failure.
…_request validate_resource_name only rejects control chars, path traversal, ?, #, and %. It does NOT reject @ or . so email-style calendar IDs (user@example.com) pass validation correctly. The earlier comment to remove it was based on a mistaken assumption about the validator's character set.
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request implements resource ID validation across the Calendar, Docs, Drive, and Sheets helpers to mitigate risks from adversarial AI-agent inputs, such as path traversal and URL injection. The validate_resource_name function is now applied to calendar_id, document_id, parent_id, and spreadsheet_id before they are used in API requests. Corresponding unit tests have been added to ensure that invalid characters and traversal segments are properly rejected. I have no feedback to provide as the implementation is consistent and includes appropriate test coverage.
Description
Adds
validate_resource_name()calls before embedding user-supplied IDs in API request parameters for four helpers that were missing this check. This is required by the AGENTS.md security checklist:Affected helpers:
docs +write—--documentID embedded inbatchUpdateparamssheets +appendand+read—--spreadsheetID embedded invalues.append/values.getparamscalendar +insert—--calendarID embedded inevents.insertparamsdrive +upload—--parentfolder ID embedded infiles.createmetadata bodyvalidate_resource_name()rejects path traversal segments (..), control characters, and URL-special characters (?,#,%) that could be injected by adversarial AI-agent inputs.Dry Run Output:
Checklist:
AGENTS.mdguidelines (no generatedgoogle-*crates).cargo fmt --allto format the code perfectly.cargo clippy -- -D warningsand resolved all warnings.pnpx changeset) to document my changes.