Explore our new Cybersecurity Terms Glossary, explained by our experts.
Cybersecurity Terms Glossary
CodeQL is GitHub’s semantic code analysis engine. It compiles a codebase into a relational database and lets you query it for vulnerable patterns with a declarative language called QL.

What Is CodeQL?
CodeQL treats source code as data. Instead of matching text patterns, it compiles a codebase into a relational database that captures the syntax tree, the type information, and the control and data flow, then lets you ask questions of that database in QL, a declarative language in the Datalog family. A query that finds SQL injection is, quite literally, a query: find every path from a value controlled by a request to a method that executes a statement, where nothing on the path neutralises it.
The engine came from Semmle, a spin-out from the University of Oxford, which GitHub acquired in September 2019. It now powers GitHub code scanning.
Analysis happens in two stages. First you build a database, which for compiled languages means observing a real build so that the extractor sees exactly what the compiler sees:
codeql database create db --language=java --command="mvn -B clean package -DskipTests"
codeql database analyze db codeql/java-queries --format=sarif-latest --output=results.sarif
Then you run queries against it. The queries that matter for security are mostly taint-tracking queries, built from three sets: sources (where untrusted data enters), sinks (where it becomes dangerous), and sanitisers (what makes it safe again). Because the model is explicit, results come with a full path from entry point to sink, which is the single biggest difference when triaging findings. A reviewer can see the seven frames between the HTTP parameter and the command execution rather than guessing whether a flagged line is reachable at all.
Supported languages include C and C++, C#, Go, Java and Kotlin, JavaScript and TypeScript, Python, Ruby, Rust, Swift, and GitHub Actions workflows.
Consider a value read from a request header, stored in a map, passed through two helper methods in different files, and finally concatenated into a shell command. A regular-expression scanner sees nothing suspicious at any single line. CodeQL follows the value across files and reports the path. The same mechanism finds insecure direct object references where an identifier reaches a data access layer without an ownership check, unsafe deserialisation, path traversal, and the kinds of command injection that hide behind a wrapper function.
GitHub Security Lab publishes the queries it uses to find real vulnerabilities in open-source projects, and reading those queries is the fastest way to understand what the language can express. Variant analysis is the other distinctive use: after a vulnerability is fixed, write a query describing the mistake and run it across every repository you own to find the other eleven places someone made it.
Precision is expensive. A CodeQL database for a large C++ project can take an hour to build and several gigabytes to store, and the analysis adds more. That is acceptable on a nightly schedule or on the default branch, and painful on every pull request, which is why most teams run the full query suite on a schedule and a reduced suite on pull requests. Build observation is also a genuine operational constraint — if the continuous integration job cannot reproduce a working build, there is no database to analyse.
Licensing deserves attention. The CodeQL CLI and the standard query packs are free for analysis of open-source code, but use against private or commercial codebases requires GitHub Advanced Security. Unlike Semgrep, which pairs an open-source engine with a quick rule-writing syntax, CodeQL is deep but commercially gated and has a steeper learning curve for custom rules.
security-extended or security-and-quality suites deliberately rather than by default; they raise recall and the false positive rate together.Static analysis of this kind pairs with dynamic testing rather than replacing it; the two find different classes of defect. At Privia Security, we combine automated analysis with manual review in our web application security services.
It is free to analyse public repositories and open-source projects, both through GitHub code scanning and with the standalone CLI. Running it against private or commercial code requires a GitHub Advanced Security licence. That distinction catches teams out when they prototype on an open-source repository and then discover the production codebase needs a paid plan.
Semgrep matches patterns that look like the code you want to find and runs in seconds, which makes it excellent for custom organisational rules and fast pull request feedback. CodeQL builds a full semantic database and performs cross-file data flow analysis, which finds deeper issues and produces traceable paths, at the cost of longer build times and a harder query language. Many teams run both.
Yes, and for internal frameworks it is the main reason to use the tool. Queries are written in QL, imported into a query pack, and run with the CLI or added to a code scanning configuration. Expect a real learning curve: the language is declarative and unlike anything most developers have written. Start by modifying an existing query from the standard library rather than writing one from scratch.
For compiled languages the extractor runs alongside the compiler so it can see exactly which files were compiled, with which flags, and against which dependencies. Without that, generated code, conditional compilation, and dependency resolution would be guesswork. Interpreted languages such as Python, Ruby, and JavaScript do not need a build command, so their databases are much quicker to create.
You May Be Interested In These
We use a few cookies that are needed to make this website work, and they are always on. We would also like to set analytics cookies, to see which pages are useful; functional cookies, so that our live chat works; and advertising cookies, to measure our campaigns. We will not set any of those until you say yes, and you can change your mind at any time from the Cookie Settings link in the footer.
Choose the cookies you are happy for us to use. Strictly necessary cookies are always on; everything else is off until you turn it on.
These cookies keep the website working: they hold your security checks, your form submissions and the choice you make here. The site cannot run without them, so they are always on.
These let our live chat open and remember your conversation, and let the newsletter sign-up work. Switch them off and the chat window will not appear.
These tell us which pages are read and how people find us, so that we can improve the site. The reports are about groups of visitors, never about you personally.
These let us measure our advertising and show you our adverts on other websites, such as LinkedIn, Google and Meta. Switch them off and you will still see adverts, but they will be less relevant.