Skip to content

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

26.9 KB
Raw Blame
id: credential-file-read
version: 3
title: Agent read a credential-bearing file
description: >
  The agent read a concrete secret artifact — cloud credentials, an SSH private
  key, a dotenv file, a git credential store, .netrc/.pgpass, or a generic
  credentials file, a package registry token file (.npmrc, .pypirc), a
  Docker, GitHub CLI, gcloud or Azure CLI credential store, or Terraform state.
  It matches the secret-bearing member only (e.g. ~/.aws/credentials not
  ~/.aws/config, id_rsa not id_rsa.pub), whether read with a file tool or with
  a shell command such as cat, head, grep or base64 — on Claude Code a Bash
  `cat .env` is recorded as command.executed, not file.read. Committed dotenv
  templates (.env.example, .env.sample, .env.template, .env.dist, including
  names such as .env.local.example) hold no secrets and do not match.
severity: high
status: stable
posture: detect
taxonomy:
  beacon_category: credential-access
  owasp_llm: LLM02
  mitre_atlas: AML.T0024

match: >
  (
    e.event.action == "file.read" && (
      (e.file.path.matches("(?i)(^|/)\\.env($|\\.)") && !e.file.path.matches("(?i)(^|/)\\.env(\\.[\\w-]+)*\\.(example|sample|template|dist)$")) ||
      e.file.path.matches("(?i)\\.aws/credentials") ||
      e.file.path.matches("(?i)(^|/)id_(rsa|ed25519|ecdsa|dsa)$") ||
      e.file.path.matches("(?i)(^|/)\\.git-credentials$") ||
      e.file.path.matches("(?i)/\\.config/git/credentials$") ||
      e.file.path.matches("(?i)(^|/)(\\.netrc|\\.pgpass)$") ||
      e.file.path.matches("(?i)(^|/)credentials(\\.json|\\.toml)?$") ||
      e.file.path.matches("(?i)(^|/)(\\.npmrc|\\.pypirc)$") ||
      e.file.path.matches("(?i)(^|/)\\.docker/config\\.json$") ||
      e.file.path.matches("(?i)(^|/)\\.config/gh/hosts\\.yml$") ||
      e.file.path.matches("(?i)(^|/)application_default_credentials\\.json$") ||
      e.file.path.matches("(?i)/\\.config/gcloud/(credentials|access_tokens)\\.db$") ||
      e.file.path.matches("(?i)/\\.azure/(msal_token_cache|accesstokens)\\.json$") ||
      e.file.path.matches("(?i)\\.tfstate(\\.backup)?$") ||
      e.file.path.matches("(?i)/\\.terraform\\.d/credentials\\.tfrc\\.json$")
    )
  ) || (
    e.event.action == "command.executed" &&
    (e.command.command.matches("(?i)(^|[;&|(`]|\\$\\()\\s*(sudo\\s+)?(cat|tac|head|tail|less|more|bat|nl|strings|xxd|od|hexdump|base64)\\b[^;&|>\\n]*?[\\s/'\"=](\\.env((\\.[\\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-]+))?|\\.aws/credentials|id_(rsa|ed25519|ecdsa|dsa)|\\.git-credentials|\\.netrc|\\.pgpass|credentials(\\.json|\\.toml)?|\\.npmrc|\\.pypirc|\\.docker/config\\.json|\\.config/gh/hosts\\.yml|application_default_credentials\\.json|\\.config/gcloud/(credentials|access_tokens)\\.db|\\.azure/(msal_token_cache|accesstokens)\\.json|[\\w.-]*\\.tfstate(\\.backup)?|\\.terraform\\.d/credentials\\.tfrc\\.json)($|[\\s'\";|&)<>])") || e.command.command.matches("(^|[;&|(`]|\\$\\()\\s*(sudo\\s+)?tar(?:\\s+[A-Za-z]*[cru][A-Za-z]*|(?:\\s+(?:(?:[^\\s;&|>-][^\\s;&|>]*|-|-[^\\s;&|>x-][^\\s;&|>]*|-x[^\\s;&|>]+|--(?:|[^\\s;&|>e][^\\s;&|>]*|e|e[^\\s;&|>x][^\\s;&|>]*|ex|ex[^\\s;&|>c][^\\s;&|>]*|exc|exc[^\\s;&|>l][^\\s;&|>]*|excl|excl[^\\s;&|>u][^\\s;&|>]*|exclu|exclu[^\\s;&|>d][^\\s;&|>]*|exclud|exclud[^\\s;&|>e][^\\s;&|>]*|exclude[^\\s;&|>]+))|--exclude(?:=[^\\s;&|>]*|\\s+[^\\s;&|>]+)|-x(?:\\s+[^\\s;&|>-][^\\s;&|>]*)*\\s+(?:-|-[^\\s;&|>x-][^\\s;&|>]*|-x[^\\s;&|>]+|--(?:|[^\\s;&|>e][^\\s;&|>]*|e|e[^\\s;&|>x][^\\s;&|>]*|ex|ex[^\\s;&|>c][^\\s;&|>]*|exc|exc[^\\s;&|>l][^\\s;&|>]*|excl|excl[^\\s;&|>u][^\\s;&|>]*|exclu|exclu[^\\s;&|>d][^\\s;&|>]*|exclud|exclud[^\\s;&|>e][^\\s;&|>]*|exclude[^\\s;&|>]+))))*?\\s+(?:-[A-Za-z]*[cru][A-Za-z]*|--(?:create|append|update)))(?:\\s+(?:(?:[^\\s;&|>-][^\\s;&|>]*|-|-[^\\s;&|>x-][^\\s;&|>]*|-x[^\\s;&|>]+|--(?:|[^\\s;&|>e][^\\s;&|>]*|e|e[^\\s;&|>x][^\\s;&|>]*|ex|ex[^\\s;&|>c][^\\s;&|>]*|exc|exc[^\\s;&|>l][^\\s;&|>]*|excl|excl[^\\s;&|>u][^\\s;&|>]*|exclu|exclu[^\\s;&|>d][^\\s;&|>]*|exclud|exclud[^\\s;&|>e][^\\s;&|>]*|exclude[^\\s;&|>]+))|--exclude(?:=[^\\s;&|>]*|\\s+[^\\s;&|>]+)|-x(?:\\s+[^\\s;&|>-][^\\s;&|>]*)*\\s+(?:-|-[^\\s;&|>x-][^\\s;&|>]*|-x[^\\s;&|>]+|--(?:|[^\\s;&|>e][^\\s;&|>]*|e|e[^\\s;&|>x][^\\s;&|>]*|ex|ex[^\\s;&|>c][^\\s;&|>]*|exc|exc[^\\s;&|>l][^\\s;&|>]*|excl|excl[^\\s;&|>u][^\\s;&|>]*|exclu|exclu[^\\s;&|>d][^\\s;&|>]*|exclud|exclud[^\\s;&|>e][^\\s;&|>]*|exclude[^\\s;&|>]+))))*?\\s+['\"]?(?:[^\\s;&|>'\"=-][^\\s;&|>'\"]*/)?(?i:\\.env((\\.[\\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-]+))?|\\.aws/credentials|id_(rsa|ed25519|ecdsa|dsa)|\\.git-credentials|\\.netrc|\\.pgpass|credentials(\\.json|\\.toml)?|\\.npmrc|\\.pypirc|\\.docker/config\\.json|\\.config/gh/hosts\\.yml|application_default_credentials\\.json|\\.config/gcloud/(credentials|access_tokens)\\.db|\\.azure/(msal_token_cache|accesstokens)\\.json|[\\w.-]*\\.tfstate(\\.backup)?|\\.terraform\\.d/credentials\\.tfrc\\.json)($|[\\s'\";|&)<>])") || e.command.command.matches("(^|[;&|(`]|\\$\\()\\s*(sudo\\s+)?zip(?:\\s+(?:(?:[^\\s;&|>-][^\\s;&|>]*|-|-[^\\s;&|>x-][^\\s;&|>]*|-x[^\\s;&|>]+|--(?:|[^\\s;&|>e][^\\s;&|>]*|e|e[^\\s;&|>x][^\\s;&|>]*|ex|ex[^\\s;&|>c][^\\s;&|>]*|exc|exc[^\\s;&|>l][^\\s;&|>]*|excl|excl[^\\s;&|>u][^\\s;&|>]*|exclu|exclu[^\\s;&|>d][^\\s;&|>]*|exclud|exclud[^\\s;&|>e][^\\s;&|>]*|exclude[^\\s;&|>]+))|--exclude(?:=[^\\s;&|>]*|\\s+[^\\s;&|>]+)|-x(?:\\s+[^\\s;&|>-][^\\s;&|>]*)*\\s+(?:-|-[^\\s;&|>x-][^\\s;&|>]*|-x[^\\s;&|>]+|--(?:|[^\\s;&|>e][^\\s;&|>]*|e|e[^\\s;&|>x][^\\s;&|>]*|ex|ex[^\\s;&|>c][^\\s;&|>]*|exc|exc[^\\s;&|>l][^\\s;&|>]*|excl|excl[^\\s;&|>u][^\\s;&|>]*|exclu|exclu[^\\s;&|>d][^\\s;&|>]*|exclud|exclud[^\\s;&|>e][^\\s;&|>]*|exclude[^\\s;&|>]+))))*?\\s+['\"]?(?:[^\\s;&|>'\"=-][^\\s;&|>'\"]*/)?(?i:\\.env((\\.[\\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-]+))?|\\.aws/credentials|id_(rsa|ed25519|ecdsa|dsa)|\\.git-credentials|\\.netrc|\\.pgpass|credentials(\\.json|\\.toml)?|\\.npmrc|\\.pypirc|\\.docker/config\\.json|\\.config/gh/hosts\\.yml|application_default_credentials\\.json|\\.config/gcloud/(credentials|access_tokens)\\.db|\\.azure/(msal_token_cache|accesstokens)\\.json|[\\w.-]*\\.tfstate(\\.backup)?|\\.terraform\\.d/credentials\\.tfrc\\.json)($|[\\s'\";|&)<>])") || e.command.command.matches("(?i)(^|[;&|(`]|\\$\\()\\s*(sudo\\s+)?cp\\b[^;&|>\\n]*?[\\s/'\"=](\\.env((\\.[\\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-]+))?|\\.aws/credentials|id_(rsa|ed25519|ecdsa|dsa)|\\.git-credentials|\\.netrc|\\.pgpass|credentials(\\.json|\\.toml)?|\\.npmrc|\\.pypirc|\\.docker/config\\.json|\\.config/gh/hosts\\.yml|application_default_credentials\\.json|\\.config/gcloud/(credentials|access_tokens)\\.db|\\.azure/(msal_token_cache|accesstokens)\\.json|[\\w.-]*\\.tfstate(\\.backup)?|\\.terraform\\.d/credentials\\.tfrc\\.json)['\"]?\\s+[^\\s;&|<>]") || e.command.command.matches("(?i)(^|[;&|(`]|\\$\\()\\s*(sudo\\s+)?(grep|egrep|fgrep|rg|awk|sed|jq)\\b[^;&|>\\n]*?(\\s['\"]?[^\\s;&|'\"]*/(\\.env((\\.[\\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-]+))?|\\.aws/credentials|id_(rsa|ed25519|ecdsa|dsa)|\\.git-credentials|\\.netrc|\\.pgpass|credentials(\\.json|\\.toml)?|\\.npmrc|\\.pypirc|\\.docker/config\\.json|\\.config/gh/hosts\\.yml|application_default_credentials\\.json|\\.config/gcloud/(credentials|access_tokens)\\.db|\\.azure/(msal_token_cache|accesstokens)\\.json|[\\w.-]*\\.tfstate(\\.backup)?|\\.terraform\\.d/credentials\\.tfrc\\.json)($|[\\s'\";|&)<>])|\\s[^\\s-][^\\s;&|>]*\\s+(\\.env((\\.[\\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-]+))?|\\.aws/credentials|id_(rsa|ed25519|ecdsa|dsa)|\\.git-credentials|\\.netrc|\\.pgpass|credentials(\\.json|\\.toml)?|\\.npmrc|\\.pypirc|\\.docker/config\\.json|\\.config/gh/hosts\\.yml|application_default_credentials\\.json|\\.config/gcloud/(credentials|access_tokens)\\.db|\\.azure/(msal_token_cache|accesstokens)\\.json|[\\w.-]*\\.tfstate(\\.backup)?|\\.terraform\\.d/credentials\\.tfrc\\.json)\\s*($|[;&|)]))"))
  )

