feat(rules): add AI600-AI900 security rules for agents, RAG, API keys, and output handling - #92
Conversation
…API keys, and output handling Adds 18 new rules covering: - AI600: Unsafe agent behavior & tool poisoning (web browsing, subprocess, file write, indirect injection) - AI700: RAG security (embedding poisoning, context overflow, untrusted sources) - AI800: API key management (OpenAI, Anthropic, Cohere hardcoded keys) - AI900: Output handling & DoS (YAML unsafe load, JSON DoS, exec/eval of LLM output, XSS) Also adds 4 new taint sources/sinks for RAG and agent web tool flows. Closes ParzivalHack#91
|
Hello @mmustafasenoglu thanks for adding the AI600-AI900 rules. The security coverage is valuable, but I recommend requesting changes before merging because several rules currently produce false positives or do not match their stated behavior. Some comments:
The tests currently focus mostly on positive regex matches. Please add negative tests for ordinary HTTP clients, subprocess usage, JSON parsing, trusted embedding models, normal file writes, sanitized HTML, and multiline code. Taint-flow tests should also verify that trusted constants do not become tainted and that duplicate AI501/AI601 findings are avoided. I suggest narrowing or removing the broad regex rules and using AST/taint analysis where the rule depends on data flow or agent context. After these corrections, the proposed rule categories should be much more useful with less noise. |
- Remove AI601/AI603/AI604: line-based regex cannot establish agent context; SSRF and file access already covered by AI501/AISK08 and AI502/AISK09 taint analysis - Remove AITS12/AISK11: AITS12 tainted every requests.get response, AISK11 duplicated the existing AISK08 sink - AI602: require shell=True instead of flagging all subprocess usage - AI702: pattern now checks score_threshold (was checking top-k count) - AI902/AI903/AI904: narrow patterns to LLM-output variables; drop broad .*response|.*output|.*completion alternatives that matched any line containing those words - AI904: exclude sanitized output (sanitize|bleach) - AITS11: fix malformed function path, match instance calls via .similarity_search - Add negative tests: plain HTTP clients, subprocess without shell, plain json.loads, other embedding models, sanitized HTML, top-k without threshold, plain eval, multiline taint flow - Taint tests: trusted constants stay untainted, no duplicate AI501/AI601 findings
|
Thanks for the detailed review, @desimetallica — you're right on every point. I've reworked the rules and addressed all of it in 2a73c99. Removed (couldn't reliably prove agent context with line-based regex, or duplicated existing coverage):
Narrowed:
Lowered confidence / clarified: AI605, AI701, AI703, AI704 now carry New tests (68 in total now):
The broader rules that depend on data flow or agent context are now taint-driven rather than regex-driven, so the remaining regexes should produce much less noise. |
Summary
Adds 18 new AI/LLM security rules covering understimated attack surfaces: unsafe agent behavior, RAG pipeline security, hardcoded API keys, and unsafe output handling.
Motivation
Closes #91
The existing ruleset covers prompt injection and model deserialization well, but modern LLM applications have expanded attack surfaces that weren't being caught. This adds coverage for:
Changes
AI600 - Unsafe Agent Behavior & Tool Poisoning
AI700 - RAG Security
AI800 - API Key & Credential Management
AI900 - Output Handling & DoS
Also adds 4 new taint sources/sinks (AITS11-12, AISK11-12) for RAG vector store retrieval and agent web tool flows.
Testing