Static Application Security Testing (SAST)

The Hard-Coded API Key That Cost Us 6 Figures

"We've been breached. Someone's been using our AWS account for cryptocurrency mining."

The date: June 3, 2019. The bill: $47,000 for a single weekend. The cause: a hard-coded AWS access key checked into Git... 8 months earlier.

The attacker found it using a simple GitHub search: "aws_access_key_id" filename:config.js. Within minutes, they had launched 200 EC2 GPU instances for crypto mining. Our alerting? Failed to catch it because it happened over a weekend.

The worst part? We had SonarQube running. It had flagged the hard-coded secret. The developer had marked it as "Won't Fix" because "it's just for testing."

That "testing" key had full production access.

This incident taught me three painful lessons:

  1. SAST tools are only effective if teams act on findings

  2. Security findings need to be unmissable, not buried in dashboards

  3. "Won't Fix" should require security team approval

This article documents how we transformed SAST from a checkbox tool that generated noise into a critical security gate that developers actually trust and use.

What You'll Learn

  • Setting up effective SAST scanning

  • Integrating SAST into CI/CD pipelines

  • Tuning rules to reduce false positives

  • Managing and prioritizing findings

  • GitLab + SonarQube integration

  • Making SAST findings actionable

What is SAST?

Static Application Security Testing analyzes source code for security vulnerabilities without executing it.

SAST vs Other Security Testing

spinner

Key Difference: SAST finds potential vulnerabilities in code structure; DAST finds actual vulnerabilities in running applications.

Setting Up SAST: GitLab + SonarQube

We use two layers of SAST:

  1. GitLab SAST - Fast, integrated, baseline scanning

  2. SonarQube - Deep analysis, quality gates, historical tracking

GitLab SAST Setup

GitLab provides built-in SAST scanning using industry-standard analyzers.

1. Enable GitLab SAST

GitLab automatically selects analyzers based on languages detected:

Language
Analyzer
What It Finds

JavaScript/TypeScript

Semgrep, ESLint

XSS, prototype pollution, insecure crypto

Python

Bandit, Semgrep

SQL injection, command injection, hardcoded secrets

Java

SpotBugs, Semgrep

OWASP Top 10, insecure deserialization

Go

Gosec, Semgrep

SQL injection, hardcoded credentials

C#

Security Code Scan

OWASP Top 10, .NET specific vulns

2. View Results in Merge Requests

Findings appear automatically in MR security widget:

Developers see security findings where they review code, not in separate dashboards.

SonarQube Setup

SonarQube provides deeper analysis with quality gates and historical tracking.

1. Deploy SonarQube

Start SonarQube:

2. Configure Quality Gate

Quality gates define pass/fail criteria for your code:

3. GitLab Integration

Add SonarQube token to GitLab CI/CD variables:

Real Vulnerability Examples

Example 1: Hard-Coded Secrets (The $47K Lesson)

Vulnerable Code:

SonarQube Finding:

Fixed Code:

Example 2: SQL Injection

Vulnerable Code:

Attack Vector:

SonarQube Finding:

Fixed Code:

Example 3: Path Traversal

Vulnerable Code:

Attack Vector:

SonarQube Finding:

Fixed Code:

Example 4: Insecure Cryptography

Vulnerable Code:

SonarQube Findings:

Fixed Code:

Managing SAST Findings

Prioritization Strategy

Not all findings are equally important. Our priority matrix:

False Positive Management

Process for marking false positives:

SonarQube Suppression Example:

Baseline and Track Progress

Establish a baseline and track improvements:

IDE Integration: Shift Further Left

Catch issues before committing:

SonarLint for VS Code

Configure connected mode to sync with SonarQube:

Developers see security issues as they type, not in CI/CD.

Performance Optimization

SAST scans can be slow. Our optimizations:

1. Incremental Scanning

Scan only changed files in MRs:

Result:

  • Full scan: 8 minutes

  • Incremental scan: 2 minutes (only changed files)

2. Parallel Analysis

Run multiple analyzers in parallel:

3. Caching

Cache SonarQube analysis cache:

Real Results

Metrics (2019 β†’ 2023)

Developer Feedback

Before SAST:

"Security team tells us about vulnerabilities 3 months after deployment. By then the code is in 20 microservices."

After SAST:

"I see security issues in my IDE as I code. Fixing them immediately is easy. I've become a better developer."

Key Takeaways

βœ… SAST finds vulnerabilities in code before they reach production βœ… GitLab + SonarQube provides comprehensive SAST coverage βœ… Block on critical findings - don't allow security debt βœ… IDE integration (SonarLint) catches issues before commit βœ… Prioritize findings - not all issues are equally urgent βœ… False positive process essential for developer trust βœ… Hard-coded secrets are the easiest and costliest to exploit

What's Next

SAST finds vulnerabilities in source code. But what about vulnerabilities that only appear when code is running? The next article covers DAST (Dynamic Application Security Testing)β€”testing running applications for security issues.


Next Article: Dynamic Application Security Testing (DAST) β†’


Part of the DevSecOps 101 Series

Last updated