Skip to content

Enterprise Security Gateway

Commander's EnterpriseSecurityGateway provides a 7-layer defense-in-depth architecture that is invoked during all LLM calls and tool executions. It cannot be bypassed — cost checks execute both before and after LLM calls.

7-Layer Defense

LayerNamePurpose
1Zero-Trust SignatureIntegrity verification + replay prevention
2AuthenticationAPI Key validation with timing-safe comparison
3Rate LimitingGlobal token bucket + tiered IP limits
4Input ScanningContent injection detection + input validation
5Cost Pre-CheckBill explosion prevention (pre-call estimation)
6Request ProcessingBusiness logic execution
7Output ScanningDLP data leak prevention + cost recording

Design Principles

  • Defense in depth — Multiple independent layers, each with distinct responsibility
  • Fail fast — Reject early at the cheapest layer
  • Observable — Every decision is logged with security metadata
  • Tenant isolation — All checks are per-tenant
  • Unbypassable — Cost checks execute both before and after LLM calls

Data Loss Prevention (DLP)

The dataLossPrevention.ts module scans all egress points for sensitive data across a 5-stage pipeline.

Detected Patterns (12+)

PatternExample
API Keysk-..., sk-ant-...
JWTeyJ...
Private Key (PEM)-----BEGIN PRIVATE KEY-----
Credit Card (Luhn)4111 1111 1111 1111
SSN123-45-6789
Emailuser@example.com
Phone+1-555-0123
Internal IP10.0.0.1, 192.168.1.1
Database Connection Stringmongodb://user:pass@host:port
AWS/GCP/Azure CredentialsAKIA..., AIza...
China ID Card (checksum)110101199003077735
Bank AccountNumeric with branch code

Redaction Strategies

StrategyBehavior
REDACTReplace with [REDACTED]
MASKPartial masking (sk-...abc)
HASHSHA-256 hash
ALLOWPass through (logged only)

Egress Points

DLP is applied at all output boundaries:

  • API responses
  • Log entries
  • Tool results
  • Agent outputs
  • SSE event streams

Tool Input Scanning

Tool inputs are scanned for 6 specific sensitive patterns before execution:

  1. API Key
  2. Private Key
  3. AWS Key
  4. GitHub Token
  5. JWT
  6. Password

Capability Tokens

The capabilityToken.ts module issues short-lived HMAC-signed authorization tokens:

  • Short TTL — Tokens expire automatically, limiting exposure window
  • Scope-bound — Each token carries specific capabilities (tool, resource, duration)
  • HMAC-signed — Tamper-proof via server-side secret
  • Revocable — Can be invalidated before expiry

All tool executions require capability token validation at execution points.

Audit Chain Ledger

The auditChainLedger.ts creates a tamper-proof hash chain of all security-relevant events:

entry_1 → SHA256(prev_hash | entry_1) → hash_1
entry_2 → SHA256(hash_1 | entry_2) → hash_2

Any modification to historical entries breaks the chain, making tampering detectable.

Agent Lineage

The agentLineage.ts module tracks immutable parent-child relationships between agents:

  • spawnChild() validates parent node existence in the lineage tree
  • Lineage is immutable once recorded
  • Enables complete audit trail of agent delegation chains

Additional Security Components

ComponentPurpose
guardianAgent.tsSemantic drift, anomaly, and safety monitoring
securityMonitor.tsContinuous monitoring + anomaly detection + alerting
zeroTrustValidator.tsZero-trust request validation
billExplosionGuard.tsCost explosion prevention
memoryPoisoningDefenseEngine.tsMemory poisoning attack defense
toolPoisoningGuard.tsTool poisoning detection
mcpToolPoisoningGuard.tsMCP tool poisoning detection
mlInjectionDetector.tsML injection detection
taintTracker.tsTaint tracking across data flows
supplyChainScanner.tsDependency supply chain scanning
owaspAgenticAiTop10.tsOWASP Agentic AI Top 10 compliance
mitreAtlasMapper.tsMITRE ATLAS threat mapping
redTeamFramework.tsRed team testing framework
postQuantumCrypto.tsPost-quantum cryptography
gdprCompliance.tsGDPR compliance checking
euAiActCompliance.tsEU AI Act compliance

Plugin Permission Enforcement

Third-party plugins receive a sandboxed load context that deliberately excludes the raw HookManager:

typescript
// buildSandboxedLoadContext() — only for third-party plugins
const sandboxContext = {
  registerHook: enforcer.wrapRegisterHook(...),
  readFile: enforcer.wrapReadFile(...),
  writeFile: enforcer.wrapWriteFile(...),  // mode 0o600
  fetch: enforcer.wrapFetch(...),          // domain + port check
  getEnvVar: enforcer.wrapGetEnvVar(...),
  getConfig: enforcer.wrapGetConfig(...),
  log: enforcer.wrapLog(...),
};
// hookManager is NOT included — prevents privilege escalation

Built-in plugins (no enforcer) still receive the full hookManager.

Permission Constraints

  • Plugin permissions must never exceed main system permissions
  • updateConfig() routes through the same sandbox context as register()
  • withTimeout() uses Math.min(plugin.maxExecutionTimeMs, globalTimeoutMs) — the stricter value wins
  • Network requests are URL-parsed and checked via enforcer.checkNetwork()
  • All failures are reported via reportSilentFailure (never throws to plugin)

MIT Licensed — Built for multi-agent orchestration.