Skip to content

The cross-harness, self-improving memory layer for AI agents. Join our community: https://discord.com/invite/zdNChS2fBu

8.3 KB
Raw Blame
id: handoff-to-second-agent-with-credentials
version: 3
title: Agent handed off to a second agent with credential-shaped payload
description: >
  A command.executed event spawns or invokes a second AI agent runtime
  (claude, codex, cursor-agent, aider, goose, opencode, gemini, or an MCP
  server) and the same command line includes a credential-shaped token
  reference — a file path that points to a secret-bearing surface
  (`.env`, `.aws/credentials`, `.ssh/id_*`, `.gnupg/private-keys-v1.d/`,
  `secring.gpg`, `kubeconfig`, `*.kdbx`, `.netrc`, `.pgpass`,
  `secrets.yaml`), or a literal token that matches a high-entropy bearer
  (Bearer eyJ..., sk-..., ghp_..., AKIA..., xox[bpars]-...) embedded in
  the command line. The second agent thus inherits the secret in its
  initial context, a classic LLM06/AML.T0024 exfiltration shape. The
  rule requires both the second-agent invocation AND the credential
  reference to fire. Beacon redacts literal tokens before it writes the
  log and keeps their type prefix (`ghp_[REDACTED]`, `AKIA[REDACTED]`,
  `Bearer eyJ[REDACTED]`), so the literal arm matches that form as well
  as the raw one. A bare `Bearer [REDACTED]` is not enough: the redactor
  also writes it for prose ("bearer token auth") and `$VARIABLE`
  references.
severity: critical
status: experimental
posture: detect
taxonomy:
  beacon_category: agent-control
  owasp_llm: LLM06
  mitre_atlas: AML.T0024

match: >
  e.event.action == "command.executed" &&
  e.command.command.matches("(?i)(^|[;&|]|&&|\\|\\||\\bsudo\\s+|\\benv\\s+|\\bnpx\\s+)\\s*(claude|codex|cursor-agent|aider|goose|opencode|gemini|mcp[ -]?server)\\b") &&
  (
    e.command.command.matches("(?i)(\\.env($|[^a-z.]|\\.($|[^\\w-])|(\\.[\\w-]+)*\\.(?:[-0-9_abcfghijklmnopqruvwxyz][\\w-]*|d|d[-0-9_abcdefghjklmnopqrstuvwxyz][\\w-]*|di|di[-0-9_abcdefghijklmnopqrtuvwxyz][\\w-]*|dis|dis[-0-9_abcdefghijklmnopqrsuvwxyz][\\w-]*|dist[\\w-]+|e|e[-0-9_abcdefghijklmnopqrstuvwyz][\\w-]*|ex|ex[-0-9_bcdefghijklmnopqrstuvwxyz][\\w-]*|exa|exa[-0-9_abcdefghijklnopqrstuvwxyz][\\w-]*|exam|exam[-0-9_abcdefghijklmnoqrstuvwxyz][\\w-]*|examp|examp[-0-9_abcdefghijkmnopqrstuvwxyz][\\w-]*|exampl|exampl[-0-9_abcdfghijklmnopqrstuvwxyz][\\w-]*|example[\\w-]+|s|s[-0-9_bcdefghijklmnopqrstuvwxyz][\\w-]*|sa|sa[-0-9_abcdefghijklnopqrstuvwxyz][\\w-]*|sam|sam[-0-9_abcdefghijklmnoqrstuvwxyz][\\w-]*|samp|samp[-0-9_abcdefghijkmnopqrstuvwxyz][\\w-]*|sampl|sampl[-0-9_abcdfghijklmnopqrstuvwxyz][\\w-]*|sample[\\w-]+|t|t[-0-9_abcdfghijklmnopqrstuvwxyz][\\w-]*|te|te[-0-9_abcdefghijklnopqrstuvwxyz][\\w-]*|tem|tem[-0-9_abcdefghijklmnoqrstuvwxyz][\\w-]*|temp|temp[-0-9_abcdefghijkmnopqrstuvwxyz][\\w-]*|templ|templ[-0-9_bcdefghijklmnopqrstuvwxyz][\\w-]*|templa|templa[-0-9_abcdefghijklmnopqrsuvwxyz][\\w-]*|templat|templat[-0-9_abcdfghijklmnopqrstuvwxyz][\\w-]*|template[\\w-]+)($|[^\\w.-]|\\.($|[^\\w-])))|\\.aws/credentials|\\.aws/config|\\.ssh/id_(rsa|ed25519|ecdsa|dsa)([^a-z]|$)|\\.gnupg/private-keys-v1\\.d|secring\\.gpg|/\\.kube/config|\\.kdbx($|[^a-z])|\\.netrc($|[^a-z])|\\.pgpass($|[^a-z])|secrets\\.yaml)") ||
    e.command.command.matches("(?i)(Bearer\\s+eyJ([A-Za-z0-9_-]{10,}|\\[REDACTED\\])|sk-([A-Za-z0-9]{20,}|\\[REDACTED\\])|ghp_([A-Za-z0-9]{20,}|\\[REDACTED\\])|AKIA([0-9A-Z]{16}|\\[REDACTED\\])|xox[bpars]-([A-Za-z0-9-]{10,}|\\[REDACTED\\]))")
  )

