01_security_model

security model

ARES Security and Threat Model

Purpose

The ARES Security Model defines the safeguards and trust boundaries within the meta-compiler ecosystem. As a tool that generates and executes code across multiple backends (C++, Python, Node.js), ARES maintains a strict separation between the Compilation Environment (Node.js) and the Runtime Environment (Orchestrator Daemon). This document outlines the strategies used to mitigate risks like arbitrary code injection, lateral movement, and resource exhaustion during both the compilation and execution phases.

Prerequisites

  • Host Permissions: The compiler should be run as a non-privileged user unless IoT/GPIO access is required.
  • Target Sandboxing: OS-level isolation (e.g., Docker, seccomp, or apparmor) is recommended for Phase 9 execution of untrusted ARES scripts.

Dependencies

  • src/orchestrator/daemon.ts: Implements process-level isolation and timeouts.
  • src/umr/umr_bridge.ts: Performs declarative (not shell-scripted) dependency resolution.

Formal Definition

Let SS be the ARES source input and E(S)E(S) be its execution. The Security Invariant Isec\mathcal{I}_{sec} states that: S,E(S)CompilerState=\forall S, E(S) \cap \text{CompilerState} = \emptyset This separation ensures that an ARES script can only access its own memory mapped arena and the I/O streams assigned to it by the Orchestrator Daemon.

Operational Behavior

  1. Process Isolation: Every backend (C++, Python, Node) is spawned as a child process via child_process.spawn, which does not share the parent's environment by default (Line 139, daemon.ts).
  2. Input sanitization: While ARES allows for complex literals, the AresParser (Phase 2) rejects any non-standard tokens, preventing some forms of syntax-level injection into the target backend's emitters.
  3. Timeout Enforcement: A fixed 60-second execution window is hard-coded in the daemon (Line 160) to prevent Denial of Service (DoS) attacks via infinite loops.
  4. UMR Declarativity: The Universal Module Resolver does not execute postinstall scripts or arbitrary shell commands during configuration generation (Phase 6), reducing the risk of supply-chain attacks through the compiler.

Implementation Mapping

Attack Surface vs. ARES Mitigation

1. Arbitrary Code Injection (Command Level)

Attack Vector:

ares
use secret_alg on "; rm -rf /"

ARES Mitigation (Emitters): The Emitters (e.g., CppEmitter) do not concatenate input strings directly into system shell calls. The use target is bound specifically as an identifier or string literal in the generated source code, not as a shell command.

2. Resource Exhaustion

Attack Vector:

ares
while true { // infinite loop }

ARES Mitigation (Daemon):

typescript
setTimeout(() => { proc.kill(); // Forced termination after 60s }, 60000);

3. Shared Memory Leakage

Attack Vector:

ares
use dijkstra on adj // then read indices beyond adj

ARES Mitigation (Bridge): The Shared Memory Bridge utilizes read-only mapping (mode: 'r') in consumers and unique binary files in the temporary directory for each run, preventing cross-execution data leaks.

Mathematical Model

The attack success probability Pattack\mathcal{P}_{attack} is bounded by: PattackComplexity of Parsable SurfaceSanitization Depth\mathcal{P}_{attack} \propto \frac{\text{Complexity of Parsable Surface}}{\text{Sanitization Depth}} ARES minimizes the parsable surface by using a strict EBNF grammar (9_formal_spec/01_ebnf.md) that does not allow for raw backend-specific escapes.

Complexity

  • Mitigation Latency: O(1)O(1) constant overhead for process monitoring and timeouts.
  • Sanitization Time: O(N)O(N) linear time checking during Phase 2 parsing.

Examples

Securely Passing Identifiers: The emitter wraps all approach targets in appropriate language-specific scoping to prevent variable name hijacking.

Resource Capping (Configuration): The estimatedN parameter (CompilerOptions:35) is used by the profilier to prevent the selection of O(N2)O(N^2) algorithms on N=106N=10^6 datasets before the code is even compiled.

Traces

Trace for a malicious script execution:

  1. Lexer identifies valid ARES tokens.
  2. Parser validates the grammar (Fails if invalid syntax is used to break the string).
  3. Emitter generates a static C++ source file.
  4. g++ compiles the static file safely.
  5. daemon.execute() spawns the process.
  6. setTimeout() fires after 60s, calling proc.kill().

Edge Cases

  • IoT/GPIO Exposure: When using gpio_control, the execution process must be run with higher privileges. This opens the system to risk if the ARES script is untrusted.
  • C++ Overflow: While ARES generates long long for integers, a malicious script could still overflow buffers in the generated C++ if custom user snippets are poorly authored in the registry.

Failure Modes

  • Zombies: If a script spawns its own children (e.g., via a Python subprocess call), the 60-second limit will kill the parent but might leave "orphaned" children if the OS-level process group is not correctly terminated.
  • Compiler-Side DoS: A very large, recursive if-else chain can exhaust the Node.js stack memory during AST construction.

Compatibility

  • Standards: Follows OWASP recommendations for process isolation and least-privilege execution.
  • Platforms: Sandbox behavior is more robust on Linux (using PID namespaces) than on Windows.

Testing

  • Timeout Test: tests/security.test.ts executes a 5-second busy-wait script with a 1-second override timeout to verify the killer works.
  • Grammar Injection Test: Attempts to inject }; system("...") into a read statement and verifies that the AresParser rejects it.

Related Entities

  • 6_compiler_and_runtime/08_orchestrator_daemon.md: Implementation of the killer timer.
  • src/umr/umr_bridge.ts: Declarative resolution logic.

Source Attribution

  • Security Model: Derived from Judge0 and Isolator security principles.
  • Infrastructure: src/orchestrator/daemon.ts.
ARES