> ## Documentation Index
> Fetch the complete documentation index at: https://docs.hoox.sh/llms.txt
> Use this file to discover all available pages before exploring further.

# Enterprise Security & Compliance

> Extending the 5-layer model with Bot Management, API Shield, Zero Trust, mTLS, AI Guardrails, and immutable audit for HOOX Enterprise.

# Enterprise Security & Compliance

> **Open Core vs Enterprise**
> The base 5-layer security model and many patterns are part of the open core.
> Advanced Enterprise-only security features (full Bot Management, API Shield at scale, SCIM, dedicated mTLS setups, etc.) are described in this commercial layer document.

HOOX's existing 5-layer security model is excellent. Enterprise adds several powerful layers that are either only available or significantly stronger on paid/Enterprise plans.

## Extended Layers

### Layer 0: Bot Management (Enterprise)

* Scores every request (`cf.botManagement.score`).
* Detects verified bots, corporate proxies, automated tooling.
* JA3/JA4 fingerprinting, JS challenge results.
* Early drop of suspicious TradingView/Telegram/email signal sources.
* Combined with WAF custom rules and rate limiting.

Example in Dispatch / Gateway:

```ts theme={null}
const bot = request.cf?.botManagement;
if (bot && !bot.verifiedBot && bot.score < 30) {
  return new Response("Blocked", { status: 403 });
}
```

### Layer 1: Advanced WAF + API Shield

* Enterprise WAF supports 100 rate limiting rules, complex expressions, high cardinality.
* **API Shield**:
  * JSON Schema validation on webhook and internal-ish endpoints.
  * JWT validation.
  * mTLS (client certificates) for dashboard or partner integrations.
  * Sequence / anomaly detection.

### Layer 2: Zero Trust / Access

* Dashboard and management APIs protected by Cloudflare Access (SSO, device posture, WARP, etc.).
* Replaces or augments custom passkeys for human operators.
* SCIM for team provisioning in larger organizations.
* Gateway policies for outbound control if needed.

### Layer 3: Internal + mTLS

* Existing `INTERNAL_KEY_BINDING` + `requireInternalAuth` remains.
* Add mTLS between Workers where possible (or use Service Binding + strong claims).
* Per-tenant claims propagated in auth headers.

### Layer 4: Durable Object + Cryptographic Controls

* SQLite DOs for tamper-evident logs (append-only tables with hashes).
* Signatures on important events (fills, kill switches, config changes).
* Stored in D1 + R2 (dual write for durability).

### Layer 5: AI Guardrails (new)

* **AI Gateway** in front of all LLM calls (risk agents, summaries, strategy parsing).
  * Prompt injection detection / sanitization.
  * Logging + caching + rate limits + fallbacks.
  * Cost control and audit of every AI decision.
* Existing prompt-sanitizer in agent-worker is promoted and expanded.

## Immutable Audit (Compliance Core)

Every security-relevant event flows to Logpush → R2 (see observability-audit.mdx).

Key events:

* All webhook / signal ingress (with bot score, WAF decision)
* Auth decisions (success + failure)
* Idempotency DO outcomes
* Order placement + exchange responses (full)
* Risk actions (trailing stop, kill switch)
* Config / secret changes (via audit hooks)
* Workflow step outcomes

Retention: typically 7 years for financial services (configurable via R2 lifecycle).

## Data Residency & Sovereignty

* R2 jurisdiction controls (e.g., EU, US, APAC only buckets).
* DO location hints + Worker placement for sensitive tenants.
* D1 database location choices.
* Optional: separate Enterprise accounts per major jurisdiction.

## Kill Switch & Fail-Closed Enhancements

* Multiple kill switch sources (manual via Zero Trust dashboard, API with mTLS, automated via Workflow or AI anomaly).
* Every activation produces a signed, immutable record.
* Position flattening Workflow must run to completion (durable).

## Secrets & Key Management

* Use Cloudflare Secret Store / per-script secrets.
* Rotate via CLI + audit event.
* For very high security: integrate with external KMS via Hyperdrive or mTLS if needed (rare).

## Threat Model Updates (Enterprise)

See original threat model (papers/appendices/C-threat-model.tex and docs).

New / amplified threats addressed:

* Malicious or compromised tenant code (mitigated by WfP isolation + review gates).
* Supply-chain attacks on customer strategies (AI Gateway + sandboxing patterns).
* Regulatory "prove you didn't front-run" → full immutable trace + signatures.
* Nation-state / sophisticated bot attacks on signal sources → Bot Management + WAF.

## Implementation Notes

* Bot Management and advanced WAF rules are configured at the zone/account level (Enterprise).
* API Shield schemas live with the Dispatch Worker and public ingress points.
* Zero Trust policies defined for `dashboard`, `cli` (via API tokens with context), and internal tools.
* All new Enterprise components must emit audit events using the shared `trackAnalytics` / audit path.

## Related Documents

* Root security overview: `docs/devops/security/overview.mdx`
* Architecture: `docs/devops/enterprise/architecture.mdx`
* Multi-tenancy isolation guarantees: `multi-tenancy.mdx`
* Original 5-layer model in the academic paper.
