Skip to content

[bug] Glob and Grep tools allow directory traversal outside Location boundary #33070

Closed as not planned

Description

Description

The Glob tool (packages/core/src/tool/glob.ts, line ~57-58) and Grep tool (packages/core/src/tool/grep.ts, line ~78) accept an optional path parameter that is passed directly to path.resolve(location.directory, input.path ?? ".") without validating whether the resolved path escapes the active Location directory.

Unlike the Read tool which uses FSUtil.contains to restrict file access within the Location boundary, Glob and Grep have no such check. The permission assertion only validates the search pattern, not the search path.

Code location

Steps to reproduce

  1. Open a session in any project directory
  2. Call glob({ pattern: "*", path: "../../../etc" })
  3. The tool returns file listings from outside the Location boundary
  4. Same for grep({ pattern: ".", path: "../../../etc" })

Expected behavior

Glob and Grep should reject paths that escape the active Location, matching the behavior of the Read tool which uses FSUtil.contains.

Environment

OpenCode Desktop 1.17.8, Windows 11

Activity

  1. Necmttn commented on Jun 21, 2026

    @Necmttn

    Glob/Grep should share the same location-boundary check as Read. Resolve the requested path, canonicalize symlinks where possible, and reject any search root outside the active Location unless the user grants an explicit broader scope.

    The tool result should distinguish "no matches" from "search root rejected." Regression cases: .. traversal, symlink escape, absolute path outside workspace, allowed subdirectory, and Windows drive-letter/case variants. Search tools are read tools, but they still expose filesystem contents.


    Generated with ax.

  2. rekram1-node commented on Jun 22, 2026

    @rekram1-node
    Contributor

    STOP SPAMMING ISSUES.

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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions