fix(static-patterns): filter false positives from documentation and code examples
Summary
Static pattern analyzers fire on markdown documentation, fenced code blocks, and inline examples (e.g. curl -k in a README usage guide, rm -rf in a Dockerfile reference) even though these are not executable skill logic. This inflates finding counts and the overall risk score with noise that obscures genuine threats.
Changes
- Centralized
is_code_example()filter instatic_runner.run_static_patterns(): any finding whose surrounding context matches documentation indicators (fenced code blocks, "example:", "for example", "e.g.", etc.) is dropped before conversion toFinding. All 12 static pattern analyzers benefit without per-module changes. - Documentation-path confidence reduction: findings from markdown files in known documentation directories (
docs/,procedures/,references/,examples/,guides/) receive a0.3×confidence multiplier, so they still appear in results but contribute proportionally less to the risk score. - SKILL.md exemption: the primary skill instruction file is explicitly excluded from documentation-path reduction since it contains the agent's executable instructions.
Behavioral Impact
| Scenario | Before | After |
|---|---|---|
curl -k in docs/usage.md inside a code block |
TM1 HIGH (confidence 0.6) | Filtered out (code example) |
rm -rf /var/lib/apt in docs/docker.md prose |
TM1 HIGH (confidence 0.85) | TM1 with confidence 0.255 (0.85 × 0.3) |
subprocess.run(cmd, shell=True) in deploy.py |
TM1 HIGH (confidence 0.9) | TM1 HIGH (confidence 0.9) — unchanged |
Pattern in SKILL.md code block |
TM1 HIGH | Filtered out (code example context) |
Test Plan
- [x] 20 new unit tests covering code-example filtering, documentation-path detection, SKILL.md exemption, and non-documentation paths
- [x] Full test suite: 696 passed, 0 failures, 0 regressions
- [x]
ruff checkandruff formatclean - [x] No new mypy errors introduced (pre-existing type widening in
state.get()calls unchanged)
Fixes #135
PS: These issues were found while running bunch of skill evals using SkillSpector and hence raising all the issues so that i can use these with correct reference to Upstream code
Thanks for catching this — you're right that hard-dropping findings in executable files based on generic indicators is a detection-bypass risk.
Changes made:
is_code_example()now only hard-drops findings in non-executable file types (markdown, text, json, yaml, toml)- For executable files (.py, .sh, .js, .ts, etc.), findings with code-example context are downweighted (0.5x confidence) instead of dropped — this preserves recall while the LLM meta-analyzer can still adjudicate
- Added
_NON_EXECUTABLE_FILE_TYPESfrozenset to gate the behavior - Added test
test_finding_in_executable_not_dropped_by_generic_indicatorthat verifies an attacker cannot suppress a genuine finding in a.pyfile by salting nearby code with# Note: ...
The doc-path 0.3x confidence reduction remains unchanged (only applies to markdown in documentation subdirectories).