Inspiration

I'm a second-year student, and almost every student project I've seen, including mine, has the same bugs: SQL queries built with f-strings, os.system(f"...") on user input, API keys pasted straight into the code. Linters flag them, but they don't tell a beginner why it's dangerous or how to fix it. And when you ask an AI to "fix my code", it often returns a patch that doesn't compile or quietly breaks something else. I wanted an AI tool that doesn't just suggest a fix but checks its own work, and shows you the attack actually failing.

What it does

VulnLoop is an agent that runs a full loop on your Python code:

  1. Scan. Finds 11 classes of vulnerabilities (SQL injection, command injection, eval, unsafe pickle/YAML, hard-coded secrets, verify=False, MD5/SHA-1, debug mode, insecure temp files), each tagged with its CWE id and OWASP Top 10 category.
  2. Plan. Orders the work by severity.
  3. Patch. For each bug, an LLM writes the smallest safe fix and a concrete attacker story ("the input ' OR '1'='1 dumps every user").
  4. Verify. Every patch must pass three checks: the file still compiles, the bug is gone, and no new issue appeared. If not, it's rolled back and a deterministic built-in fix is tried. Bugs it can't fix safely (like exec() of plugin code) go to a human with guidance instead of a fake fix.
  5. Prove. Exploit replay runs the same harmless attack against the original and the patched function: SQL injection leaks 3 rows before, 0 after; ; echo PWNED runs before and is blocked after.
  6. Report. Diff, patched file download, and a Markdown security report.

On the demo app it fixes 10 of 11 issues, all verified, and raises the security score from 0 to 75/100. It's also a dev tool: python -m vulnloop . --check fails a CI build or pre-commit hook when issues exist.

How we built it

  • Python 3 with the standard-library ast module for the scanner. Rules resolve import aliases (from os import system) and track SQL strings assigned to variables before execute().
  • Patches as minimal source edits using AST node positions, so comments and formatting outside the changed expression survive. SQL fixes convert f-strings, %, + and .format() queries into parameterized queries with the right placeholder (? for sqlite3, %s otherwise).
  • Agent loop in agent.py: scan → plan → patch → verify → rollback/fallback → report, with a live trace streamed to the UI.
  • Free LLM backends only: Google Gemini (free tier), Groq (free tier, Llama 3.3 70B), or a local open-weight model through Ollama. With no key, an offline demo mode uses the built-in fixes, so anyone can try it.
  • Streamlit web UI, pytest suite (29 tests including a Streamlit AppTest that clicks through the whole demo), GitHub Actions CI, Dockerfile for free Hugging Face Spaces hosting.
  • AI coding assistants helped during development; all libraries and APIs are listed here per the rules.

Challenges we ran into

  • Trusting LLM patches. Models sometimes return code that doesn't compile or fixes one bug by adding another. The verify-then-rollback step was the answer: nothing is kept unless it passes.
  • Editing code without destroying it. Re-printing the whole file from the AST loses comments, so patches are applied as byte-accurate edits at AST node positions (UTF-8 columns included).
  • SQL injection has many shapes: f-strings, %, concatenation, .format(), and queries built on one line and executed on another. Each needed its own rewrite into a parameterized query, with quote stripping around the placeholders.
  • Proving fixes safely. Exploit replay runs only on the bundled sample, with fixed harmless payloads, in a separate process inside a temp folder, never on uploaded code.

Accomplishments that we're proud of

  • Every fix shown to the user is verified, and the demo shows the actual attack failing after the patch.
  • It runs completely free, even with no internet and no API key.
  • Honest about limits: it hands exec() to a human instead of pretending.

What we learned

How real injection attacks work end to end, how to map bugs to CWE/OWASP, how much an agent improves when it can check its own output, and how to make Python's ast do precise source edits.

What's next for VulnLoop

  • A GitHub App that comments verified fix suggestions on pull requests.
  • Cross-file taint tracking (user input from a Flask route reaching execute() in another module).
  • More languages (JavaScript first) and auto-generated exploit tests for any function, not just the demo.

Built With

Share this project:

Updates

Submission history