emit:
  reason: "Agent read a credential-bearing file (secret store member)"

tests:
  - name: read_aws_credentials
    verdict: match
    events:
      - event: { action: file.read }
        file: { path: "/home/u/.aws/credentials" }
        session: { id: s1 }
  - name: read_ssh_private_key
    verdict: match
    events:
      - event: { action: file.read }
        file: { path: "/home/u/.ssh/id_ed25519" }
        session: { id: s1 }
  - name: read_dotenv
    verdict: match
    events:
      - event: { action: file.read }
        file: { path: "service/.env.production" }
        session: { id: s1 }
  - name: ssh_public_key_not_secret
    verdict: no_match
    events:
      - event: { action: file.read }
        file: { path: "/home/u/.ssh/id_rsa.pub" }
        session: { id: s1 }
  - name: aws_config_not_credentials
    verdict: no_match
    events:
      - event: { action: file.read }
        file: { path: "/home/u/.aws/config" }
        session: { id: s1 }
  - name: ordinary_source_read
    verdict: no_match
    events:
      - event: { action: file.read }
        file: { path: "src/main.go" }
        session: { id: s1 }
  - name: read_gcloud_adc
    verdict: match
    events:
      - event: { action: file.read }
        file: { path: "/home/u/.config/gcloud/application_default_credentials.json" }
        session: { id: s1 }
  - name: read_docker_config
    verdict: match
    events:
      - event: { action: file.read }
        file: { path: "/home/u/.docker/config.json" }
        session: { id: s1 }
  - name: read_terraform_state
    verdict: match
    events:
      - event: { action: file.read }
        file: { path: "infra/terraform.tfstate" }
        session: { id: s1 }
  - name: read_npmrc
    verdict: match
    events:
      - event: { action: file.read }
        file: { path: "/home/u/.npmrc" }
        session: { id: s1 }
  - name: shell_cat_dotenv
    verdict: match
    events:
      - event: { action: command.executed }
        command: { command: "cat .env" }
        session: { id: s1 }
  - name: shell_head_aws_credentials
    verdict: match
    events:
      - event: { action: command.executed }
        command: { command: "head -n 5 ~/.aws/credentials" }
        session: { id: s1 }
  - name: shell_grep_in_ssh_key_chain
    verdict: match
    events:
      - event: { action: command.executed }
        command: { command: "cd /tmp && grep -c BEGIN $HOME/.ssh/id_ed25519" }
        session: { id: s1 }
  - name: shell_base64_gh_hosts
    verdict: match
    events:
      - event: { action: command.executed }
        command: { command: "base64 ~/.config/gh/hosts.yml" }
        session: { id: s1 }
  - name: shell_cat_public_key
    verdict: no_match
    events:
      - event: { action: command.executed }
        command: { command: "cat ~/.ssh/id_ed25519.pub" }
        session: { id: s1 }
  - name: shell_cat_aws_config
    verdict: no_match
    events:
      - event: { action: command.executed }
        command: { command: "cat ~/.aws/config" }
        session: { id: s1 }
  - name: shell_echo_mentions_dotenv
    verdict: no_match
    events:
      - event: { action: command.executed }
        command: { command: "echo 'copy .env.example to .env'" }
        session: { id: s1 }
  - name: shell_ls_home
    verdict: no_match
    events:
      - event: { action: command.executed }
        command: { command: "ls -la ~/.aws" }
        session: { id: s1 }
  - name: docker_compose_not_docker_config
    verdict: no_match
    events:
      - event: { action: file.read }
        file: { path: "deploy/docker/config.yaml" }
        session: { id: s1 }
  - name: search_pattern_credentials_not_a_read
    verdict: no_match
    events:
      - event: { action: command.executed }
        command: { command: "grep -rn credentials src/" }
        session: { id: s1 }
  - name: search_pattern_id_rsa_not_a_read
    verdict: no_match
    events:
      - event: { action: command.executed }
        command: { command: "rg \"id_rsa\" docs" }
        session: { id: s1 }
  - name: search_pattern_dotenv_not_a_read
    verdict: no_match
    events:
      - event: { action: command.executed }
        command: { command: "grep -r .env .gitignore" }
        session: { id: s1 }
  - name: search_dotenv_as_last_operand
    verdict: match
    events:
      - event: { action: command.executed }
        command: { command: "grep API_KEY .env" }
        session: { id: s1 }
  - name: jq_docker_config_path
    verdict: match
    events:
      - event: { action: command.executed }
        command: { command: "jq .auths ~/.docker/config.json" }
        session: { id: s1 }
  - name: heredoc_write_dotenv_not_read
    verdict: no_match
    events:
      - event: { action: command.executed }
        command: { command: "cat > .env <<'EOF'\nAPI_KEY=changeme\nEOF" }
        session: { id: s1 }
  - name: heredoc_append_npmrc_not_read
    verdict: no_match
    events:
      - event: { action: command.executed }
        command: { command: "cat >> ~/.npmrc <<EOF\n//registry.npmjs.org/:_authToken=${NPM_TOKEN}\nEOF" }
        session: { id: s1 }
  - name: heredoc_write_docker_config_not_read
    verdict: no_match
    events:
      - event: { action: command.executed }
        command: { command: "cat > ~/.docker/config.json <<EOF\n{}\nEOF" }
        session: { id: s1 }
  - name: heredoc_redirect_after_delimiter_not_read
    verdict: no_match
    events:
      - event: { action: command.executed }
        command: { command: "cat <<EOF > .env\nPORT=3000\nEOF" }
        session: { id: s1 }
  - name: cp_template_to_dotenv_not_read
    verdict: no_match
    events:
      - event: { action: command.executed }
        command: { command: "cp .env.example .env" }
        session: { id: s1 }
  - name: cp_into_ssh_key_not_read
    verdict: no_match
    events:
      - event: { action: command.executed }
        command: { command: "cp /tmp/deploy_key ~/.ssh/id_ed25519" }
        session: { id: s1 }
  - name: cp_secret_out_is_read
    verdict: match
    events:
      - event: { action: command.executed }
        command: { command: "cp ~/.aws/credentials /tmp/c" }
        session: { id: s1 }
  - name: cat_dotenv_redirected_out_is_read
    verdict: match
    events:
      - event: { action: command.executed }
        command: { command: "cat .env > /tmp/out" }
        session: { id: s1 }
  - name: cp_template_then_cat_is_read
    verdict: match
    events:
      - event: { action: command.executed }
        command: { command: "cp .env.example .env && cat .env" }
        session: { id: s1 }
  - name: tar_exclude_eq_dotenv_not_read
    verdict: no_match
    events:
      - event: { action: command.executed }
        command: { command: "tar -czf app.tgz --exclude=.env --exclude=node_modules ." }
        session: { id: s1 }
  - name: tar_exclude_space_dotenv_not_read
    verdict: no_match
    events:
      - event: { action: command.executed }
        command: { command: "tar czf out.tgz --exclude .env ." }
        session: { id: s1 }
  - name: zip_x_dotenv_not_read
    verdict: no_match
    events:
      - event: { action: command.executed }
        command: { command: "zip -r out.zip . -x .env" }
        session: { id: s1 }
  - name: tar_including_dotenv_is_read
    verdict: match
    events:
      - event: { action: command.executed }
        command: { command: "tar czf out.tgz src .env" }
        session: { id: s1 }
  - name: zip_including_ssh_key_is_read
    verdict: match
    events:
      - event: { action: command.executed }
        command: { command: "zip k.zip ~/.ssh/id_rsa" }
        session: { id: s1 }
  - name: search_no_path_grep_credentials_not_a_read
    verdict: no_match
    events:
      - event: { action: command.executed }
        command: { command: "grep -rn credentials" }
        session: { id: s1 }
  - name: search_no_path_rg_credentials_not_a_read
    verdict: no_match
    events:
      - event: { action: command.executed }
        command: { command: "rg credentials" }
        session: { id: s1 }
  - name: search_no_path_rg_id_rsa_piped_not_a_read
    verdict: no_match
    events:
      - event: { action: command.executed }
        command: { command: "rg -n id_rsa | head -50" }
        session: { id: s1 }
  - name: search_no_path_rg_dotenv_not_a_read
    verdict: no_match
    events:
      - event: { action: command.executed }
        command: { command: "rg -i .env" }
        session: { id: s1 }
  - name: search_pattern_option_then_dotenv_is_read
    verdict: match
    events:
      - event: { action: command.executed }
        command: { command: "grep -e TOKEN .env" }
        session: { id: s1 }
  - name: tar_exclude_does_not_hide_other_secrets
    verdict: match
    events:
      - event: { action: command.executed }
        command: { command: "tar czf out.tgz --exclude=.env ~/.aws/credentials ~/.ssh/id_rsa" }
        session: { id: s1 }
  - name: tar_exclude_space_does_not_hide_other_secrets
    verdict: match
    events:
      - event: { action: command.executed }
        command: { command: "tar czf out.tgz --exclude .env .aws/credentials" }
        session: { id: s1 }
  - name: zip_x_does_not_hide_earlier_secret
    verdict: match
    events:
      - event: { action: command.executed }
        command: { command: "zip -r k.zip ~/.ssh/id_rsa -x .env" }
        session: { id: s1 }
  - name: zip_x_then_option_then_secret_is_read
    verdict: match
    events:
      - event: { action: command.executed }
        command: { command: "zip -r k.zip . -x .env -i ~/.ssh/id_rsa" }
        session: { id: s1 }
  - name: tar_verbose_long_option_then_secret_is_read
    verdict: match
    events:
      - event: { action: command.executed }
        command: { command: "tar --verbose -czf o.tgz .env" }
        session: { id: s1 }
  - name: tar_excludes_only_secrets_not_read
    verdict: no_match
    events:
      - event: { action: command.executed }
        command: { command: "tar --exclude=.env --exclude=id_rsa -czf a.tgz ." }
        session: { id: s1 }
  - name: zip_x_list_of_secrets_not_read
    verdict: no_match
    events:
      - event: { action: command.executed }
        command: { command: "zip -r out.zip . -x .env credentials.json" }
        session: { id: s1 }
  - name: chained_cp_template_to_dotenv_not_read
    verdict: no_match
    events:
      - event: { action: command.executed }
        command: { command: "cd app && cp .env.example .env" }
        session: { id: s1 }
  - name: cp_template_to_dotenv_local_not_read
    verdict: no_match
    events:
      - event: { action: command.executed }
        command: { command: "cp .env.example .env.local" }
        session: { id: s1 }
  - name: cp_sample_template_variants_not_read
    verdict: no_match
    events:
      - event: { action: command.executed }
        command: { command: "cp -n .env.sample .env; cp .env.template .env.production" }
        session: { id: s1 }
  - name: chained_cp_dotenv_out_is_read
    verdict: match
    events:
      - event: { action: command.executed }
        command: { command: "cd app && cp .env .env.bak" }
        session: { id: s1 }
  - name: cp_dotenv_local_out_is_read
    verdict: match
    events:
      - event: { action: command.executed }
        command: { command: "cp .env.local /tmp/x" }
        session: { id: s1 }
  - name: tar_extract_oldstyle_not_read
    verdict: no_match
    events:
      - event: { action: command.executed }
        command: { command: "tar xzf backup.tgz .env" }
        session: { id: s1 }
  - name: tar_extract_dashed_not_read
    verdict: no_match
    events:
      - event: { action: command.executed }
        command: { command: "tar -xzf backup.tgz .env" }
        session: { id: s1 }
  - name: tar_extract_split_flags_not_read
    verdict: no_match
    events:
      - event: { action: command.executed }
        command: { command: "tar -x -f a.tar ~/.ssh/id_rsa" }
        session: { id: s1 }
  - name: tar_list_not_read
    verdict: no_match
    events:
      - event: { action: command.executed }
        command: { command: "tar tzf backup.tgz .env" }
        session: { id: s1 }
  - name: tar_append_secret_is_read
    verdict: match
    events:
      - event: { action: command.executed }
        command: { command: "tar -rf a.tar .env" }
        session: { id: s1 }
  - name: tar_long_create_secret_is_read
    verdict: match
    events:
      - event: { action: command.executed }
        command: { command: "tar --create -f a.tar ~/.aws/credentials" }
        session: { id: s1 }
  - name: dotenv_example_template_not_secret
    verdict: no_match
    events:
      - event: { action: file.read }
        file: { path: "/repo/.env.example" }
        session: { id: s1 }
  - name: dotenv_multipart_template_not_secret
    verdict: no_match
    events:
      - event: { action: file.read }
        file: { path: "/repo/.env.local.example" }
        session: { id: s1 }
  - name: shell_cat_dotenv_template_not_read
    verdict: no_match
    events:
      - event: { action: command.executed }
        command: { command: "cat .env.example" }
        session: { id: s1 }
  - name: dotenv_local_is_secret
    verdict: match
    events:
      - event: { action: file.read }
        file: { path: "/repo/.env.local" }
        session: { id: s1 }