Chapter 23Lesson 03~160 minutes

CodeQL, Code Scanning, SARIF, Custom Queries, Autofix, and Security Gates: Configuration, Design Choices, and Tradeoffs

A scanner configuration is an operating decision, not a one-time checkbox. This lesson chooses between default and advanced setup, standard and custom queries, informational alerts and merge blocking, and machine-proposed autofixes versus reviewed engineering changes.

Advanced setupQuery suitesCustom queriesAutofixPolicy

Learning objectives

  • Choose default versus advanced CodeQL setup from concrete requirements and maintenance cost.
  • Choose default/security-extended suites versus custom queries without confusing coverage with certainty.
  • Separate alert generation from merge-blocking policy and design a baseline strategy for existing findings.
  • Review Copilot Autofix as a code-change proposal and identify when manual security design review remains necessary.
  • Compare repository-local scanning, centralized governance, external scanners, and their compatibility/cost boundaries.
No-paid path: all required reasoning and public-repository features in this lesson are available without purchasing Code Security. Private/internal organization repositories and centralized organization controls remain plan/product dependent and are labeled as optional production extensions.

1. Default setup or advanced setup?

Start with the problem, not the workflow file. Default setup minimizes maintenance and automatically follows supported-language changes. Advanced setup is justified when the repository has an analysis requirement that GitHub-managed defaults cannot satisfy. Creating an advanced workflow “because CI should be YAML” adds an owner, action-version update burden, trigger logic, permissions, and build failure modes without automatically increasing coverage.

Requirement Default setup Advanced setup
Ordinary supported language, standard build Preferred starting point Possible but usually unnecessary
Choose Default or Extended built-in suite Supported Supported
Manual build commands / generated code workflow Limited; may require switching Strong fit
Custom query suite / local query pack Not the normal path Required for custom suite control
Custom event scheduling / runner orchestration Managed constraints Strong fit
Maintenance burden Low Higher: workflow, pins, permissions, build, queries

For compiled languages, validate the database itself. Current CodeQL may use none for C/C++, C#, Java, and Rust when appropriate, while Kotlin needs a build. If production correctness depends on generated source or unusual build flags, a manual advanced setup can be more representative even though it costs more to operate.

2. Built-in suites versus custom queries

The built-in default suite prioritizes high precision. security-extended adds more security queries with somewhat lower precision, so it can find additional issues at the cost of more triage. Changing suites changes the question you ask of the same code; it does not make the database more complete by itself.

Use a custom query when the organization has a recurring security invariant that standard queries do not encode—for example, a proprietary authorization API that must dominate a sensitive operation. Custom queries belong in a CodeQL pack, need metadata/tests/versioning, and should be reviewed like production code. A query that blocks merges organization-wide is internal platform code with a wide blast radius.

# Conceptual advanced-setup configuration fragment.
# Pin query packs to reviewed versions in production.
queries:
  - uses: security-extended
  - uses: your-org/security-queries@1.4.2
Supply-chain boundary: a downloaded CodeQL query pack is executable analysis logic. Review its publisher, version, dependency chain, and update process instead of treating “security tooling” as inherently trusted.

3. Alert-as-information versus merge-blocking policy

Scanning and gating answer different questions. Scanning says “this analysis produced these findings.” A gate says “given this tool, severity, branch, and policy, this change may or may not enter the target ref.” Keeping them separate lets teams collect evidence before they enforce it.

A sensible rollout is often observe → establish baseline/ownership → measure precision and coverage → gate only new/relevant high-confidence findings → tighten policy over time. A rule that fails every PR because of unrelated legacy backlog teaches developers to seek bypasses, not to fix risk.

Policy mode Benefit Risk Good use
Informational Low disruption, good for baselining Findings can be ignored indefinitely New tool/query onboarding
Block Critical/High security findings Strong control on severe new findings Incorrect classification can block urgent work Mature scanner + ownership
Block all alerts Maximum strictness Noise and legacy debt can dominate delivery Small high-assurance codebase with proven precision
Custom “new findings only” admission check Avoids inherited backlog deadlock Requires careful diff/ref/analysis identity logic Large legacy estate during migration

4. Copilot Autofix versus manual remediation

Copilot Autofix is a proposal generator. Its strongest fit is a localized alert with a well-understood fix pattern and tests that exercise the behavior. Manual design review is still required when remediation changes trust boundaries, authorization, parsing semantics, cryptography, data lifetime, or cross-service behavior.

Agentic autofix is currently public preview and can involve a Copilot cloud agent session and AI-credit billing. It is not required for this course. Even when agentic validation reruns CodeQL, GitHub notes that it cannot guarantee fixes for custom-query or security-extended findings. Production policy should therefore record which analysis was rerun and what independent tests/review were completed.

5. Repository-local versus centralized security platform code

Repository-local configuration keeps ownership near the application, which helps unusual builds. Organization-level security configurations and policies improve consistency but require organization roles and, for private/internal repositories, appropriate product entitlements. External CI scanners may be necessary for regulated networks or existing tooling; SARIF keeps the GitHub alert/triage surface interoperable even when analysis runs elsewhere.

Do not blur external systems into GitHub: a third-party scanner owns its rules/license/runtime; GitHub hosts the repository and code-scanning result objects; Actions may orchestrate execution; rulesets govern merge admission; Git provides revisions. Each component has a separate identity, billing model, and incident boundary.

6. Worked decision: Atlas Relay

Atlas Relay has a public JavaScript SDK, a private Java service, an inherited backlog of medium findings, and one custom authorization framework. The team wants meaningful security gates without stopping all delivery.

Dimension Decision Why
Maintainability Default setup for public JS; advanced/manual setup for Java only if build coverage requires it Avoid custom workflow maintenance where it adds no coverage.
Security Default suite initially; add one versioned custom authorization query pack after tests Target a real organization-specific blind spot rather than indiscriminately adding noise.
Governance Block new High/Critical findings on protected branches; legacy Medium backlog gets owners/SLA Protect new change without creating a permanent baseline deadlock.
Reliability Track tool status, analyzed commit SHA, category, and failed/skipped scans A missing analysis must not masquerade as a clean analysis.
Compatibility Use SARIF for an existing external scanner; unique stable category per logical slice Keeps third-party analysis identity separate from CodeQL.
Cost Public repo free path; verify private Code Security entitlement and Actions minutes before rollout Do not silently assume paid private scanning or unlimited capacity.

Knowledge check

Why not use advanced setup everywhere?

What changes when you switch from default to security-extended?

Why should a custom query pack have an owner and version policy?

When is blocking all alerts a poor rollout strategy?

Does accepting an autofix eliminate the need for testing?

Summary

Configuration is a tradeoff among coverage, precision, maintenance, governance, compatibility, and cost. Default setup is the baseline; advanced setup and custom queries are justified by specific coverage needs. Gates should consume mature evidence, and autofix remains a reviewable patch proposal.

Next you will diagnose the failure modes that make apparently healthy scanning pipelines misleading or operationally harmful.

Next lesson

CodeQL, Code Scanning, SARIF, Custom Queries, Autofix, and Security Gates: Diagnostics, Failure Modes, Security, and Performance

Official references

Keep the academy open

Support free, practical DevOps education.

Every lesson is designed to remain readable in a browser, downloadable from GitHub, and usable without a paid learning platform. Contributions help expand and maintain the curriculum.

Ethereum / ERC-20
0x716c4Ab160C4B66F31a28AE2448BfF68fc3a2ef0 Send only Ethereum/ERC-20 compatible assets to this address.