Skip to content

CRITICAL BUG: Unset $env:*/* may silently expand to drive root and BYPASS external_directory permission, causing entire windows drive got destroyed #24468

Closed as not planned

Description

@wiryls

Description

When using $env:WorkDir in PowerShell commands (e.g. Remove-Item -Recurse -Force $env:WorkDir\*), if the environment variable is not set, it resolves to an empty string. This causes the path to become \* which targets the root of the current drive, potentially wiping all user files on that drive.

opencode's external_directory protection is designed to confine file operations to a designated workspace directory. However, this safeguard is completely bypassed if using $env:WorkDir\*.

In the incident, my D: drive was completely wiped because the command operated at D:\* instead of the intended subdirectory, with zero interference from the external_directory guard.

Plugins

None

OpenCode version

1.14.25

Steps to reproduce

  1. Ensure $env:WorkDir is not set in the PowerShell session.
  2. Ask your model run the command: Remove-Item -Recurse -Force $env:WorkDir\*. (Direct requests may be rejected, requiring adjustments to prompt words or more attempts.)
  3. Observe that the command runs without interception.

Operating System

Windows 11

Terminal

Windows Terminal

Activity

  1. added
    coreAnything pertaining to core functionality of the application (opencode server stuff)
    on Apr 26, 2026
  2. github-actions commented on Apr 26, 2026

    @github-actions
    Contributor

    This issue might be related to existing issues about external_directory permission bypasses. Please check:

    Your report describes a distinct vector (unset PowerShell environment variable expanding to drive root), so this may warrant its own fix, but the above issues share context and may be worth referencing.

  3. removed
    bugSomething isn't working
    coreAnything pertaining to core functionality of the application (opencode server stuff)
    on May 3, 2026
  4. github-actions commented on Jul 4, 2026

    @github-actions
    Contributor

    To stay organized issues are automatically closed after 60 days of no activity. If the issue is still relevant please open a new one.

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