Skip to content

fix(security): validate --upload and --output file paths#374

Open
AshwinRenjith wants to merge 4 commits intogoogleworkspace:mainfrom
AshwinRenjith:ashwin/codex/pr1-path-validation-upload-output
Open

fix(security): validate --upload and --output file paths#374
AshwinRenjith wants to merge 4 commits intogoogleworkspace:mainfrom
AshwinRenjith:ashwin/codex/pr1-path-validation-upload-output

Conversation

@AshwinRenjith
Copy link

Harden file path handling for untrusted CLI inputs by adding safe upload/output validators and enforcing them centrally in execute_method.

Covers traversal, absolute paths, control characters, and symlink escapes before any file I/O. Adds regression tests and required changeset.

Description

This PR fixes a filesystem trust-boundary gap where untrusted CLI path inputs (--upload, --output) could be consumed directly for file I/O.

Changes:

  • Added validate_safe_upload_file_path and validate_safe_output_file_path in src/validate.rs.
  • Enforced both validators centrally in src/executor.rs::execute_method, so all command paths (including helpers) are covered.
  • Added regression tests for traversal, absolute paths, control characters, and symlink-escape cases.
  • Added required changeset: .changeset/hardening-upload-output-paths.md.

Dry Run Output (--output safe path):

{
  "body": null,
  "dry_run": true,
  "is_multipart_upload": false,
  "method": "GET",
  "query_params": {},
  "url": "https://www.googleapis.com/drive/v3/files"
}

Dry Run Output (--upload safe path):

{
  "body": null,
  "dry_run": true,
  "is_multipart_upload": true,
  "method": "POST",
  "query_params": {},
  "url": "https://www.googleapis.com/upload/drive/v3/files"
}

Checklist:

  • My code follows the AGENTS.md guidelines (no generated google-* crates).
  • I have run cargo fmt --all to format the code perfectly.
  • I have run cargo clippy -- -D warnings and resolved all warnings.
  • I have added tests that prove my fix is effective or that my feature works.
  • I have provided a Changeset file (e.g. via pnpx changeset) to document my changes.

@changeset-bot
Copy link

changeset-bot bot commented Mar 10, 2026

🦋 Changeset detected

Latest commit: 6eaa5ad

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@googleworkspace/cli Patch

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

@google-cla
Copy link

google-cla bot commented Mar 10, 2026

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.

@googleworkspace-bot googleworkspace-bot added area: http area: core Core CLI parsing, commands, error handling, utilities labels Mar 10, 2026
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, 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 significantly improves the security posture of the application by implementing robust validation for user-provided file paths. It addresses a potential trust-boundary gap by ensuring that paths specified via --upload and --output CLI arguments are safe and do not lead to unintended file system access or manipulation. The changes centralize path validation and include comprehensive tests to prevent common file system attacks.

Highlights

  • Enhanced File Path Validation: Introduced new validation functions (validate_safe_upload_file_path and validate_safe_output_file_path) to rigorously check --upload and --output CLI file paths for security vulnerabilities.
  • Centralized Enforcement: Integrated the new path validators into the execute_method function in src/executor.rs, ensuring all command paths are securely handled before any file I/O operations.
  • Robust Security Checks: The validation logic now explicitly rejects absolute paths, prevents directory traversal, and guards against symlink escapes, along with checking for control characters.
  • Comprehensive Regression Tests: Added new #[tokio::test] cases to verify that unsafe upload and output paths are correctly rejected, covering various attack vectors.
  • Changelog Entry: A new changeset file (.changeset/hardening-upload-output-paths.md) was added to document the security hardening for file path handling.
Changelog
  • .changeset/hardening-upload-output-paths.md
    • Harden --upload and --output path handling by validating file paths against traversal, absolute paths, control characters, and symlink escape before any file I/O.
Activity
  • No human activity has been recorded on this pull request yet.
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 👍 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

  1. Review the Generative AI Prohibited Use Policy, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces important security validations for file paths provided via --upload and --output. However, the validation logic for output files is vulnerable to a bypass using broken symbolic links, which could allow an attacker to write files outside the current directory. Additionally, a critical Time-of-check to Time-of-use (TOCTOU) race condition vulnerability exists in the new validation logic, potentially allowing unintended file access. The new validation functions also perform blocking I/O within an async context, which may impact performance and stability.

@github-actions
Copy link
Contributor

/gemini review

1 similar comment
@github-actions
Copy link
Contributor

/gemini review

@github-actions
Copy link
Contributor

/gemini review

Harden file path handling for untrusted CLI inputs by adding safe upload/output validators and enforcing them centrally in execute_method.

Covers traversal, absolute paths, control characters, and symlink escapes before any file I/O. Adds regression tests and required changeset.
Address broken symlink prefix bypass in output path validation by using symlink-aware normalization and canonicalization.

Also run path validators via spawn_blocking in execute_method to avoid blocking filesystem checks on async runtime threads. Adds regression coverage for broken symlink prefixes.
Disallow existing FIFO/special-file paths for --output so untrusted CLI inputs cannot redirect writes to non-regular sinks. Adds unix regression test for FIFO target rejection.
@AshwinRenjith AshwinRenjith force-pushed the ashwin/codex/pr1-path-validation-upload-output branch from 7ec989e to 6eaa5ad Compare March 10, 2026 15:47
@github-actions
Copy link
Contributor

/gemini review

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: core Core CLI parsing, commands, error handling, utilities area: distribution area: http

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants