{
  "id": 21485203,
  "title": "How I built a SQL injection scanner for Java using ASTs (as a sophomore)",
  "url": "https://urgent.news/2026/11/23/how-i-built-a-sql-injection-scanner-for-java-using-asts-as-a-sophomore",
  "topic": "tech",
  "section": "Tech",
  "published": "2026-11-23T22:25:07.000Z",
  "source": {
    "name": "Dev.to",
    "slug": "dev-to",
    "url": "https://dev.to/hassan_59466a07a822f7d840/how-i-built-a-sql-injection-scanner-for-java-using-asts-as-a-sophomore-511c"
  },
  "original_language": "en",
  "account": "As a sophomore studying Computer Science at George Mason, I aimed to gain insight into how tools like CodeQL detect vulnerabilities. To achieve this, I created a Java SQL injection scanner using abstract syntax trees (ASTs). The initial approach involved searching for specific strings, but this proved inadequate as the SQL commands could be constructed using variables or StringBuilder objects. Regex proved insufficient for understanding the code's intent.\n\nAn abstract syntax tree (AST) represents the structure of the code, breaking it down into its fundamental components such as method calls, strings, and variables. By converting Java files into ASTs using JavaParser, I could develop \"visitor\" rules to navigate the tree and identify potential SQL injection vulnerabilities. Specifically, I aimed to detect cases where user input was directly concatenated into a database query string rather than utilizing prepared statements with placeholder arguments.\n\nOne of the major challenges I faced was minimizing false positives. Detecting hardcoded secrets seemed straightforward - simply scanning for patterns like 'password = \"...\"'. However, real-world code often contains example values, test data, and placeholders that could be mistakenly flagged as secrets. To address this issue, I ran my scanner across 31 open-source projects containing 27,552 files. I then manually reviewed the results and refined the rules to filter out common false alarms. This process reduced false alarms from 156 to just 27, achieving an 83% reduction and ensuring that all actual secrets within the surveyed codebase were still detected. This aspect proved to be the most valuable outcome of the project.\n\nIn addition to flagging vulnerabilities, I incorporated an optional feature that leverages a local language model, specifically through the Ollama framework, to suggest potential fixes for identified issues. Before presenting any suggestions, the proposed changes are parsed again to ensure they are syntactically valid Java code. This added layer of validation helps maintain the reliability of the scanner's recommendations.\n\nThe entire scanning process takes approximately 2 minutes to complete. To integrate the scanner into your Java project, you need to create a GitHub Actions workflow file named `.github/workflows/security-scan.yml`. Within this file, specify the necessary configuration for triggering the scan on push events or pull requests, and utilize the provided scanner repository URL. Once set up, open your repository's Actions tab to view the scan results. Any detected vulnerabilities will display the file path, line number, and the specific issue encountered.\n\nWhile CodeQL and Semgrep offer more comprehensive vulnerability detection capabilities, this learning project served as an excellent opportunity for me to delve deeper into the fundamentals of AST-based analysis and its application in detecting SQL injection risks and hardcoded secrets. If you decide to give it a try and encounter any false positives, please don't hesitate to open an issue to help improve the scanner's accuracy.",
  "summary": "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 \" +…",
  "key_points": [
    "Sophomore CS student built Java SQL injection scanner using ASTs",
    "Converted Java files to ASTs with JavaParser for vulnerability detection",
    "Reduced false positives by 83% through manual review and refinement"
  ],
  "editors_take": null,
  "illustration": null,
  "coverage": {
    "outlets": 1,
    "also_reported_by": []
  },
  "ai_generated": true,
  "disclaimer": "Summaries, key points and the editor’s take are written by software from other outlets’ reporting and may contain errors — always check the linked original."
}