Skip to content

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

Open
mmustafasenoglu wants to merge 3 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 3 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.

@desimetallica

Copy link
Copy Markdown
Collaborator

Hello mmustafasenoglu, thanks for the review of the PR and sorry for the late response.
You have improved a lot the points we have highlighted before. I've tested locally the pr but I see two test not passing properly:

  • TestAI600AgentBehavior::test_aits11_chroma_retrieval_taint_flow
  • TestAI900OutputHandling::test_ai904_sanitized_inner_html_is_safe

But maybe its my fault.
I have some points i would like to discuss with u also:

  • AITS11 now uses .similarity_search, which supports instance calls but also treats any unrelated object with that method name as a vector-store source or I'm missing something? Is that ok for us?
  • AI702 now checks score_threshold, which fixes the original k mismatch, but it flags every decimal threshold such as 0.9, is ok for us? We can treat it as a low confidence review warning like?
  • AI602 uses line-based matching and could miss implementation like multiline, is that ok for us? Anyway is marked as a low confidence.
  • AI904 use textual sanitize|bleach exclusion it that ok for us?
  • AI902/AI903 using regex could generate some noise and false positives or miss some positives cases, but the fact are marked as a low confidence could be ok for us?

What you think about it? Thanks for your helpful contribution

Tighten regex to match only thresholds 0.0-0.5 (e.g., 0.3, 0.4, 0.5, 0.50)
instead of all decimals. Thresholds >= 0.6 (0.7, 0.9) are considered
reasonable and no longer flagged.
Copilot AI review requested due to automatic review settings August 25, 2026 19:28

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