T07 · Tool Hijacking and Spoofing
Error
- Location
- references/throughput-dashboard.js:29
- Finding
- Arbitrary Code Execution Through Dynamic Loading of a Workspace Metrics Module<![CDATA[ ## Vulnerability Details **File Location**: `references/throughput-dashboard.js`, lines 29 and 51–66 **Vulnerability Type**: Unsafe dynamic module execution across a local trust boundary **Risk Level**: High ### Vulnerable Code ```javascript function safeRequire(p) { try { return require(p); } catch (_) { return null; } } function collectSessionSummary(workspaceRoot) { const metricsPath = path.join(workspaceRoot, 'scripts', 'session-metrics.js'); const mod = safeRequire(metricsPath); if (!mod || typeof mod.getWeeklySummary !== 'function') { return { total_tasks: 0, total_cost: 0, avg_cost_per_task: 0, total_subagents: 0, quality_ratio: 1.0, sessions: 0 }; } try { return mod.getWeeklySummary(workspaceRoot); } catch (_) { return { total_tasks: 0, total_cost: 0, avg_cost_per_task: 0, total_subagents: 0, quality_ratio: 1.0, sessions: 0 }; } } function collectRoutingStats(workspaceRoot) { const metricsPath = path.join(workspaceRoot, 'scripts', 'session-metrics.js'); const mod = safeRequire(metricsPath); if (!mod || typeof mod.getRoutingStats !== 'function') { return { total_decisions: 0, by_target: { core: 0, specialist: 0, escalate: 0 }, by_type: {} }; } ``` ### Technical Analysis The dashboard treats `scripts/session-metrics.js` as a metrics source but loads it through Node.js `require()`. Requiring a JavaScript module immediately executes all of its top-level code before the exported functions are inspected. The module path is derived from the supplied workspace root, and the code performs no integrity validation, ownership check, permission check, or module allowlisting. Consequently, anyone capable of creating or replacing `scripts/session-metrics.js` in the selected workspace can cause arbitrary JavaScript to execute when the dashboard runs. Wrapping `require()` in `try/catch` does not provide a security boundary. It only suppresses exceptions after malicious top-level code may already have executed. Suppression ...[truncated 1691 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions 1. Replace executable metrics modules with a non-executable data format such as JSON or JSONL. 2. Parse the metrics file using `JSON.parse()` and validate it against a strict schema before use. 3. Reject unexpected fields, invalid types, non-finite numbers, and values outside documented ranges. 4. If a plugin architecture is necessary, load plugins only from an explicit administrator-controlled allowlist. 5. Verify plugin integrity using a pinned cryptographic hash or signed manifest before loading it. 6. Check file ownership and permissions and reject modules writable by less-trusted users. 7. Run scheduled monitoring under a dedicated least-privilege account with narrowly scoped filesystem and network access. 8. Do not silently suppress module-loading failures. Record failures in a protected audit log without exposing sensitive data. 9. Resolve and validate the canonical workspace path before accessing any workspace resources. ]]>
