# Lethal-trifecta containment

An agent becomes dangerous when three things meet in one session:

1. **Private data:** it can read things you don't want to leak (customer records, source code, email).
2. **Untrusted content:** it reads text an attacker can control (web pages, issues, inbound email, documents).
3. **A way out:** it can send data somewhere (email, HTTP requests, comments, messages).

Any two are fine. All three together let a hidden instruction in the untrusted content tell the agent to send the private data out. Models can't reliably tell injected instructions from yours, so Godelgate doesn't try to detect the attack. It removes the path.

## Label your tools

Give each tool the labels that apply, per server, with globs on the tool name:

```yaml
servers:
  - name: github
    command: npx
    args: [-y, "@modelcontextprotocol/server-github"]
    labels:
      "get_*": [private]
      "search_*": [untrusted]
      "list_issues": [private, untrusted]
      "create_*": [egress]
      "add_issue_comment": [egress]
```

| Label | Means | Examples |
| --- | --- | --- |
| `private` | Returns data you don't want leaked | read a CRM, read a private repo, read email |
| `untrusted` | Returns content someone else can write | fetch a URL, read issues or tickets, read inbound mail |
| `egress` | Can send data outside | send email, post a comment, call a webhook, fetch a URL with a query string |

A tool can have several labels. All matching globs apply. Tools with no labels never affect the trifecta.

> When unsure, over-label. A web fetch tool is usually both `untrusted` (it reads attacker content) and `egress` (the URL itself can carry data out).

## How sessions are tracked

Each MCP session keeps two markers, and records which tool set each one:

- **private**, set after a `private` tool returns
- **untrusted**, set after an `untrusted` tool returns

Markers are set only after the upstream server actually answers, and they never reset during the session. Sessions are separate: one agent's history never affects another's. You can see the markers for every active session in the dashboard's **Sessions** tab.

## When a call is blocked

A call completes the trifecta when **all** of these are true:

- the tool is labeled `egress`
- the session already holds private data
- the session already read untrusted content, **or** the tool itself is labeled `untrusted`

What happens next is set by `policy.trifecta`:

| Value | Effect |
| --- | --- |
| `block` (default) | The call is denied with the reason, and logged as `denied` |
| `approve` | The call waits for a human in the dashboard, like an [approval rule](/docs/approvals) |
| `off` | No trifecta checks |

```yaml
policy:
  trifecta: block
```

The agent receives an error result like:

```text
Blocked by Godelgate: lethal trifecta: session read private data
(crm__read_customers) and untrusted content (web__fetch_url);
this tool can send data out
```

## Interaction with rules

The trifecta check runs after deny rules and quarantine, and **before** allow and approve rules. An `allow` rule grants access to a tool; it never grants permission to exfiltrate data after the session read untrusted content. See [Policy rules](/docs/policy) for the full decision order.

## Starting fresh

Because markers last for the whole session, an agent that needs to send something after reading untrusted content should do it in a new session, or a human approves it with `trifecta: approve`. Idle sessions are closed after one hour.
