Discovering and exploiting a remote code execution vulnerability in OpenCode (GHSA-632h-h47v-g4x4)
The article describes GHSA-632h-h47v-g4x4, a content-type confusion vulnerability in OpenCode’s /global/upgrade endpoint that allows remote code execution. By submitting a POST request with Content-Type: text/plain, attackers bypass CORS protections and cause the server to pass an untrusted URL to npm install, which the npm spec allows to reference remote tarballs. An attacker can host a malicious npm package tarball containing a preinstall script that executes when installed. Cross-origin exploitation is achieved by hosting a webpage that auto-submits a form to the local OpenCode server, executing arbitrary commands on a developer’s machine. OpenCode 1.18.22 contains the fix.
This post is licensed under CC BY 4.0 by the author.