llamaCVEVulnerability Intelligence
/
Advisory · GitHub · npm · knowns

GHSA-W323-3WPX-F7G5

MCP Permission Guard Bypass: code.replace (CapRead) Self-Grants Delete

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 el mismo día de la divulgación
Exposición97 dDesde la divulgación, 16 ago 2026, 5:52 a. m.
Detección94 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.
No es para las 3 a. m., pero sí para esta semana.Te dejo mi extintor por si acaso.
Timeline

Ciclo de vida de la vulnerabilidad

Hoy
Divulgación
Publicada
Modificada
Explotación
Remediación
Parche 0.30.0
Monitoreo
Detectada +1
16 ago 26
3 sept 26
19 nov 26
21 nov 26
16 ago 26
9 sept 26
4 oct 26
28 oct 26
21 nov 26
FechaFaseEventoDetalle
Divulgación Publicada GHSA-W323-3WPX-F7G5 divulgada · CVSS 10 (GitHub)
Remediación Parche 0.30.0 knowns · 0 d desde divulgación
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

Overview

Verified. The Knowns MCP permission model suffers from a critical AI Agent Sandbox Escape and Self-Privilege Escalation vulnerability. A read-only AI agent session can bypass capability restrictions, overwrite the workspace configuration, and dynamically self-grant full `read-write` / `delete` privileges.

This occurs because the destructive `code.replace` action is absent from the `ActionRegistry`, causing the permission guard to fall back to a `CapRead` default. The agent leverages this misclassified write primitive combined with a path traversal to overwrite `.knowns/config.json`. Because the configuration store re-reads the policy from disk on every invocation without caching, the permission switch is instantaneous. The agent then immediately executes destructive tools (e.g., `docs.delete`) against arbitrary files outside the project root, completely compromising the host filesystem.

Affected paths

| File Path | Role | Vulnerability & Execution Impact |
| :--- | :--- | :--- |
| `internal/permissions/registry.go` | Permission Guard | Capability Misclassification (CWE-693): `code.replace` is absent from `ActionRegistry`. `ClassifyAction()` falls back to `toolFallback["code"]` mapping to `CapRead`, allowing a destructive file-overwrite operation to bypass `read-only` session constraints. |
| `internal/mcp/handlers/code.go` | Vulnerable Sink | Unrestricted File Overwrite (CWE-22 / CWE-73): `handleCodeReplace()` resolves `path` with `filepath.Join` but performs no traversal validation. With `mode=regex` and needle `(?s).*`, it acts as an arbitrary file overwrite primitive targeting `.knowns/config.json` or host files. |
| `internal/storage/config_store.go` | State Manager | Stateless Policy Reload (CWE-662): `Get()` calls `loadRaw()` on every invocation, executing `os.ReadFile()` unconditionally with no in-memory cache. Policy modifications take effect immediately on the next evaluation. |

Root Cause

### Flaw 1 - Capability Misclassification in ActionRegistry
In `internal/permissions/registry.go`, `ActionRegistry` defines capabilities for `code.search`, `code.symbols`, `code.deps`, and `code.graph`. However, `code.replace` (a destructive write operation) is entirely missing. When `ClassifyAction("code", "replace")` is called, it falls back to `toolFallback["code"]` which defaults to `Capability: CapRead`. Consequently, the permission guard evaluates the file overwrite as a safe read operation, permitting execution under strict `read-only` presets.

### Flaw 2 - Path Traversal in File Operations
In `internal/mcp/handlers/code.go`, `handleCodeReplace()` resolves the caller-supplied `path` using `filepath.Join(projectRoot(store), path)` but lacks any post-resolution prefix check. It also implicitly accepts absolute paths. Combined with `mode=regex`, this allows an agent to target any file on the filesystem accessible to the Knowns process.

### Flaw 3 - Stateless Policy Evaluation
In `internal/storage/config_store.go`, the `Get()` function unconditionally calls `loadRaw()`, which executes `os.ReadFile(cs.configPath())` on every single policy evaluation. There is no session-locking or in-memory caching of the policy file. This stateless design allows an attacker to overwrite the policy file and have the new elevated privileges recognized instantly on the very next request.

Attack Vector

| Phase | Request / Action | Effect |
| :--- | :--- | :--- |
| 1. Recon | Agent initialized with `read-only` preset | Agent is restricted from calling `CapWrite` or `CapDelete` tools. |
| 2. Escalation | Call `code` tool with `action=replace`, targeting `.knowns/config.json` | `ClassifyAction` evaluates as `CapRead` (bypassing guard). File is overwritten with a payload setting the preset to `read-write`. |
| 3. Propagation | System evaluates next request | `config_store.Get()` re-reads disk via `loadRaw()`. Session is now evaluated as `read-write`. |
| 4. Execution | Call `docs.delete` with path traversal payload (`../../../etc/cron.d/...`) | Destructive operation executes against out-of-bounds host files. Sandbox is fully escaped. |

Preconditions: Knowns MCP server running; AI Agent or user connected with a restrictive `read-only` policy.

Analysis

### Capability Misclassification (`registry.go`)
The permission guard relies on a static map to enforce boundaries. The fallback logic is fundamentally insecure (fail-open for unknown actions):

// internal/permissions/registry.go
var ActionRegistry = map[string]ActionMeta{
    "code.search":  {Capability: CapRead, ...},
    "code.symbols": {Capability: CapRead, ...},\
    "code.deps":    {Capability: CapRead, Target: TargetCode, Risk: RiskLow},
    "code.graph":   {Capability: CapRead, Target: TargetCode, Risk: RiskLow},
    // code.replace is MISSING
}

var toolFallback = map[string]ActionMeta{
    "code": {Capability: CapRead, ...}, // Fallback for unregistered code actions
}

func ClassifyAction(tool, action string) ActionMeta {
    key := tool + "." + action
    if meta, ok := ActionRegistry[key]; ok {
        return meta
    }
    if meta, ok := toolFallback[tool]; ok {
        return meta // code.replace lands here → evaluated as CapRead
    }
    return defaultMeta
}

### Path Traversal Sink (`code.go`)
The `handleCodeReplace` function trusts the resolved path implicitly. By supplying `needle="(?s).*"` (matching the entire file) and a path traversal sequence, the agent overwrites the configuration file:

// internal/mcp/handlers/code.go
absPath := path
if !filepath.IsAbs(absPath) {
    absPath = filepath.Join(projectRoot(store), absPath)
}
// NO containment check: strings.HasPrefix(absPath, projectRoot(store)) is missing
data, err := os.ReadFile(absPath)
// ...
if err := os.WriteFile(absPath, []byte(next), 0644); err != nil { ... }

### Stateless Policy Reload (`config_store.go`)
The lack of a caching layer in `loadRaw()` is the catalyst that turns a local config overwrite into a live privilege escalation:

// internal/storage/config_store.go
func (cs *ConfigStore) Get(key string) (any, error) {
    raw, err := cs.loadRaw() // re-reads disk on every call
    // ...
}

func (cs *ConfigStore) loadRaw() (map[string]any, error) {
    data, err := os.ReadFile(cs.configPath()) // No cache, no lock
    // ... parses and returns live config
}

Fix

*Patch is available right now at New Release https://github.com/knowns-dev/knowns/releases.*

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.29.1
0.29.1
0.35.0
Remediación

Estado del parche por paquete

Paquete / productoEstadoCorregida enDesde divulgaciónÚltima versión
npmknowns
Corregida 0.30.0 0 d 0.35.0 no afectada
Versiones corregidas0.30.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-w323-3wpx-f7g5

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