IncidentCoding assistants
OpenCode: a web page could make the coding agent's local server install an attacker's npm package
Christophe Tafani-Dereeper of Datadog Security Labs disclosed on September 24 that a web page could run code on a developer's machine through OpenCode's upgrade endpoint. The local server that opencode serve and opencode web start on 127.0.0.1:4096 parsed the body of /global/upgrade as JSON without checking its content type, so an ordinary page could post a plain-text form to it, and the upgrade accepted a URL as the npm package to install. The attacker's package then ran its preinstall script. It affected OpenCode 1.14.30 through 1.18.21 installed through npm, pnpm or Bun and run without password authentication, or with credentials the browser had cached from a recent sign-in. Reported on August 11, it was fixed in 1.18.22 on August 24, which accepts only version numbers as upgrade targets and checks the content type.
Replay the attack step by step in the Learning Center
How it happened
- The developer runs opencode serve or opencode web, which listens on 127.0.0.1:4096, without a password.
- A malicious web page submits a form with enctype text/plain to /global/upgrade; the handler parsed it as JSON without checking the Content-Type.
- The upgrade passes an attacker-controlled URL to the package manager, and the package's preinstall script runs as the developer.
Impact
Code execution on the developer's machine from a visit to a malicious web page.
The fix
Upgrade OpenCode to 1.18.22 or later, and set a password whenever you run opencode serve or opencode web.
Lessons
- A server on localhost can be reached by every web page you open; local agent servers need authentication and strict content-type checks.
- An upgrade or install endpoint that accepts a URL runs whatever that URL serves.