Skip to main content
Finding vulnerabilities in your own source code requires more than pattern matching; it needs semantic, data-flow analysis. Simple text searches (for example, a naive grep) can find suspicious tokens but cannot determine whether user-controlled data actually reaches a dangerous sink.
This article walks through how CodeQL turns your code into a queryable database and uses taint/data-flow analysis to trace dangerous paths from sources to sinks. We’ll compare CodeQL to simple text matching, show a few practical examples, and explain important differences between interpreted and compiled languages when running CodeQL in CI. What CodeQL does differently
  • Treats code as a queryable database rather than a set of files.
  • Performs semantic and cross-file analysis to follow actual data flow.
  • Uses language libraries (including taint-tracking predicates) to model sources, sanitizers, and sinks.
Example: grep vs semantic analysis A naive grep can find literal appearances of risky functions like eval:
But this only shows the presence of the token, not whether an attacker can control the evaluated input. CodeQL can express and find flows where user-controlled input reaches eval. src/render.js
A concise CodeQL query that aims to detect eval calls receiving user-controlled input might look like: eval-taint.ql
In the example above, isUserControlled(...) is a conceptual placeholder. In real CodeQL queries you should use CodeQL’s taint-tracking predicates (from the official libraries) or define precise source predicates to model user-controlled input. See CodeQL taint-tracking for implementation patterns.
Tracing the same value across layers CodeQL can trace a value from an HTTP request, through API logic, into a database call. Example: src/api/search.js
CodeQL connects the data source (req.query.q) to the sink (db.query(...)) and can flag this as an SQL injection if the value is tainted and not sanitized. Interpreted vs compiled languages To analyze code, CodeQL needs a representation of the program. How it obtains that differs by language:
  • For interpreted languages (JavaScript, Python, Ruby), CodeQL can read and analyze source files directly.
A slide titled "Interpreted – Read Directly" with two labeled language icons. The icons show Python and JavaScript.
  • For compiled languages (Java, C/C++, Go, etc.), CodeQL must observe the build because compiled artifacts and generated files affect the final program structure. CodeQL hooks into your compiler and build system to capture the build artifacts. If the build fails, CodeQL cannot complete its analysis.
When a build fails, CodeQL aborts the analysis. Example Maven failure:
If the CodeQL workflow cannot reproduce your project’s build (missing code generation, different build flags, or absent dependencies), analysis will fail. Ensure your CI build mirrors the local build steps exactly for compiled languages.
Integrating CodeQL into CI (recommended) A common pattern is to run CodeQL as part of GitHub Actions and make the CodeQL job (and the build job it depends on) a required status check on protected branches. This prevents merging code that either fails the build required by CodeQL or introduces new findings.
A screenshot of a "Required Status Check" panel showing two checks: "build (ubuntu-latest)" marked successful with a green check, and "CodeQL / Analyze (java)" marked required and failing after 2 minutes with a red X.
Best practices for reliable CodeQL analysis
  • Reproduce your CI build locally and include all build steps: compilation, code generation, dependency fetching.
  • For compiled languages, include the same build commands in the CodeQL workflow so it can analyze the produced artifacts.
  • Make CodeQL (and its underlying build) a required status check for protected branches to block merges when analysis cannot complete or reports new issues.
  • Use CodeQL’s standard libraries for taint-tracking and model specific sources/sinks for your application framework.
Quick-reference table Summary (what to remember)
  • CodeQL provides semantic, cross-file, data-flow analysis — not simple token matching.
  • It excels at finding vulnerability patterns that depend on program logic (e.g., unsanitized input reaching eval, SQL builders, or command execution).
  • For interpreted languages, analysis can run on source files. For compiled languages, ensure builds succeed and are reproduced in the workflow.
  • Failures in the build step will prevent CodeQL from analyzing your project; make your CI build reliable and consistent.
Links and references

Watch Video