Skip to content

feat(rules): add AI600-AI900 security rules for agents, RAG, API keys, and output handling - #93

Open
mmustafasenoglu wants to merge 2 commits into
ParzivalHack:mainfrom
mmustafasenoglu:feat/ai600-900-security-rules
Open

feat(rules): add AI600-AI900 security rules for agents, RAG, API keys, and output handling#93
mmustafasenoglu wants to merge 2 commits into
ParzivalHack:mainfrom
mmustafasenoglu:feat/ai600-900-security-rules

Conversation

@mmustafasenoglu

Copy link
Copy Markdown

Summary

Adds AI600-AI900 security rules for detecting vulnerabilities in AI/LLM-related code:

  • AI600: Agent execution without sandbox detection
  • AI601: Prompt injection pattern detection
  • AI602: Shell command execution with user input
  • AI603: Unsafe deserialization in RAG pipelines
  • AI604: API key exposure in logs/config
  • AI605: Unvalidated LLM output usage
  • AI700-AI704: RAG-specific security checks
  • AI800-AI804: Vector database security
  • AI900-AI904: Output sanitization and XSS prevention

Changes

  • New rule definitions in pyspector/rules/ai_security.py
  • Test cases for each rule (positive/negative)
  • Fixed false positives from review feedback (commit 2a73c99)
  • All 68 tests pass

Review Status

Previously reviewed by @desimetallica — addressed all feedback:

  • Removed broken rules (AI601, AI603, AI604, AITS12, AISK11)
  • Narrowed scope of remaining rules
  • Added confidence = "Low" where appropriate
  • Fixed malformed path in AITS11

Fixes #92 (reopened per maintainer request — volunteers need time, thank you for patience!)

…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
- 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
Copilot AI lite review requested due to automatic review settings August 18, 2026 14:37

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

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

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants