# opencode remote MCP OAuth RCE

- ID: opencode-mcp-oauth-rce-2026-10
- Reported: 2026-10-19
- Researcher: Eilon Cohen
- Organization: Pillar Security
- AI role: ai_agent_or_mcp_as_target (Agent / MCP as target)
- Confidence in AI involvement: not assessed
- Research / borderline: false
- Last reviewed: 2026-10-20
- Entry page: https://openattacks.ai/attacks/opencode-mcp-oauth-rce-2026-10/
- Entry JSON: https://openattacks.ai/api/attacks/opencode-mcp-oauth-rce-2026-10.json
- Browse title: opencode remote MCP OAuth command execution
- Editorial summary: A malicious remote MCP server can return an OAuth URL that runs commands via PowerShell when opencode opens it on Windows or WSL. No prompt injection is needed.
- Evidence class (catalog annotation): Vulnerability report
- Source-stated target environments: Agents & MCP; Windows
- Stage hunts and conditional defenses: https://openattacks.ai/api/defenses/opencode-mcp-oauth-rce-2026-10.json

## Technique
Malicious or compromised remote MCP server returns 401 and OAuth discovery with attacker-controlled authorization\_endpoint. opencode passes that URL to npm open; on Windows/WSL open 10.x builds a PowerShell -EncodedCommand without escaping the target, so $(...) in an https URL runs before the browser launches. No prompt injection required.

## Stack relevance (editorial)
Assessment: mapped. Editorial applicability reviewed against the catalog source account; not a scan or independent incident verification.
First action: Check the fixed version and review remote MCP endpoints before opening their OAuth authorization URLs.
- Relationship: target; tools: opencode; OS scope: windows; requires existing MCP connections: true.
  Relevance: opencode opens an untrusted MCP OAuth authorization URL through the reported Windows execution path.
  Condition to check: Confirm that the installed version is affected by the historical report; selecting a product does not establish its version or patch status.
  Condition to check: The report describes Windows or WSL and a malicious or intercepted remote MCP OAuth server.
  Evidence: https://www.pillar.security/blog/open-and-shut-remote-code-execution-in-opencode-via-mcp-oauth
A product mention alone is not a victim-side applicability mapping. Selection does not verify affected versions, permissions or compromise.

## Initial access
Developer connects coding agent to attacker-controlled or later-compromised remote MCP server

## AI tooling and models
- [opencode](https://github.com/anomalyco/opencode) / [opencode-ai](https://github.com/anomalyco/opencode) 1.0.137–1.18.32
- MCP OAuth discovery

## Other tooling
- [npm open@10.1.2](https://github.com/sindresorhus/open)
- [PowerShell](https://github.com/PowerShell/PowerShell)
- related class CVEs: CVE-2025-6514 [mcp-remote](https://github.com/punkpeye/mcp-remote), CVE-2025-58062 [openmcp-client](https://github.com/LSTM-Kirigaya/openmcp-client), CVE-2025-10619 [sequa-mcp](https://github.com/sequa-ai/sequa-mcp)

## Victims and sectors
Windows and WSL developers using opencode (~3M weekly npm downloads cited by Pillar)

## Target geography
- unknown

## Attribution
Vulnerability research (no in-the-wild campaign named)

## Scale and metrics
Fixed in 1.18.33 (2026-09-28) without CVE/advisory; proposed CVSS 9.8

## Attack flow
Catalog reconstruction of the supplied source account. Unknowns and research caveats are preserved.
### step-1: Developer connects a remote MCP server [access]
The server is attacker-controlled or later compromised.
Evidence: https://www.pillar.security/blog/open-and-shut-remote-code-execution-in-opencode-via-mcp-oauth

### step-2: OAuth discovery supplies an attacker URL [ai]
A 401 response leads to an attacker-controlled authorization endpoint.
Evidence: https://www.pillar.security/blog/open-and-shut-remote-code-execution-in-opencode-via-mcp-oauth

### step-3: URL enters PowerShell through open() [execution]
Affected Windows or WSL browser-opening code fails to escape the target.
Evidence: https://www.pillar.security/blog/open-and-shut-remote-code-execution-in-opencode-via-mcp-oauth

### step-4: Commands execute before the browser opens [impact]
The injection occurs in the URL-opening path without requiring prompt injection.
Evidence: https://www.pillar.security/blog/open-and-shut-remote-code-execution-in-opencode-via-mcp-oauth

Connections:
- step-1 -> step-2
- step-2 -> step-3
- step-3 -> step-4

## Stage defense and hunting recommendations
Editorial recommendations, not validated coverage. Source-controlled query starters are drafts. Custom-schema examples require telemetry collection and field mapping; absence of a mapping means not assessed. MagicSword policy opportunities require managed Windows scope and enforcement.
### step-1: Agent trust / configuration changes
- Visibility: Defender-side logs where collected
- Query origin: catalog_authored; status: draft; log scope: custom_schema
- SIGMA query download: /api/detections/mcp-config.sigma.yml
- KQL query download: /api/detections/mcp-config.kql
- SPL query download: /api/detections/mcp-config.spl
- Hunt hypothesis: A repository, dependency or agent changes MCP commands, automatic-task settings, tool approval or model-routing configuration before new execution.
- Required telemetry: File changes and before/after content for MCP / IDE configuration; Repository audit / pull-request history; Agent startup and tool-invocation logs
- Investigate: Diff command, args, environment, origin, autoApprove and task settings against the previously approved version.
- Investigate: Correlate the author and change with the next agent launch; inspect path canonicalization and trailing-dot variants where relevant.
- Limitation: A file-write event alone cannot establish what changed. Legitimate setup also changes these files; obtain a diff and authorization context.
- Qualification: Compare the remote server origin and connection settings with the approved inventory before examining the OAuth execution stage.
- No direct MagicSword prevention claim is recorded for this stage.

### step-2: Unexpected agent tool use
- Visibility: Defender-side logs where collected
- Query origin: catalog_authored; status: draft; log scope: custom_schema
- SIGMA query download: /api/detections/agent-tools.sigma.yml
- KQL query download: /api/detections/agent-tools.kql
- SPL query download: /api/detections/agent-tools.spl
- Hunt hypothesis: Untrusted content or a changed tool definition precedes a file read, command, or remote call outside the user's intended task.
- Required telemetry: Agent tool-call audit records with session / tool / destination; Tool-definition and approval changes; Endpoint process, file-access and network evidence where available
- Investigate: Join input provenance, tool descriptions and calls by session ID and compare the action to the approved task.
- Investigate: Inspect child processes and destinations; record whether execution was in-process, local, or through a remote SaaS connector.
- Limitation: Process logs cannot recover model intent. Remote connectors and in-process interpreters may produce no local child process. Prompt content alone is not a reliable signature.
- No direct MagicSword prevention claim is recorded for this stage.

### step-3: Suspicious Windows script execution
- Visibility: Defender-side logs where collected
- Query origin: catalog_authored; status: draft; log scope: native
- SIGMA query download: /api/detections/windows-shell.sigma.yml
- KQL query download: /api/detections/windows-shell.kql
- SPL query download: /api/detections/windows-shell.spl
- Hunt hypothesis: A script host or shell runs encoded content, a remote URL, or inline script syntax, then downloads or launches a payload.
- Required telemetry: Windows process creation: Sysmon Event 1 or Defender DeviceProcessEvents; PowerShell script-block logging when enabled; Download / network and installer events
- Investigate: Follow the parent and child process tree and recover the script or URL from logs without executing it.
- Investigate: Correlate the payload's signer/hash, persistence, and network activity; baseline approved automation.
- Limitation: Encoded commands and remote administration can be legitimate. This does not cover every script host, in-process execution, or non-Windows branch.
- Conditional MagicSword policy: Use MagicSword application control to restrict an unneeded Windows shell/helper or deny unapproved payloads while the vulnerable client is patched.
- Policy scope: The reported Windows / WSL PowerShell helper, only where execution policy restricts it. Policy is not a replacement for fixing unsafe URL handling.
- Policy limitation: Policy opportunity, not tested incident coverage. Requires enrolled Windows devices, a policy covering the actual executable, and enforcement. Audit mode records decisions without blocking; allowed tools and in-process / cloud actions can remain reachable.
- Policy reference: https://www.magicsword.io/use-cases/application-control?utm_source=openattacks&utm_medium=referral&utm_content=stage-control

### step-4: Suspicious Windows script execution
- Visibility: Defender-side logs where collected
- Query origin: catalog_authored; status: draft; log scope: native
- SIGMA query download: /api/detections/windows-shell.sigma.yml
- KQL query download: /api/detections/windows-shell.kql
- SPL query download: /api/detections/windows-shell.spl
- Hunt hypothesis: A script host or shell runs encoded content, a remote URL, or inline script syntax, then downloads or launches a payload.
- Required telemetry: Windows process creation: Sysmon Event 1 or Defender DeviceProcessEvents; PowerShell script-block logging when enabled; Download / network and installer events
- Investigate: Follow the parent and child process tree and recover the script or URL from logs without executing it.
- Investigate: Correlate the payload's signer/hash, persistence, and network activity; baseline approved automation.
- Limitation: Encoded commands and remote administration can be legitimate. This does not cover every script host, in-process execution, or non-Windows branch.
- No direct MagicSword prevention claim is recorded for this stage.


## MITRE ATLAS
Mappings are catalog annotations based on described behavior, not assignments or endorsements by MITRE.
No source-backed mapping is currently recorded.

## Defensive notes
Upgrade opencode; inventory installations (no CVE for scanners); pull unvetted remote MCP; argv not shell for URLs; MagicSword prevent unapproved second-stage binaries

## Sources
- https://www.pillar.security/blog/open-and-shut-remote-code-execution-in-opencode-via-mcp-oauth
