<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Hassan</title>
    <description>The latest articles on DEV Community by Hassan (@hassan_59466a07a822f7d840).</description>
    <link>https://dev.to/hassan_59466a07a822f7d840</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4261458%2F575bb38f-4dac-46b1-b434-66bd9491edc6.png</url>
      <title>DEV Community: Hassan</title>
      <link>https://dev.to/hassan_59466a07a822f7d840</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/hassan_59466a07a822f7d840"/>
    <language>en</language>
    <item>
      <title>How I built a SQL injection scanner for Java using ASTs (as a sophomore)</title>
      <dc:creator>Hassan</dc:creator>
      <pubDate>Mon, 23 Nov 2026 22:25:07 +0000</pubDate>
      <link>https://dev.to/hassan_59466a07a822f7d840/how-i-built-a-sql-injection-scanner-for-java-using-asts-as-a-sophomore-511c</link>
      <guid>https://dev.to/hassan_59466a07a822f7d840/how-i-built-a-sql-injection-scanner-for-java-using-asts-as-a-sophomore-511c</guid>
      <description>&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;Here's what I learned building it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why regex isn't enough
&lt;/h2&gt;

&lt;p&gt;My first idea was to just search for strings like &lt;code&gt;"SELECT " +&lt;/code&gt;. That breaks fast. The SQL might be built in a variable three lines up, or split across a &lt;code&gt;StringBuilder&lt;/code&gt;. Regex only sees text. It doesn't know what the code means.&lt;/p&gt;

&lt;h2&gt;
  
  
  What an AST is
&lt;/h2&gt;

&lt;p&gt;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 &lt;strong&gt;JavaParser&lt;/strong&gt; to turn each Java file into a tree, then wrote "visitor" rules that walk the tree.&lt;/p&gt;

&lt;p&gt;For SQL injection, the rule looks for a database call like &lt;code&gt;executeQuery(...)&lt;/code&gt; where the query was built by gluing user input onto a string, instead of using a &lt;code&gt;PreparedStatement&lt;/code&gt; with &lt;code&gt;?&lt;/code&gt; placeholders.&lt;/p&gt;

&lt;h2&gt;
  
  
  The hard part: false alarms
&lt;/h2&gt;

&lt;p&gt;Finding secrets sounds easy: look for things like &lt;code&gt;password = "..."&lt;/code&gt;. But real code is full of fake ones, like test values, placeholders and example configs. My first version flagged way too much.&lt;/p&gt;

&lt;p&gt;So I ran it on &lt;strong&gt;31 open source projects (27,552 files)&lt;/strong&gt; 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 &lt;strong&gt;156 to 27, about 83% fewer&lt;/strong&gt;, and every real secret in that survey was still caught.&lt;/p&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;h2&gt;
  
  
  Suggesting fixes with a local LLM
&lt;/h2&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;h2&gt;
  
  
  Try it
&lt;/h2&gt;

&lt;p&gt;It takes about 2 minutes. Create &lt;code&gt;.github/workflows/security-scan.yml&lt;/code&gt; in your repo:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Security scan&lt;/span&gt;
&lt;span class="na"&gt;on&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;push&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;pull_request&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="na"&gt;jobs&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;scan&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;runs-on&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;ubuntu-latest&lt;/span&gt;
    &lt;span class="na"&gt;steps&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
      &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="na"&gt;uses&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;actions/checkout@v5&lt;/span&gt;
      &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="na"&gt;uses&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;noorhusaan302-png/ast-security-reviewer@v1.1.0&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then open the Actions tab. Any finding shows the file, the line and the problem.&lt;/p&gt;

&lt;p&gt;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 &lt;a href="https://github.com/noorhusaan302-png/ast-security-reviewer/issues" rel="noopener noreferrer"&gt;open an issue&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>java</category>
      <category>security</category>
      <category>beginners</category>
      <category>github</category>
    </item>
  </channel>
</rss>
