top of page

AI Can Generate Code Faster Than Humans Can Review It: A Practical Guide to Free Static Security Analysis (SAST) with SonarQube

  • techsandpartnershi
  • 2 days ago
  • 5 min read

AI doesn't remove the need for code review, it increases it. Since human review capacity doesn't scale at the same rate as AI-generated code, automated analysis becomes essential for maintaining software quality and security.


A human eye

What Is Static Application Security Testing (SAST)?


The rise of AI coding assistants has fundamentally changed how software is built. Developers can now generate features, APIs, and even entire applications in a fraction of the time it once took. While this has dramatically increased development velocity, it has also created a new challenge: the amount of code being produced is growing faster than humans can thoroughly review it.


This is where Static Application Security Testing (SAST) becomes an essential part of the modern development workflow.


SAST is an automated method of analyzing an application's source code without executing the application. It identifies security vulnerabilities, insecure coding patterns, and quality issues early in the Software Development Life Cycle (SDLC), often before the code is merged or deployed.


Unlike manual code reviews, which depend on the reviewer's time and expertise, SAST can consistently inspect every commit, every pull request, and every release. It helps development teams detect issues such as injection vulnerabilities, insecure cryptographic usage, hardcoded secrets, unsafe API usage, and other security weaknesses before they become production incidents.


However, SAST is not a replacement for human expertise. It cannot fully understand business logic, architecture, or how an application behaves at runtime. Instead, it complements manual security reviews, dynamic application security testing (DAST), dependency scanning, and penetration testing by providing an automated first line of defense.


In this guide, we'll explore how you can use the free SonarQube Community Build to introduce SAST into your development workflow, continuously review AI-generated and human-written code, and establish a strong security baseline without additional licensing costs.



Running SonarQube Locally with Docker


One of the biggest advantages of SonarQube Community Build is that you can get started in just a few minutes without installing Java or configuring a local environment. Using Docker, you can run both the SonarQube server and the SonarScanner in isolated containers.


1. Create a Docker Network

We'll use a dedicated Docker network so the scanner container can communicate with the SonarQube server by its container name.

$ docker network create sonarnet

2. Start the SonarQube Server

For local development and evaluation, you can start SonarQube with a single command:

$ docker run \
  --name sonarqube \
  --network sonarnet \
  -e SONAR_ES_BOOTSTRAP_CHECKS_DISABLE=true \
  -p 9000:9000 \
  sonarqube:latest

Wait until the server finishes starting, then open: http://localhost:9000


Log in using the default credentials:

  • Username: admin

  • Password: admin


You'll be prompted to change the password on first login. Next, navigate to My Account → Security and generate a user token. This token will be used by the scanner to authenticate with the server.


Note: The embedded H2 database is intended for local development and evaluation. For production deployments, SonarSource recommends using PostgreSQL.


3. Run Your First Scan

Once you have a token, you can analyze any project by mounting its source code into the SonarScanner Docker container.

