promptsnake
Static analyzer that traces untrusted text in AI chatbot and agent code into code execution, shell, and database sinks
Role
Solo Developer & Researcher
Tech Stack
6 technologies
About This Project
Once an attacker can influence a prompt, through a chat box, a web page an agent reads, a poisoned document in a vector store, or a tool result, the model's output is attacker controlled. Code that hands that output to exec, subprocess, or cursor.execute has the same bug as code that hands it request.args. This is OWASP LLM05 (Improper Output Handling), and it sits behind published CVEs in LangChain's LLMMathChain and PALChain, Vanna.AI, and GraphCypherQAChain.
General Python linters treat the return value of a chat-completion call as an ordinary value, so they either miss the flow or flag every exec regardless of input. promptsnake is a static taint checker built for this case. It labels where text comes from (model output, retrieved documents, tool and MCP inputs, web requests, the environment) and follows it across functions and across modules into dangerous sinks. Every finding comes with the path the text took, line by line. It parses code with Python's own ast module, never imports or runs what it scans, and has no runtime dependencies.
The headline benchmark is a 100-case held-out split, written separately from the implementation and run once after all engine changes. promptsnake scores 0.94 F1 there, against 0.77 for Semgrep's LLM taint rules and 0.46 for Bandit. Ablations on the 164-case dev split show where the accuracy comes from: without function summaries recall falls from 0.98 to 0.81, and without sanitizer modeling false positives more than quadruple.
The benchmark isn't the whole story, and the README says so. Scans of 50 real open-source LLM applications found far lower precision. That finding reshaped the tool: cross-module analysis, so wrapped model calls can be followed to their sinks, and a default profile that reports only AI-specific flows. promptsnake is presented as a research prototype, precise on the benchmark and still noisy on real code. It is meant to be run with a baseline and reviewed by hand.
Key Features
- ◆Labels every source (LLM, RAG, TOOL, USER, WEB, ENV, CLI) and follows it into ten rule classes, from exec and shell injection to SQL, pickle, SSRF, path writes, and template injection
- ◆Interprocedural and cross-module: function summaries follow a model call wrapped in one module to a sink in another, with each step of the trace naming its file and line
- ◆An llm profile, the default, reports only flows that involve model output, retrieved documents, or tool input, so findings are about AI-specific risk rather than ordinary web taint
- ◆Understands common guards: allowlists, containment checks on normalized paths, anchored regular expressions, and sanitizer functions
- ◆Fails closed: a file it could not parse or fully analyze is always reported, so a CI gate cannot pass on code it skipped
- ◆Text, JSON, SARIF, and GitHub Actions output, plus baselines, suppressions, and staged-file scans for pre-commit
- ◆Parses code with the standard library ast module, never imports or runs it, and installs nothing else
- ◆595 tests with branch coverage enforced in CI
Challenges
Following taint through helper functions like ask_llm() and run_generated(), exactly where general linters lose the trail
Treating config files inside a scanned repo as untrusted, so a pull request cannot add its own sources or sinks and switch findings off
Learning that benchmark precision does not carry over to real code: two in-the-wild studies on 50 open-source LLM apps turned up mostly false positives, and that result drove the cross-module analysis and the llm default profile
Outcomes
- ✓0.94 F1 (0.95 precision, 0.94 recall) on a 100-case held-out split, written separately from the implementation and run once
- ✓Beats Semgrep's LLM taint rules (0.77 F1), Bandit (0.46), Agent Audit (0.40), and Semgrep registry rules (0.31) on the same cases
- ✓Ablations on the 164-case dev split show function summaries add 17 true positives and sanitizer modeling removes 7 false positives
- ✓Published in-the-wild precision numbers alongside the benchmark, including the unflattering ones
Tech Stack
Want to talk about this project?
Questions, collaboration, or overlapping research: send a raven.
Get in Touch