GHSA-W323-3WPX-F7G5
MCP Permission Guard Bypass: code.replace (CapRead) Self-Grants Delete
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
Ciclo de vida de la vulnerabilidad
| Fecha | Fase | Evento | Detalle |
|---|---|---|---|
| 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 |
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.*
Desglose de métricas
Rangos afectados
Estado del parche por paquete
| Paquete / producto | Estado | Corregida en | Desde divulgación | Última versión |
|---|---|---|---|---|
npmknowns |
Corregida | 0.30.0 | 0 d | 0.35.0 no afectada |
0.30.0Arsenal público
Sin exploits, módulos ni PoC públicos conocidos a la fecha de verificación.
https://github.com/knowns-dev/knowns/security/advisories/GHSA-w323-3wpx-f7g5Las referencias externas se muestran para copiar: cve.llama.ec no lo redirige a otros sitios.
