Skip to content

Reject paths outside the repo root in repo drivers and AI file tools - #9723

Open
nishantmonu51 wants to merge 3 commits into
mainfrom
ai_file_tools_scoping
Open

Reject paths outside the repo root in repo drivers and AI file tools#9723
nishantmonu51 wants to merge 3 commits into
mainfrom
ai_file_tools_scoping

Conversation

@nishantmonu51

Copy link
Copy Markdown
Collaborator

The AI file tools (read_file, write_file, develop_file) and the runtime's file APIs passed caller-supplied paths straight to repo.Get/Put/Delete, where both the file and admin drivers joined them onto the repo root with no containment check. A path with .. segments (e.g. /models/../../../../etc/passwd) could therefore read, write, or delete files outside the project root.

  • Adds drivers.ResolveRepoPath, which resolves a repo-relative path against the root and errors if the result escapes it. Both repo drivers now use it everywhere they previously did filepath.Join(root, path) (Get, Hash, Stat, Put, MkdirAll, Rename, Delete).
  • The AI file tools additionally reject paths containing .. segments up front, so the model gets a clear error instead of a filesystem error.
  • Adds unit tests for ResolveRepoPath, traversal assertions in the shared repo driver test suite, and traversal cases for the read_file and write_file tools.

Checklist:

  • Covered by tests
  • Ran it and it works as intended
  • Reviewed the diff before requesting a review
  • Checked for unhandled edge cases
  • Linked the issues it closes
  • Checked if the docs need to be updated. If so, create a separate Linear DOCS issue
  • Intend to cherry-pick into the release branch
  • I'm proud of this work!

@nishantmonu51

Copy link
Copy Markdown
Collaborator Author

@codex: review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: fc3a9b7d0a

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread runtime/drivers/repo.go
@nishantmonu51 nishantmonu51 added Type:Bug Something isn't working Size:M Medium change: 100-499 lines labels Jul 23, 2026
@nishantmonu51
nishantmonu51 requested a review from k-anshul July 28, 2026 11:44
@nishantmonu51

Copy link
Copy Markdown
Collaborator Author

@begelundmuller @k-anshul : can one of you review this ?

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

Labels

Size:M Medium change: 100-499 lines Type:Bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant