Skip to content

False positive: a '.env' substring anywhere in a command is tagged as credential access #40

Closed

Description

@blitzcrieg1

Found during dogfood triage on 2026-08-04. It produced two separate critical false positives from a single mis-tagged event.

What happens

_CREDENTIAL_PATTERNS in apps/orchestrator/agentmetry/core/audit/mitre.py:116 contains the bare string ".env", matched with p in text against the whole command. Any command whose text happens to contain those four characters is tagged T1552.001 Credentials In Files.

The event that triggered it was a Python heredoc rewriting import paths across source files. It contained:

from agentmetry.core.diagnostics.env_file import upsert_env_key

diagnostics.env_file contains .env. No credential was read.

$ echo ...diagnostics.env_file...
  mitre  -> T1552.001 Credentials In Files
  traits -> []

Why it matters more than one bad tag

classify_command() returns zero traits for that command. The credential verdict comes only from the MITRE mapper, and the sequence rules trust it. So two classifiers disagree, the rules consume the weaker one, and one mis-tagged event became the credential-access half of two separate critical findings:

  • credential-exfil (credential access then network egress)
  • dotfile-read-then-git-push (credential read then git push)

Both were dispositioned false_positive. The git push in the second one was real and correctly traited; only its partner was fiction.

Any commit message, doc edit, or source file mentioning .env does this. That is a common thing for a coding agent to touch, which makes this a recurring critical-severity false positive, and critical false positives are how a feed gets muted.

Suggested fix

Two parts, and the second is the more important one:

  1. Require a path-ish or read-ish context around .env rather than a bare substring anywhere in the command. Reuse mask_literals() so quoted example text does not count.
  2. Decide which classifier is authoritative for credential access. Sequence rules keying off MITRE tags while classify_command() says otherwise means the trait layer can be improved without the rules noticing. A credential_access trait that both consume would make the disagreement impossible rather than merely unlikely.

Acceptance criteria

  • A benchmark corpus case: a command mentioning .env in an import path or commit message produces no detection.
  • The existing true positive (an actual cat ~/.aws/credentials-style read) still fires.
  • agentmetry benchmark green, including zero false positives on the benign half.

Blocked until the dogfood gate closes. The detection sources are frozen for the current four-week run and landing this restarts the clock. Tracked so it is not lost, not to be merged yet.

Activity

  1. added
    bug
    detection-rule
    on Aug 4, 2026
  2. blitzcrieg1 commented on Aug 5, 2026

    @blitzcrieg1
    OwnerAuthor

    Fixed in 74edf7e, along with the deeper problem this issue names.

    The .env substring. .env now needs to look like a path (~/.env, ./.env, config/.env.local) or sit directly after something that reads a file. Anchoring it as a filename was not enough on its own: git commit -m "docs: explain .env handling" still matched, and a commit message is the single most likely place for a developer to type it.

    The split brain, which mattered more. Credential recognition existed twice, and the sequence rules read only the MITRE tag, so the mapper was the sole opinion that counted while being the one with less information and no corpus. traits.py now owns the patterns, mitre.py imports them, and _is_credential_access accepts either signal.

    While closing it I also widened credential access to cover environment variables, which was the larger hole: echo $AWS_SECRET_ACCESS_KEY was generic Execution, so credential-exfil could not fire on the way every container and CI runner holds secrets.

    Corpus grew 20 → 24. The new benign case pins the counterweight: a commit message naming .env, an attack string echoed into docs, a fixture written to disk. Benchmark green, 17/17 detected, 0 false positives, 695 tests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugdetection-rule

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions