Gemini CLI path guard flaw: prefix check lets sibling dirs bypass docs sandbox

ranjan-del · ghdev · 2026-09-09

A P1 PR against google-gemini/gemini-cli fixes a path traversal bypass in the getinternaldocs tool: its guard used a string startsWith check on the resolved path, so a request like ../docs-private/secret.md still shared the <repo>/docs prefix and passed, letting the tool read sibling directories' files and return them to the model.

The fix swaps in the repo's existing isSubpath() helper, which uses path.relative() for component-boundary-aware comparison and handles case-insensitive filesystems on Windows/macOS. The original test only exercised ../package., which never shared the prefix, so the sibling-prefix case was never covered; the new test creates a real sibling directory and asserts denial. The tool is read-only, limiting severity.

Original post →

More from coding & agent

coding & agent channel →