Conversation
…alidate --upload/--output paths - Cap Retry-After header at 60s to prevent hostile servers from hanging the CLI - Extract compute_retry_delay() with saturating_pow for safe exponential backoff - Sanitize mimeType by stripping control characters to prevent MIME header injection - Add validate_safe_file_path() for --upload and --output path validation - Gate --upload/--output through path validation in main.rs before any I/O Consolidates security fixes from PRs #448 and #447.
🦋 Changeset detectedLatest commit: eca0442 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 |
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 consolidates several security hardening measures to improve the robustness and safety of the CLI. It addresses potential vulnerabilities related to server-controlled retry delays, malicious MIME type injection in uploads, and unsafe file path handling for user-provided Highlights
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
|
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces several important security hardening measures: capping Retry-After sleep times, sanitizing upload MIME types, and validating file paths to prevent directory traversal. The changes are well-tested and significantly improve the tool's robustness. I've identified a critical issue in the MIME type sanitization logic where a refactoring bug could bypass the security fix. I've also noted a potential high-severity TOCTOU race condition in the new path validation logic. My review includes a suggested fix for the critical bug.
- Restructure resolve_upload_mime() using or_else chain so all code paths go through control-char stripping (early returns were bypassing it) - Document TOCTOU limitation in validate_safe_file_path() as known caveat
There was a problem hiding this comment.
Code Review
This pull request introduces several important security hardening measures. It caps the Retry-After duration to prevent denial-of-service, sanitizes MIME types in uploads to prevent header injection, and adds validation for file paths to prevent path traversal. These are all excellent improvements.
My review found one critical security issue related to the new path validation. While the validation logic itself is sound, it's vulnerable to a Time-of-check to time-of-use (TOCTOU) attack because the validated, canonical path is not used for subsequent I/O operations. Please see my detailed comment in src/main.rs.
|
/gemini review |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #523 +/- ##
==========================================
+ Coverage 67.94% 68.11% +0.17%
==========================================
Files 40 40
Lines 17721 17848 +127
==========================================
+ Hits 12040 12158 +118
- Misses 5681 5690 +9 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Code Review
This pull request introduces several important security hardening measures: capping the Retry-After delay, sanitizing upload MIME types to prevent header injection, and validating file paths to prevent directory traversal. The changes for retry capping and MIME type sanitization are well-implemented and include good test coverage.
However, I've identified a critical path traversal vulnerability in the new validate_safe_file_path function. The current implementation can be bypassed with specially crafted paths containing non-existent directories and .. components, allowing file access outside the current working directory. My review includes a detailed comment with a suggested fix for this vulnerability.
… suffix Address review comments: - main.rs: use canonicalized path from validate_safe_file_path for I/O instead of discarding it (closes TOCTOU gap) - validate.rs: add normalize_dotdot() to resolve .. components in non-existent suffix (prevents traversal via doesnt_exist/../../etc/passwd) - Add regression test for non-existent prefix traversal bypass
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces several important security hardening measures. It caps the Retry-After delay to prevent indefinite hangs, sanitizes MIME types in uploads to prevent header injection, and adds robust path validation to guard against directory traversal. The changes are well-structured and include good unit tests.
Summary
Consolidates security hardening from PRs #448 and #447 into a single, well-tested PR. PR #484 (Unicode validation) is already merged.
Changes
1. Cap Retry-After header at 60s (
client.rs)compute_retry_delay()withsaturating_pow(fixes potential overflow from1 << attempt)2. Sanitize mimeType in multipart uploads (
executor.rs)mimeTypeto prevent MIME header injectionapplication/octet-streamif sanitized value is empty3. Validate --upload/--output paths (
validate.rs,main.rs)validate_safe_file_path()rejects traversal, control chars, and symlink escapesmain.rsbefore any I/O occursSupersedes
Test Results
All 660 tests pass. Clippy clean.