Urgent.News

What's breaking now, across hundreds of outlets.

Tech

How I built a SQL injection scanner for Java using ASTs (as a sophomore)

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 " +…

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.

An 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.

One 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.

In 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.

The 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.

While 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.

Rewritten by urgent.news; may contain errors — check the original.

Source: dev.to

Read the original at dev.to →

Report a problem with this story

More in Tech

How to check an MCP server is safe before you install it

Disclosure: I run PickAPlugin , an independent catalog of ChatGPT and Codex plugins and MCP servers. This is adapted from our guide on the same topic.

  • Examine existing configuration files to see installed servers
  • Verify publisher by tracing package back to real repository
  • Pin exact package version to prevent automatic updates

Vue3 Data Grid - Free & Open source

Hey there guys. I'd like to say a few words about open source package for vue3 I've recently pushed to npm. npmjs.com deniskoronets.github.io Lightweight Vue 3 data grid (needs Vue 3.4+).

  • li-grid is new open source Vue 3 data grid package
  • Lightweight component with server-side filtering, sorting, pagination
  • npm install li-grid, works with any API via async dataLoader

Three hours, one small extension, and Firefox Add-ons

After Chrome Web Store (approved in about 5 hours) and Edge Add-ons (in review), I thought Firefox would be the easy one. Same extension, same Manifest V3, same zip. 😅 It took me three hours.

  • Firefox mandates an ID in manifest, formatted as "your-extension@yourdomain.com"
  • Avoid prematurely deleting draft add-on; ID and URL slug are permanently reserved
  • Manifest must be at root of zip file; zipping folder results in validation failure

SCKit Keeps Targeting Unpatched ScreenConnect

Huntress detected a new spike in SCKit activity on November 13, affecting 205 hosts across 41 organizations. ConnectWise says attacks against on-premises ScreenConnect environments are still being…

  • SCKit targeting unpatched ScreenConnect on 205 hosts across 41 organizations
  • Authentication vulnerability in RMM+ versions 1.0.31 and 1.0.32 enabling SCKit deployment
  • ScreenConnect CVE-2026-84869 remote code execution vulnerability addressed in version 26.6.5

More from Monday 23 November →