Documentation

Secret exposure alerts

People paste API keys into coding agents. Agents put keys into commands and write them into files. Once that has happened the key should be treated as exposed, and somebody needs to know.

The Countersign hook looks for keys and tokens on the machine where the agent runs. When it finds one it reports what kind of secret it was, where it appeared, which agent and when. It never reports the value.

What is looked at

WhereWhat the hook readsReported as
A prompt you sendThe text of the promptprompt
A shell command the agent is about to runThe commandcommand
An address the agent is about to fetchThe URLurl
A file the agent is about to write or editThe new text going into the filefile
Any other tool call, such as an MCP toolIts text argumentsarguments

The text an edit removes from a file is not looked at. An agent that deletes a key it found in a file does not raise an alert for doing so.

The kinds of secret

KindName in a ruleLooked for in
Private key (a PEM block)private_keyEverywhere
AWS access keyaws_keyEverywhere
GitHub tokengithub_tokenEverywhere
API key with a known prefix: Anthropic and OpenAI (sk-), Stripe (sk_live_, sk_test_, rk_live_, rk_test_), Slack tokens (xox), Google (AIza), npm (npm_), GitLab (glpat-)api_keyEverywhere
Webhook address for Slack, Discord or Microsoft TeamswebhookEverywhere
Signed web token (JWT)web_tokenEverywhere
Bearer token after the word "Bearer"bearer_tokenPrompts, commands, URLs, arguments
Password inside a URL (://user:password@host)url_passwordPrompts, commands, URLs, arguments
A value assigned to a name such as password, token, secret or api_keyassigned_secretCommands only

The last three are looser shapes. They are left out of file contents because ordinary source code is full of lines like password = form["password"], and an alert on each of those would bury the real ones.

What is recorded

One entry in the ledger for each prompt or tool call that carried a secret. It is an ordinary action, signed by the agent and by the engine, with two extra facts.

FactExampleMeaning
secretaws_key,github_tokenThe kinds found
secret_incommandWhere they appeared
secret_repeat1Present when the same value was already reported from that machine in the last day

A prompt is recorded with the tool name prompt. The prompt's text is not sent. A prompt with no secret in it is not reported at all, so the ledger does not learn that you typed anything.

For a file, the path is recorded and the contents are not. For a command, the command is recorded with the secret blanked out, as described in Security and limits. A private key is blanked with its body, up to its END line.

What stays on the machine

  • The value. It is never part of what the hook sends.
  • A fingerprint of each value, kept for a day in ~/.countersign/hook/. It is a hash keyed with the agent's own signing key, and it is what lets the hook mark a second sighting as a repeat. It is not sent.

The record also holds a hash of the prompt, so the entry is bound to one prompt. That hash is keyed with the agent's signing key as well, so nobody without that key can test guesses against it.

The alert

A workspace that has Slack alerts on gets a message for each new sighting. It goes to the channel the workspace owner connected in Settings, Alerts, with Add to Slack or a pasted address. See Team, alerts and replay.

The message says what kind of secret it was, where it appeared, which agent, and whether the action was blocked. It links to the Exposures page.

  • A repeat is recorded and listed. It is not posted again.
  • The alert is sent in recording-only mode too.
  • The owner can switch these messages off in Settings without turning off approval alerts.
  • A workspace on your own machine, started with countersign start, has no Slack setting. Its exposures are on the Exposures page, in countersign log, and flagged in countersign digest.

The Exposures page

Exposures in the console lists every sighting, newest first: the kind, where it appeared, the agent, the time, the receipt number, and whether it was blocked. The value is not there to show.

Warn or block

With no rule, a secret is recorded and alerted on, and the prompt or tool call goes ahead. That is "Warn". The hook also hands the agent a one-line notice for the person. The live runs were scripted sessions, so how each agent shows that notice in its own window has not been checked.

To stop a kind of secret, set it to Block on the Exposures page and choose Sign and activate. Each Block is one rule in your policy. You can write the same rule by hand:

{
  "id": "secrets.private_key",
  "effect": "deny",
  "when": "action.attrs.secret.contains('private_key')",
  "reason": "private keys do not go near an agent"
}

What a block does:

  • On a prompt: the prompt is stopped before the model sees it, and the person is told why.
  • On a tool call: the command does not run, or the file is not written, and the agent is told why.

A blocked secret has still been typed or generated. Blocking stops it going further. Replace the key either way.

You can narrow a rule with any other fact. This one blocks AWS keys in prompts and leaves commands alone:

{
  "id": "no-aws-keys-in-prompts",
  "effect": "deny",
  "when": "action.attrs.secret.contains('aws_key') && action.attrs.secret_in.contains('prompt')",
  "reason": "do not paste AWS keys into an agent"
}

Three things to know about prompts:

  • A passport lists the tools an agent may use. It does not decide what a person may type, so a prompt is never stopped because the passport does not list prompt.
  • "Ask a human" cannot hold a prompt. A rule with that effect stops the prompt, the same as a block.
  • In recording-only mode nothing is stopped, whatever the rules say.

Turning it on

The prompt check needs one more entry in the agent's hook file, beside the two for tool calls.

  • New connections get it. countersign connect and countersign start add all three entries.
  • Agents connected before this feature have the two tool entries only. They report secrets in commands, URLs and files straight away once the CLI is updated. To add the prompt entry, run countersign start again, or the connect command again. countersign doctor says when the prompt entry is missing.
  • By hand: the snippets in Connect an agent show the third entry for each agent.

Limits

  • It matches shapes. A key with a known prefix or format is found. A password that looks like any other word is missed, and so is a key that has been split, encoded or wrapped across lines in an unusual way.
  • It can raise a false alarm. An example key in documentation has the same shape as a real one.
  • It does not look at what the agent reads. A key inside a file the agent opens, or in the output of a command, is not checked. The check covers what goes into the agent from you and what comes out of it as actions.
  • It does not look at attachments. Files and images added to a prompt are not read.
  • It reads the first 2 MB of each prompt, command or file.
  • Hooks only. Agents connected through an SDK, a framework adapter or the MCP gateway blank secrets out of what they record. They do not report exposures.
  • The agent's maker still receives the prompt on Warn. Countersign sits beside the agent. On Warn the prompt goes to the model as usual.
  • A removed hook sees nothing. Someone who can edit the agent's settings can take the hook out. A managed hook file, as in Fleet rollout, is how you prevent that.
  • Minimal facts mode still reports exposures. With --facts minimal the kind of secret and the place are sent. The command, path and URL are not.