Repository navigation
fix: confine inline file attachments to working directory (path traversal) - #9
Merged
Merged
Conversation
consult_gemini_with_files inline mode read any caller-supplied path (absolute, .. traversal, or symlink escape) and forwarded its contents to the Gemini CLI, allowing arbitrary local file read (CWE-22/CWE-200). Harden _resolve_path to resolve symlinks and confine via relative_to, and apply the same out-of-directory guard inline mode was missing that at_command mode already enforced. Adds regression tests. Reported privately by Zhihao Zhang (WPI).
4 tasks done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes an arbitrary local file read in
consult_gemini_with_filesinline mode (CWE-22 / CWE-200). A caller-suppliedfilesentry was read with no working-directory confinement and its contents forwarded to the Gemini CLI; since the caller also controlsquery, the file could be echoed back through the round-trip.The
at_commandmode already confined paths — inline mode was missing the same guard.Changes
_resolve_path: resolve symlinks for both the root and the candidate, then confine viarelative_to(root).rel_pathisNonefor anything escaping the root (absolute path outside,..traversal, or symlink escape). This hardens both modes consistently._prepare_inline_payload: skip entries that resolve outside the working directory with aSkipped file outside working directorywarning (the guardat_commandalready had) — no read...traversal, and symlink escape are rejected (content not forwarded); absolute-inside still works.Behavior change
at_commandmode now also rejects symlinks that resolve outside the working directory (previously a lexical-only check let them through).Testing
pytest— 38 passed.Reported privately by Zhihao Zhang (WPI).