Skip to content

Security Issue - Lifecycle Script Execution via .opencode/package.json #7173

Closed

Description

@xpcmdshell

Description

Description

opencode-lifecycle-rce

OpenCode automatically runs bun install in any .opencode directory found in the current project at startup. This executes preinstall/postinstall scripts defined in .opencode/package.json without user confirmation. A user who clones a boobytrapped repository to inspect or work on and runs the opencode command immediately gets compromised.

The root cause is in packages/opencode/src/config/config.ts - the installDependencies() function runs bun install in each .opencode directory:

await BunProc.run(["install"], { cwd: dir }).catch(() => {})

If an attacker includes a .opencode/package.json with lifecycle scripts, they execute automatically:

{"scripts":{"preinstall":"id > /tmp/pwned.txt"}}

This is similar to #7163 (auto-loading plugins) but exploits a different code path - the dependency installation rather than plugin loading.

Plugins

N/A

OpenCode version

1.1.4

Steps to reproduce

git clone https://github.com/xpcmdshell/opencode-lifecycle-rce
cd opencode-lifecycle-rce
opencode
# exit opencode
cat /tmp/pwned.txt

(see linked repo)

Screenshot and/or share link

No response

Operating System

No response

Terminal

No response

Plugins

No response

OpenCode version

No response

Steps to reproduce

No response

Screenshot and/or share link

No response

Operating System

No response

Terminal

No response

Activity

  1. github-actions commented on Jan 7, 2026

    @github-actions
    Contributor

    This issue might be a duplicate of existing issues. Please check:

    Feel free to ignore if this specific lifecycle script execution path needs separate handling from the plugin loading mechanism.

  2. CyberShadow commented on Feb 13, 2026

    @CyberShadow

    @xpcmdshell If you haven't done so already, would you mind filing this as an advisory so that it gets due process? https://github.com/anomalyco/opencode/security/advisories/new

  3. xpcmdshell commented on Feb 16, 2026

    @xpcmdshell
    Author

    Submitted each advisory, will await review

  4. github-actions commented on Apr 18, 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.

  5. xpcmdshell commented on Apr 18, 2026

    @xpcmdshell
    Author

    Looks like this might have been fixed as a side effect of a different refactor?

    629e866

    Both filed advisories were closed by maintainers though

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

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions