This proof-of-concept demonstrates a critical security vulnerability in OpenCode's server architecture.
OpenCode's local server has two critical security issues:
- Open CORS Policy: Uses
cors()with default settings, allowingAccess-Control-Allow-Origin: * - No Authentication: All API endpoints are accessible without any authentication
This means any website you visit can:
- Execute shell commands on your machine
- Read files from your filesystem
- Manipulate AI agents
- Exfiltrate sensitive data
-
OpenCode must be installed and running. Any of these are vulnerable:
# Production binary (installed via npm/bun) opencode serve # Or just running opencode (TUI also starts the server) opencode # Or development mode cd /path/to/opencode bun run dev
Note: The vulnerability exists in BOTH development AND production builds. The same
cors()middleware with default settings (allowing all origins) is compiled into the production binary. -
Python 3 for the demo server (or any HTTP server)
cd opencode-vuln-demo
python3 serve.pyThen open http://localhost:8080 in your browser.
# Using Node.js
npx serve .
# Using PHP
php -S localhost:8080| Attack | API Endpoint | Risk Level |
|---|---|---|
| Server Info Leak | GET /global/health, GET /path |
Medium |
| Session Enumeration | GET /session |
Medium |
| File Reading | GET /file/content?path=... |
Critical |
| Directory Listing | GET /file?path=... |
High |
| Config Extraction | GET /config |
Critical |
| PTY Shell Creation | POST /pty |
Critical |
| Shell Command Exec | WebSocket /pty/:id/connect |
Critical |
| AI Agent Manipulation | POST /session/:id/message |
Critical |
| Permission Bypass | POST /session/:id/permissions/:id |
Critical |
Even though OpenCode binds to 127.0.0.1 (localhost), browsers allow JavaScript from any origin to make requests to localhost. The open CORS policy (Access-Control-Allow-Origin: *) explicitly permits these cross-origin requests.
- Token-based authentication for all API endpoints
- Strict CORS policy - only allow requests from trusted origins
- Origin header validation - reject requests from web pages
- Rate limiting on sensitive endpoints
- Permission system for API access - not just for tool execution
This demo is for educational and security research purposes only. Please report security vulnerabilities to the OpenCode maintainers responsibly.
index.html- Main demo interfaceserve.py- Simple Python HTTP serverREADME.md- This file