# Prevent agent takeover

Spot an agent that suddenly acts like someone else. Provenance keeps a baseline per agent and API key, raises named signals, gives one verdict, and steps up, suspends or locks the agent down.

A stolen API key or agent signing key lets someone act as your agent, inside its grants, at every store that accepts it. Provenance sees each authorization, each verify and each signed request at stores that run Identify, so it notices when an agent starts to behave like someone else. The verdict is deterministic: the same activity always gives the same verdict, and the reasons say why.

**Availability:** every plan, at no charge.

**Before you begin:** register your agents and call authorize with `agent_id`; verdicts attach to registered agents. Export the account key.

```bash
export PROVENANCE_API=https://sandbox-api.provenanceauth.com
export PROVENANCE_KEY=prv_test_acct_P9xN2vQ7bT4mW8sYd3cFjLh6gAe1kR5
```

1. **Baseline**: 14 days per agent and API key
2. **Signals**: named, with thresholds
3. **Verdict**: none, elevated or high
4. **Action**: flag, step-up, suspend or lockdown

## 1. Read an agent's verdict

Each agent has a `takeover_risk` on its object and a fuller view at [`GET /v1/mandate/agents/{id}/takeover`](https://provenanceauth.com/docs/api/takeover-protection.md#get-v1-mandate-agents-id-takeover). A new agent is `learning` for its first 7 days.

**curl**

```bash
curl -s -X POST $PROVENANCE_API/v1/mandate/agents \
  -H "Authorization: Bearer $PROVENANCE_KEY" -H "Content-Type: application/json" \
  -d '{ "name": "buyer-bot" }' > agent.json
export AGENT_ID=$(jq -r '.id' agent.json)
curl -s $PROVENANCE_API/v1/mandate/agents/$AGENT_ID/takeover -H "Authorization: Bearer $PROVENANCE_KEY"
```

**Node**

```ts
const agent = await provenance.mandate.agents.create({ name: "buyer-bot" });
const view = await provenance.mandate.takeover.agent(agent.id);
console.log(view.takeoverRisk); // "learning" for the first 7 days
```

**Python**

```python
view = client.mandate.takeover.agent(agent_id)
print(view["takeover_risk"])  # "learning" for the first 7 days
```

```json
{
  "object": "agent_takeover",
  "agent_id": "agt_01M5XPDJXQR46KYMS99XT98SBT",
  "takeover_risk": "learning",
  "takeover_reasons": [],
  "active_event": null,
  "compromised_key_ids": [],
  "history": []
}
```

The baseline holds the last 14 days, one row per agent (and per API key and signing key) per hour: the network families it acts from, its action types and counterparties, its hourly rate and spend, and its client (`agent_integration` and SDK version).

A network family is a named cloud provider from the published lists (`cloud:aws`), or a salted hash of the /24 (IPv4) or /48 (IPv6) whose key rotates every 28 days. Provenance never stores an address, and none enters a token.

## 2. Know the signals

| Signal | Raised when |
| --- | --- |
| `new_network` | The agent acts from a network family it hasn't used in 14 days. |
| `split_use` | One API key or signing key is used from two network families within 5 minutes. |
| `rate_spike` | The hour's authorizations reach 20 and pass 5× the agent's hourly baseline, or the hour's approved spend reaches 1,000 and passes 5× its baseline. |
| `new_behaviour` | More than 3 action types or counterparties the agent has never used, in one hour. |
| `client_change` | The integration or SDK major version changes within one agent session. |
| `denial_burst` | 10 denied actions in an hour that are at least half its verifies, or 2 "I don't recognize this" denials. |
| `network_reports` | Another company reported fraud or an unrecognized charge about the agent in the last 24 hours. |
| `key_leaked` | Someone reported the agent's signing private key, with the private part that matches it (see [if a key leaks](https://provenanceauth.com/docs/account/if-a-key-leaks.md)). |

While an agent is learning, only the signals that need no baseline count: one key on two networks, a burst of denials, network reports and a leaked key.

## 3. Read the verdict

Each signal has a weight: `split_use` and `key_leaked` weigh 2, every other signal 1. A total of 1 is `elevated`; 2 or more is `high`. So two signals, or `split_use` alone, is `high`.

| Verdict | Default action | Other choices |
| --- | --- | --- |
| `elevated` | `flag`: the owner is told; the agent keeps working | `step_up` |
| `high` | `step_up`: every action by the agent needs a person until you answer | `flag`, `suspend`, `lockdown` |

`lockdown` suspends the agent and revokes its sessions and outstanding tokens. Under `step_up`, verify answers `approval_pending` with `step_up_reason: "agent_takeover_step_up"` until a person approves the action:

```json
{
  "object": "mandate_assessment",
  "valid": false,
  "reason": "approval_pending",
  "step_up_reason": "agent_takeover_step_up",
  "policy": { "id": "pol_3F9A1C7E52B04D8E6A1F27C9B4", "version": null, "rule": { "id": "agent_takeover_step_up", "name": null, "phase": "assess", "action": "challenge", "conditions": [] } },
  "takeover": { "takeover_event_id": "tko_01M5XPDJXQR46KYMS99XT98SBT", "risk": "high", "reasons": ["new_network", "rate_spike"] }
}
```

## 4. Choose what happens

Owners and admins set the action per verdict in **Settings → Agents → Takeover protection**, or with [`PUT /v1/mandate/settings/takeover_protection`](https://provenanceauth.com/docs/api/takeover-protection.md#put-v1-mandate-settings-takeover-protection) from a console session. An API key can read the settings and can't change them, so a stolen key can't turn protection off.

**curl**

```bash
curl -s $PROVENANCE_API/v1/mandate/settings/takeover_protection -H "Authorization: Bearer $PROVENANCE_KEY"
```

**Node**

```ts
const settings = await provenance.mandate.takeover.settings();
```

**Python**

```python
settings = client.mandate.takeover.settings()
```

```json
{
  "object": "takeover_protection",
  "mode": "enforce",
  "elevated_action": "flag",
  "high_action": "step_up",
  "leaked_live_keys": "revoke"
}
```

Turn on **shadow mode** (`mode: "shadow"`) to see what would happen first. A shadow event records the verdict and the action it would have taken, and changes nothing: no step-up, suspension or lockdown, no email, task or webhook, and no policy facts.

## 5. Use the verdict in a policy

Policies read two facts:

| Fact | Value |
| --- | --- |
| `agent.takeover_risk` | `none`, `learning`, `elevated` or `high` |
| `agent.takeover_reasons` | The reason codes, comma-separated |

The rule below denies outright instead of stepping up:

```json
{
  "rules": [
    {
      "id": "deny-high-takeover-risk",
      "when": [{ "fact": "agent.takeover_risk", "op": "eq", "value": "high" }],
      "require": { "deny": true }
    }
  ]
}
```

## 6. Answer the owner's alert

A verdict tells owners and admins at once: an email, a console task and the `mandate.agent.takeover_suspected` webhook, each with the reasons, the time and the network families (named or hashed). The event offers two answers, from the console:

- **This was us** ([`POST /v1/mandate/takeover_events/{id}/clear`](https://provenanceauth.com/docs/api/takeover-protection.md#post-v1-mandate-takeover-events-id-clear)): trusts the event's networks, clears its other signals for 2 hours, resumes an agent the event suspended, and records the answer in the decision ledger.
- **Lock it down** ([`POST /v1/mandate/takeover_events/{id}/lock_down`](https://provenanceauth.com/docs/api/takeover-protection.md#post-v1-mandate-takeover-events-id-lock-down)): suspends the agent, revokes its sessions and outstanding tokens, and lists the API keys and signing keys to rotate. It counts as an owner-confirmed takeover: other companies see `takeover_confirmed_30d` on the agent's network record, whatever the usual minimums.

Both take a console session from an owner or admin, and "This was us" asks for a recent second-factor check when the person has one.

## 7. Rotate the keys and resume

After a lockdown, rotate each key in `compromised_key_ids`: [`POST /v1/account/keys/{id}/rotate_secret`](https://provenanceauth.com/docs/api/account.md#post-v1-account-keys-id-rotate-secret) for an API key, and a new signing key followed by [`DELETE /v1/identify/agents/{id}/signing_keys/{key_id}`](https://provenanceauth.com/docs/api/signed-agents.md#delete-v1-identify-agents-id-signing-keys-key-id) for a signing key. Then resume with [`POST /v1/mandate/takeover_events/{id}/recover`](https://provenanceauth.com/docs/api/takeover-protection.md#post-v1-mandate-takeover-events-id-recover).

The agent resumes with a fresh baseline: the hours since the first signal are dropped, and the older ones stay. The compromised keys stay revoked and listed in the agent's history. A plain unsuspend refuses a locked-down agent with `agent_locked_down`.

## Errors you might see

| Code | What to do |
| --- | --- |
| `agent_locked_down` | Rotate the listed keys, then recover the agent from the console. |
| `takeover_event_closed` | The event was already answered; a new suspicion opens a new event. |
| `takeover_rotation_incomplete` | A key in `compromised_key_ids` is still active. Rotate or revoke it first. |
| `authentication_required` | Answers and settings changes take a console session, not an API key. |

## Limitations

- Each signal covers what its row in the table says, and nothing more: an attacker who acts from the agent's usual networks, at its usual rate and with its usual actions raises no signal.
- Network families are as coarse as a cloud provider or a /24, so two agents in the same cloud share a family.
- Identify traffic feeds the baseline when the store's hosted check passes the request's address.

## See also

- [If a key leaks](https://provenanceauth.com/docs/account/if-a-key-leaks.md)
- [Use network signals](https://provenanceauth.com/docs/authorize/guides/use-network-signals.md)
- [Step-up approval](https://provenanceauth.com/docs/mandate/guides/step-up-approval.md)
