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

# Approval hijack: replay and swap attempts

> What the gateway answers when an approved tool call is replayed, changed, or presented by someone else, what the workspace ledger records for each attempt, and how to run the tests yourself.

An approval in Tracelane covers one exact tool call. This page lists the ways an agent, or someone holding its API key, might try to reuse or bend an approval, what the gateway answers for each, and what the workspace ledger records. Each row is a test whose source is in the open-source repository.

> [!NOTE]
>
> This applies to **protected** tool calls that go through the gateway (MCP tool calls covered by a published action policy). Approval holds are a **Preview** and are off until a workspace turns on action control. A call that never reaches the gateway is not seen at all, and tools without a policy are observed, not held.

## What an approval is bound to

When a person approves a held call, the approval is tied to:

* the exact arguments (a digest of the full arguments in canonical JSON form, so key order and spacing do not matter but any changed or added value does),
* the API key that proposed the call,
* the tool, its server and the policy version that held it,
* the workspace.

It can be used once, before it expires.

## What each attempt gets

Send the approval's id in the `X-Tracelane-Approval-Id` header with a call. If the approval does not cover that call, the gateway refuses it, does not contact the tool, and writes one `denied_runtime` row with a reason to your workspace ledger (signed when a signing key is configured). The row holds a digest of the attempted call, never its arguments. A call whose arguments the tool contract cannot read is refused before the approval is checked and writes no row.

| Attempt | Gateway answers | Ledger reason |
| - | - | - |
| Change the amount (including by one minor unit) | `approval_mismatch` | `approval_mismatch` |
| Change the recipient: another account, same last four digits, a case change, a trailing space, a look-alike Unicode letter, a zero-width character | `approval_mismatch` | `approval_mismatch` |
| Add an argument (a destination, a callback URL, a second amount, a nested object) | `approval_mismatch` | `approval_mismatch` |
| Use the approval again after the call ran, with a new `Idempotency-Key` (replay) | `approval_not_approved` | `approval_mismatch` |
| Two calls at the same moment with one approval | one runs; the other gets `approval_not_approved` | `approval_mismatch`, once |
| Present an id from another workspace, or an id that does not exist | `approval_mismatch` (the same answer for both, so it does not reveal whether the id exists) | `approval_mismatch`, in the presenter's own ledger only |
| Present the id with a different API key in the same workspace | `approval_mismatch` | `approval_mismatch`, against that key |
| Use an approval that was denied | `approval_denied` | `approval_denied` |
| Use an approval after it expired | `approval_expired` | `approval_expired` |
| Present an approval that is still waiting, with a changed call | `approval_mismatch` | `approval_mismatch` |

Two things are not refusals:

* Presenting a still-waiting approval with the exact call returns `409 approval_required` again and writes nothing new.
* Retrying a refused attempt with the same `Idempotency-Key` gets the same answer and adds no second row. Retrying a call that already ran, with its original `Idempotency-Key`, returns the stored result and runs nothing again.

After any number of these attempts, the approval still works once for the call it was given for.

## See the attempts

Each refused attempt appears on the **Actions** page with the status **Blocked**; its detail shows the event **Refused at runtime**. The rows are part of the workspace's hash-chained, tamper-evident ledger and are checked by the offline verifier like any other row. See [Audit ledger](https://docs.tracelane.dev/audit-ledger.md).

## Run the tests yourself

The tests run the gateway's real approval and execution code against a throwaway local Postgres. Tool effects are simulated; nothing is sent to a real tool or provider.

```bash theme={"system"}
git clone https://github.com/tracelane/tracelane.git
cd tracelane
# A local Postgres you can create and drop databases on, reached over loopback.
export POSTGRES_TEST_URL=postgres://<user>:<password>@127.0.0.1:5432/<database>
cargo test --locked -p gateway --bin gateway act19_ -- --ignored --test-threads=1
```

The tests are in `crates/gateway/src/action_control/act19_pg_tests.rs`. They fail rather than skip if Postgres is not reachable. The swap sweep runs 33 changed calls and 8 malformed ones against one approval, then runs the genuine call once.

## Limits

* Only protected tool calls through the gateway are covered. The tests do not cover calls made directly to a tool.
* A replay is recorded with the reason `approval_mismatch`; the answer to the caller is the more specific `approval_not_approved`.
* Each new attempt (a new `Idempotency-Key`) adds one row.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.