← Lab /Security & privacy

OpenCode’s upgrade API allows remote code execution through content-type confusion

OpenCode versions 1.14.30-1.18.21 are vulnerable to remote code execution via a content-type confusion in the /global/upgrade endpoint.

Security & privacy Datadog Security Labs 24 Sep 2026 Disclosure Real-world evidence

Published as “Discovering and exploiting a remote code execution vulnerability in OpenCode (GHSA-632h-h47v-g4x4)”

Why it matters

OpenCode users should upgrade to version 1.18.22 or enable authentication to block remote code execution via the upgrade API.

Summary

The researchers discovered that OpenCode’s /global/upgrade endpoint parses request bodies as JSON without checking the Content-Type header, allowing a text/plain form submission that contains valid JSON to trigger an npm install of an attacker-controlled tarball. By crafting a malicious npm package with a preinstall script and delivering it via a cross-origin HTML form, they achieve remote code execution on the host running OpenCode. The exploit works against versions 1.14.30 through 1.18.21 when the server is run without authentication. The fix in OpenCode 1.18.22 restricts the upgrade target to semantic versions and enforces the correct Content-Type, causing the malicious request to be rejected with a 415 response.

What they found 1

  1. OpenCode 1.18.22 rejects the malicious request with a 415 Unsupported Media Type response.

    “OpenCode 1.18.22 rejects the malicious cross-origin request with an unsupported media type response: HTTP/1.1 415 Unsupported Media Type”

Caveats 3

  • The vulnerability is exploitable only if all of the following conditions apply:
  • The web interface requires no authentication by default, but developers can enable basic authentication, which is especially important when exposing OpenCode to a network:
  • Direct HTTP exploitation requires network access to the OpenCode server, which usually listens on 127.0.0.1.

What’s new here 4

  • First public disclosure of an RCE vulnerability in OpenCode’s upgrade API.
  • Demonstrated a cross-origin form attack that bypasses CORS by exploiting content-type confusion.
  • Provided a patch that validates semantic versions and checks Content-Type, deployed in OpenCode 1.18.22.
  • Reported that vulnerable versions received over 647,000 downloads in a single week.