8000 fix: confine inline file attachments to working directory (path traversal) by eLyiN · Pull Request #9 · eLyiN/gemini-bridge · GitHub
[go: up one dir, main page]

Skip to content

fix: confine inline file attachments to working directory (path traversal) - #9

Merged
eLyiN merged 2 commits into
masterfrom
fix/inline-path-traversal
Jun 9, 2026
Merged

eLyiN merged 2 commits into
masterfrom
fix/inline-path-traversal

Conversation

@eLyiN
@eLyiN eLyiN commented Jun 9, 2026
Copy link
Copy Markdown
Owner

Summary

Fixes an arbitrary local file read in consult_gemini_with_files inline mode (CWE-22 / CWE-200). A caller-supplied files entry was read with no working-directory confinement and its contents forwarded to the Gemini CLI; since the caller also controls query, the file could be echoed back through the round-trip.

The at_command mode already confined paths — inline mode was missing the same guard.

Changes

  • _resolve_path: resolve symlinks for both the root and the candidate, then confine via relative_to(root). rel_path is None for 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 a Skipped file outside working directory warning (the guard at_command already had) — no read.
  • Regression tests: absolute-outside, .. traversal, and symlink escape are rejected (content not forwarded); absolute-inside still works.
  • CHANGELOG + tool docstring updated; version bumped to 1.3.1.

Behavior change

at_command mode 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).

eLyiN added 2 commits June 9, 2026 21:30
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).
@eLyiN
eLyiN merged commit 8f3b85a into master Jun 9, 2026
4 checks passed
@eLyiN
eLyiN deleted the fix/inline-path-traversal branch June 9, 2026 19:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

0