Sub topic 7
Picking a query suite
This chapter assumes you can read a GitHub Actions workflow and have already seen the init and analyze steps of a CodeQL workflow. Here you will learn what a query suite is, how the built-in suites differ, and how to select one.
What a query suite is
CodeQL ships with hundreds of queries for each language. A query suite is a named list of those queries. The suite you choose decides which queries run against the database, so it controls how many alerts you get and how many of them are real problems.
Each query carries metadata such as @kind, @problem.severity and @precision. Suites select queries by reading that metadata. This is why a query can appear in one suite and not another.
The built-in suites
| Suite | What it adds | Typical use |
|---|---|---|
| `default` | High-precision queries for security issues and some code quality problems | The baseline. Used when you name no suite. |
| `security-extended` | Everything in `default`, plus lower-precision and lower-severity security queries | Teams that accept more false positives to find more issues. |
| `security-and-quality` | Everything in `security-extended`, plus maintainability and reliability queries | Teams that also want code quality findings. |
Each step up produces more alerts and a higher chance that an alert is not a real problem. The scan also takes somewhat longer, because more queries run.
Selecting a suite in a workflow
Use the queries input on the init step. Give the suite name, and CodeQL adds it to the default set.
- name: Initialize CodeQL
uses: github/codeql-action/init@v4
with:
languages: ${{ matrix.language }}
build-mode: ${{ matrix.build-mode }}
queries: security-extendedThe analyze step needs no change. It runs whatever queries init selected.
The queries input also accepts a comma-separated list. You can mix suites, query packs and paths to local queries. A leading + on the value, as in queries: +security-extended, tells CodeQL to add the listed queries to the default set instead of replacing it. Check the action's documentation for the exact behavior in your version, because it affects whether the default queries still run.
Selecting a suite in a configuration file
If you already use a configuration file, put the suite there. This keeps the choice in one place and lets you combine it with other settings.
name: "Custom CodeQL configuration"
queries:
- uses: security-extended
paths-ignore:
- '**/test/**'
- '**/node_modules/**'Point the init step at the file with config-file: ./.github/codeql/codeql-config.yml. If you set queries in both the workflow and the file, the workflow value is added to the file's list unless you override it. Pick one location to avoid confusion about what actually ran.
Deciding which suite to use
Start from your goal and your tolerance for noise.
- Use
defaultwhen you are new to code scanning or when alert volume would overwhelm the team. - Move to
security-extendedonce the default alerts are triaged and you want broader security coverage. - Use
security-and-qualityonly if you want maintainability findings in the same view as security alerts.
Change one step at a time. If you jump to the widest suite on a large repository, you may get hundreds of new alerts at once, and the real problems become hard to find.
Checking what ran
Do not assume your queries setting took effect. Open the workflow run and expand the Initialize CodeQL step. The log lists the suites and packs that were resolved. If your suite is missing, check the spelling and the indentation of the with block.
Common errors
- Writing
queries: security-extendedin a workflow that also uses a configuration file, then wondering which one applies. - Choosing
security-and-qualityand treating every quality alert as a security risk. - Forgetting that the
+prefix changes whether the default queries are kept. - Comparing alert counts between runs without checking that the suite was the same.
Exercise
Your team has triaged all default alerts and wants broader security coverage without maintainability findings. Which suite do you choose, and which line do you add to the init step?
Show answer
Choose security-extended. Add queries: security-extended under with: in the github/codeql-action/init step, then confirm in the Initialize CodeQL log that the suite was resolved.