> For the complete documentation index, see [llms.txt](https://www.openclawbook.xyz/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://www.openclawbook.xyz/en/ch10-advanced-techniques/10.2-security-hardening-and-permissions.md). Agents can also search and read this documentation through its [MCP server](https://www.openclawbook.xyz/~gitbook/mcp).

# 10.2 Security Hardening and Permission Management

> **Generated by**: Claude Opus 5 (claude-opus-5\[1m]) **Token usage**: Input \~172,000 tokens, Output \~9,000 tokens (this section) **Source baseline**: `v2026.3.9` (`v2026.3.8-170-g665f67726`)

***

## 10.2.1 The Threat Model, Stated Plainly

Before hardening anything, know what you're hardening against. OpenClaw's model (§32.6.1, §44.4):

| In scope                                        | Out of scope           |
| ----------------------------------------------- | ---------------------- |
| Unauthorized network access to the gateway      | **Prompt injection**   |
| Unauthorized channel senders reaching the agent | Malicious plugins      |
| Credential leakage                              | A compromised host     |
| Accidental destructive commands                 | Multi-tenant isolation |

**The right column is deliberate, and the first entry is the important one.**

The position isn't that prompt injection doesn't matter. It's that a system whose entire purpose is following natural-language instructions cannot reliably distinguish instructions you meant from instructions embedded in content it reads. So instead of claiming a defense that would fail, the design **limits what a manipulated agent can do**.

That reframes every hardening decision below. You're not trying to prevent the agent from being fooled — you're arranging for it not to matter much when it is.

## 10.2.2 Layered Hardening

### Layer 1 — Network

```json5
{
  gateway: {
    bind: "loopback",              // or "tailnet"
    auth: { mode: "token" },
  },
}
```

Loopback plus a token. If you need remote access, an SSH tunnel or Tailscale (§8.2.2) beats exposing the port. **Exposing 18789 publishes a full operator-access surface** — past authentication, the caller is you.

### Layer 2 — Who can reach the agent

```json5
{
  channels: {
    telegram: {
      dmPolicy: "pairing",           // not "open"
      allowFrom: ["123456789"],      // numeric IDs, not usernames
      groupPolicy: "allowlist",
      groups: { allow: ["-1001234567890"] },
      requireMention: true,
    },
  },
}
```

**Use stable numeric IDs, never display names.** Display names are reassignable on most platforms; an allowlist keyed on one is an allowlist an attacker can join by renaming.

### Layer 3 — What the agent can execute

```json5
{
  tools: {
    exec: {
      security: "allowlist",         // not "full"
      ask: "on-miss",                // prompt on anything not allowlisted
      allow: ["git status", "npm test", "ls"],
    },
  },
}
```

`ask: "on-miss"` is the practical middle ground: allowlisted commands run freely, anything else asks. `always` is safer and quickly becomes tiresome.

### Layer 4 — Sandboxing

```json5
{
  agents: {
    defaults: {
      sandbox: { mode: "non-main" },   // sandbox everything except your main session
    },
  },
}
```

Sandboxed sessions run in a container with restricted filesystem and network access.

**Note the gap you must not forget**: a sandboxed session **may not spawn ACP**, and `sandbox="require"` has no effect on that path (§9.2.3, §39.4.3). It's forbidden rather than silently escaping — but the reason it's stated so bluntly is that a switch that *looks* effective and isn't is worse than no switch.

### Layer 5 — Plugins

```json5
{
  plugins: {
    allow: ["telegram", "memory-core"],
  },
}
```

**`plugins.allow` defaults to empty, which means "discovered equals loaded"** (§32.6.5). Setting it explicitly is the cheapest hardening available.

It matters because **plugins run in-process with no capability restriction** — a plugin is part of the trusted computing base, not a sandboxed extension (§21.5.6). Installing one is equivalent to running its code as yourself.

### Layer 6 — Content handling

```json5
{
  agents: {
    defaults: {
      allowUnsafeExternalContent: false,
    },
  },
}
```

Leave this false. It gates whether externally-fetched content is treated as trusted, and true means web pages can influence the agent as if you had written the text.

## 10.2.3 Credential Handling

### Keep secrets out of the config file

```bash
export ANTHROPIC_API_KEY="sk-ant-..."
export OPENCLAW_GATEWAY_TOKEN="$(openssl rand -hex 32)"
```

```json5
{
  gateway: { auth: { token: "${OPENCLAW_GATEWAY_TOKEN}" } },
}
```

**Use a separate token for hooks** (`hooks.token`). Reusing the gateway token means anything holding the hook token holds gateway access.

### Audit

```bash
openclaw secrets audit
```

Finds plaintext credentials in your config. Run it after any config change you made by hand.

### Rotation

```bash
openclaw auth login <provider>       # add or refresh a profile
openclaw auth list
```

Multiple profiles per provider also give you **rotation across four time scales** (§39.4.1) — per-request round-robin, per-error cooldown, per-window quota, and per-day reset. Useful for availability, and it means one leaked key isn't your only key.

## 10.2.4 The Audit and What Its Severities Mean

```bash
openclaw security audit
```

This is the single most useful hardening command, and the reason is subtle: **its severities are computed against your actual configuration, not the check in the abstract** (§32.6.4).

```
Same finding, different severity:

  bind: lan + auth: none, no channels attached      → warning
  bind: lan + auth: none, public Discord attached   → CRITICAL
```

The audit knows which channels are live, which policies are open, and what's reachable. A "warning" you dismissed six months ago can legitimately be critical today because you attached a channel since — **and the audit is what remembers to re-evaluate that, which you won't.**

So: run it after every change to bindings, channels, or tool policy, and take a critical seriously even if the same line was a warning last time.

### A minimal hardened baseline

```json5
{
  gateway: { bind: "loopback", auth: { mode: "token" } },
  plugins: { allow: ["telegram"] },
  channels: {
    telegram: {
      dmPolicy: "pairing",
      groupPolicy: "allowlist",
      requireMention: true,
    },
  },
  tools: { exec: { security: "allowlist", ask: "on-miss" } },
  agents: {
    defaults: {
      sandbox: { mode: "non-main" },
      allowUnsafeExternalContent: false,
    },
  },
}
```

Every line here is doing one job: **narrowing what a manipulated agent can reach.** None of it tries to stop the manipulation — that's the point.

***

## Section Summary

1. **Prompt injection is explicitly out of scope**, and deliberately so — a system built to follow natural language can't reliably tell your instructions from instructions in content it reads. **The design limits what a manipulated agent can do instead of claiming a defense that would fail.**
2. **That reframes all hardening**: you're not preventing the agent from being fooled, you're arranging for it not to matter much.
3. **Six layers**: loopback + token, sender allowlists, exec allowlist with `ask: "on-miss"`, sandboxing, explicit `plugins.allow`, and `allowUnsafeExternalContent: false`.
4. **Allowlist on stable numeric IDs, never display names** — display names are reassignable, so such an allowlist is one an attacker can join by renaming.
5. **A sandboxed session may not spawn ACP, and `sandbox="require"` is ineffective there** — stated bluntly because a switch that looks effective and isn't is worse than no switch.
6. **`plugins.allow` defaults to empty, meaning "discovered equals loaded"** — and plugins run in-process with no restriction, so installing one is running its code as yourself.
7. **Use a separate `hooks.token`**, keep secrets in environment variables, and run `openclaw secrets audit` after hand edits.
8. **`openclaw security audit` rates severities against your live configuration** — a dismissed warning can become critical because you attached a channel since, and the audit is what remembers to re-evaluate that.
