I'm a CS sophomore at George Mason. This semester I wanted to understand how tools like CodeQL actually find bugs, so I built a small version myself. It's a GitHub Action that scans Java code for SQL injection and hardcoded secrets and marks the exact line on your pull request.
Here's what I learned building it.
Why regex isn't enough
My first idea was to just search for strings like "SELECT " +. That breaks fast. The SQL might be built in a variable three lines up, or split across a StringBuilder. Regex only sees text. It doesn't know what the code means.
What an AST is
An AST (abstract syntax tree) is the code turned into a tree of what it actually does: this is a method call, this is a string, this is a variable being added to a string. I used JavaParser to turn each Java file into a tree, then wrote "visitor" rules that walk the tree.
For SQL injection, the rule looks for a database call like executeQuery(...) where the query was built by gluing user input onto a string, instead of using a PreparedStatement with ? placeholders.
The hard part: false alarms
Finding secrets sounds easy: look for things like password = "...". But real code is full of fake ones, like test values, placeholders and example configs. My first version flagged way too much.
So I ran it on 31 open source projects (27,552 files) and went through the results by hand. I added rules to skip test folders, obvious placeholders and so on. False alarms on secrets went from 156 to 27, about 83% fewer, and every real secret in that survey was still caught.
That was the most useful part of the project. Making a scanner that finds stuff is easy. Making one people won't mute is hard.
Suggesting fixes with a local LLM
There's an optional step that sends a finding to a local model through Ollama to suggest a fix. I don't trust the output blindly. The fix gets parsed again to make sure it's valid Java before it's shown. There are 57 JUnit tests covering the rules.
Try it
It takes about 2 minutes. Create .github/workflows/security-scan.yml in your repo:
name: Security scan
on: [push, pull_request]
jobs:
scan:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
- uses: noorhusaan302-png/ast-security-reviewer@v1.1.0
Then open the Actions tab. Any finding shows the file, the line and the problem.
I know CodeQL and Semgrep are way more complete. This was a learning project, but I'd love to make it useful for student and small projects. If you try it and hit a false positive, please open an issue.
Top comments (0)