# OpenCode server's upgrade endpoint let any webpage install an attacker's npm package

Source: https://botpassword.com/incidents/2026-09-opencode-upgrade-endpoint-rce
Disclosed: 2026-09-24 · Type: AI agent · Status: Resolved · Updated: 2026-10-25

Datadog Security Labs and Anomaly disclosed on 24 September 2026 that `opencode serve` and `opencode web`, in npm, pnpm or Bun installs of OpenCode 1.14.30 through 1.18.21, exposed a `/global/upgrade` endpoint that accepted any npm package specifier and did not check the request's origin. A webpage could make the browser post to it and install an attacker's package, running its install scripts with the user's access to keys and tokens. The fix is in 1.18.22; no CVE was assigned.

Identifiers: GHSA-632h-h47v-g4x4

## What was exposed

Code execution as the user running OpenCode, and with it everything that account can read: provider API keys configured for OpenCode, Git and cloud credentials, SSH keys and `.env` files. When OpenCode is installed through an npm-compatible manager, the endpoint ran the equivalent of `npm install -g opencode-ai@<target>`, and npm accepts a remote tarball URL as the target. Because the server parsed a `text/plain` body as JSON and did not check `Origin`, a cross-site HTML form could submit the request. The advisory says password protection with `OPENCODE_SERVER_PASSWORD` did not help once the browser had cached the Basic credentials, since a top-level form navigation sends them. Datadog's write-up shows code execution through a package `preinstall` script; it does not report credential theft or exploitation in the wild.

## Who is affected

You are affected only if all of these held: you ran OpenCode 1.14.30 to 1.18.21; you used `opencode serve` or `opencode web`; OpenCode was installed with npm, pnpm or Bun (curl, Homebrew, Chocolatey and Scoop installs are not affected); the server had no password or the browser had cached it; and you visited an attacker-controlled page while it ran. Datadog suggests checking the install method with `ls -l "$(command -v opencode)"`. Look in global npm packages for an `opencode-ai` install that did not come from the npm registry.

## What to do

1. Update OpenCode to 1.18.22 or later.
2. Set `OPENCODE_SERVER_PASSWORD` whenever you run the OpenCode server, especially on a network.
3. If you ran an affected server while browsing untrusted sites, check that your global `opencode-ai` install came from the npm registry and rotate provider API keys and tokens on the machine.
4. Stop `opencode serve` when you are not using it.

## Keys to rotate

- [Anthropic](https://botpassword.com/keys/anthropic)
- [OpenAI](https://botpassword.com/keys/openai)
- [GitHub](https://botpassword.com/keys/github)

## Timeline

- 2026-04-30: OpenCode 1.14.30, the first affected release, ships, according to Datadog. ([source](https://securitylabs.datadoghq.com/articles/opencode-upgrade-remote-code-execution/))
- 2026-08-11: Datadog Security Labs reports the issue through a GitHub security advisory. ([source](https://securitylabs.datadoghq.com/articles/opencode-upgrade-remote-code-execution/))
- 2026-08-24: Anomaly merges the fix (PR #44686) and publishes OpenCode 1.18.22, then asks Datadog to delay publication by a month. ([source](https://securitylabs.datadoghq.com/articles/opencode-upgrade-remote-code-execution/))
- 2026-09-24: Anomaly publishes GHSA-632h-h47v-g4x4 (high) and Datadog publishes its write-up; Datadog notes that 38.9% of OpenCode npm downloads from 17 to 23 September were still vulnerable versions. ([source](https://github.com/anomalyco/opencode/security/advisories/GHSA-632h-h47v-g4x4))

## Indicators

- POST requests to `/global/upgrade` with a `target` that is a URL rather than a version number.
- A globally installed `opencode-ai` resolved from a non-registry tarball.

## Sources

- https://github.com/anomalyco/opencode/security/advisories/GHSA-632h-h47v-g4x4
- https://securitylabs.datadoghq.com/articles/opencode-upgrade-remote-code-execution/