$ docker run --rm \
  --network sonarnet \
  -e SONAR_HOST_URL=http://sonarqube:9000 \
  -e SONAR_TOKEN=<YOUR_TOKEN> \
  -v "/path/to/your/project:/usr/src" \
  sonarsource/sonar-scanner-cli \
    -Dsonar.projectKey=my-project \
    -Dsonar.exclusions=node_modules/**,.next/**,public/**
SonarQube dashboard

The scanner will:

  • Connect to your SonarQube server.

  • Download the required language analyzers (only the first time).

  • Analyze the project's source code.

  • Upload the results back to SonarQube.

After the scan completes, refresh the SonarQube dashboard and you'll see a new project containing security findings, code quality issues, metrics, and the Quality Gate status.


SonarQube report with issues


Learn More

The official SonarSource documentation provides more details on installation and scanner configuration:



Understanding Your SonarQube Security Results


Once the analysis is complete, SonarQube presents a dashboard summarizing the security and quality of your project. Rather than simply listing problems, it categorizes findings to help you prioritize remediation efforts.


SonarQube reports

Security Vulnerabilities

SonarQube Community Build identifies security issues based on language-specific security rules and secure coding best practices. Rather than performing advanced data-flow (taint) analysis, it focuses on detecting insecure coding patterns and security-sensitive implementations.


Examples of findings include:

  • Hardcoded credentials or secrets

  • Weak or insecure cryptographic algorithms

  • Insecure random number generation

  • Unsafe use of security-related APIs

  • Security misconfigurations

  • Other language-specific secure coding rule violations


Each finding includes:

  • Severity

  • The affected file and line number

  • A description of the issue and why it matters

  • Recommended remediation guidance

  • References to secure coding practices and, where applicable, Common Weakness Enumeration (CWE)


While Community Build provides valuable static security analysis, advanced detection of injection vulnerabilities such as SQL Injection, Cross-Site Scripting (XSS), and Command Injection through data-flow (taint) analysis is available in the commercial editions of SonarQube.


Security Hotspots

One of SonarQube's most valuable features is Security Hotspots.

A Security Hotspot is not necessarily a vulnerability. Instead, it identifies code that is security-sensitive and should be reviewed by a developer or security engineer.


Typical examples include:

  • Authentication and authorization logic

  • Cookie configuration

  • JWT handling

  • CORS configuration

  • Cryptographic operations

  • File upload functionality

  • XML processing

  • Regular expressions that could lead to denial-of-service attacks


Hotspots encourage teams to review code that automated analysis cannot confidently classify as secure or insecure. This is where human expertise remains essential.


Bugs

Although this guide focuses on security, SonarQube also detects reliability issues that may lead to application failures, such as null reference errors, resource leaks, incorrect comparisons, and unreachable code.


Fixing reliability issues improves both software stability and, in many cases, overall security.


Code Smells

Code Smells are maintainability issues rather than security defects.


Examples include:

  • Duplicate code

  • Excessively complex methods

  • Dead code

  • Large classes

  • Unused variables

  • Poor naming or structure


While Code Smells are not vulnerabilities, reducing technical debt makes applications easier to maintain, review, and secure over time.


Security Rating

SonarQube assigns a Security Rating ranging from A to E.


This rating provides a high-level indication of your project's security posture based on detected vulnerabilities.


While it should not be treated as a compliance certification, it offers a useful way to track security improvements across releases.


Quality Gate

The Quality Gate is an automated pass/fail check that evaluates your project against predefined quality conditions.


A common security-focused Quality Gate might require:

  • No Critical vulnerabilities

  • No Blocker vulnerabilities

  • Security Rating of A

  • No new security issues introduced in recently changed code


Integrating the Quality Gate into your CI/CD pipeline helps prevent new security issues from reaching production.


What SonarQube Community Build Doesn't Detect

It's important to understand the scope of static analysis.


SonarQube Community Build analyzes your source code without executing the application.


As a result, it does not replace:

  • Dynamic Application Security Testing (DAST)

  • Penetration testing

  • Business logic testing

  • Authentication and authorization reviews

  • Multi-tenant isolation verification

  • Runtime configuration reviews

  • Infrastructure security assessments

  • Software Composition Analysis (dependency vulnerability scanning)


These activities remain essential for a comprehensive security assessment.


Building a Layered Security Process

Static analysis is most effective when combined with other security practices.


A practical workflow for modern web applications might include:

  1. SonarQube (SAST) to continuously review source code for security and quality issues.

  2. Dependency scanning (SCA - available in paid versions) to identify vulnerable third-party libraries.

  3. Dynamic testing (DAST) to evaluate the running application. I recommend ZAP https://www.zaproxy.org/  which is free and open source. 

  4. Manual security review for authentication, authorization, business logic, and architecture.

  5. Performance and scalability testing before production deployment.


As AI-assisted development continues to increase code generation speed, this layered approach helps engineering teams maintain confidence that code is not only delivered quickly, but also meets a consistent security baseline.


 
 
 

Comments


bottom of page