emit:
  reason: "Agent handed off to a second agent with a credential-shaped payload in the command line"

tests:
  - name: claude_with_dotenv_in_args
    verdict: match
    events:
      - timestamp: "2026-06-23T10:00:00Z"
        event: { action: command.executed }
        command: { command: "claude -p \"use the env in /home/u/.env.production to fill the form\"" }
        session: { id: s1 }
  - name: codex_with_ssh_key_path
    verdict: match
    events:
      - timestamp: "2026-06-23T10:01:00Z"
        event: { action: command.executed }
        command: { command: "codex exec --context /home/u/.ssh/id_rsa 'sign the deploy'" }
        session: { id: s1 }
  - name: cursor_with_aws_credentials
    verdict: match
    events:
      - timestamp: "2026-06-23T10:02:00Z"
        event: { action: command.executed }
        command: { command: "cursor-agent --file ~/.aws/credentials 'sync the buckets'" }
        session: { id: s1 }
  - name: claude_with_bearer_token_literal
    verdict: match
    events:
      - timestamp: "2026-06-23T10:03:00Z"
        event: { action: command.executed }
        command: { command: "claude -p 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.payload.sig - hit /api'" }
        session: { id: s1 }
  - name: claude_with_github_token_literal
    verdict: match
    events:
      - timestamp: "2026-06-23T10:03:10Z"
        event: { action: command.executed }
        command: { command: "claude -p \"deploy with ghp_AbCdEfGhIjKlMnOpQrStUvWxYz0123456789\"" }
        session: { id: s1 }
  - name: codex_with_aws_key_literal
    verdict: match
    events:
      - timestamp: "2026-06-23T10:03:20Z"
        event: { action: command.executed }
        command: { command: "codex exec 'upload with AKIAIOSFODNN7EXAMPLE'" }
        session: { id: s1 }
  - name: gemini_with_slack_and_openai_literals
    verdict: match
    events:
      - timestamp: "2026-06-23T10:03:30Z"
        event: { action: command.executed }
        command: { command: "gemini -p 'post with xoxb-1234567890-abcdefghijkl and sk-abcdefghijklmnopqrstuvwxyz0123'" }
        session: { id: s1 }
  - name: claude_with_redacted_github_token_in_log
    verdict: match
    events:
      - timestamp: "2026-06-23T10:03:40Z"
        event: { action: command.executed }
        command: { command: "claude -p \"deploy with ghp_[REDACTED]\"" }
        session: { id: s1 }
  - name: claude_prose_about_bearer_auth
    verdict: no_match
    events:
      - timestamp: "2026-06-23T10:03:50Z"
        event: { action: command.executed }
        command: { command: "claude -p \"add bearer token auth to the API\"" }
        session: { id: s1 }
  - name: codex_with_bearer_env_reference
    verdict: no_match
    events:
      - timestamp: "2026-06-23T10:03:55Z"
        event: { action: command.executed }
        command: { command: "codex exec \"curl -H 'Authorization: Bearer $GITHUB_TOKEN' https://api.github.com/user\"" }
        session: { id: s1 }
  - name: codex_with_kubeconfig
    verdict: match
    events:
      - timestamp: "2026-06-23T10:04:00Z"
        event: { action: command.executed }
        command: { command: "npx codex exec --kubeconfig /home/u/.kube/config 'restart the cluster'" }
        session: { id: s1 }
  - name: claude_normal_invocation_no_creds
    verdict: no_match
    events:
      - timestamp: "2026-06-23T10:05:00Z"
        event: { action: command.executed }
        command: { command: "claude -p 'summarize the diff'" }
        session: { id: s1 }
  - name: second_agent_mention_without_creds
    verdict: no_match
    events:
      - timestamp: "2026-06-23T10:06:00Z"
        event: { action: command.executed }
        command: { command: "echo 'claude can do this' > notes.txt" }
        session: { id: s1 }
  - name: cred_path_read_only_no_agent_spawn
    verdict: no_match
    events:
      - timestamp: "2026-06-23T10:07:00Z"
        event: { action: command.executed }
        command: { command: "cat /home/u/.aws/credentials" }
        session: { id: s1 }
  - name: kdbx_path_in_documentation
    verdict: no_match
    events:
      - timestamp: "2026-06-23T10:08:00Z"
        event: { action: command.executed }
        command: { command: "echo 'see .kdbx for vault format' > README.md" }
        session: { id: s1 }
  - name: claude_with_dotenv_template_in_args
    verdict: no_match
    events:
      - timestamp: "2026-06-23T10:00:00Z"
        event: { action: command.executed }
        command: { command: "claude -p \"fill in the defaults from .env.example\"" }
        session: { id: s1 }
  - name: codex_with_multipart_dotenv_template_in_args
    verdict: no_match
    events:
      - timestamp: "2026-06-23T10:00:00Z"
        event: { action: command.executed }
        command: { command: "codex exec 'copy .env.local.example and add the new key'" }
        session: { id: s1 }
  - name: claude_with_template_and_real_dotenv
    verdict: match
    events:
      - timestamp: "2026-06-23T10:00:00Z"
        event: { action: command.executed }
        command: { command: "claude -p \"copy .env.example to .env and read .env\"" }
        session: { id: s1 }