โ—€ Playbook index
NO.19.4

Code Scanning

Updated: 2026-07-22

In a nutshell

Code Scanning is a GitHub feature that performs static analysis (SAST) on your repository's source code to find vulnerabilities.

The analysis engine is GitHub's own CodeQL (semantic analysis), and for each finding, Copilot Autofix generates an AI-powered fix suggestion with code ready to commit. Default setup starts with a single click โ€” no config file needed.

Default setup vs Advanced setup

There are two ways to enable CodeQL. Default setup is enough to start.

Aspect๐ŸŸข Default setup๐Ÿ› ๏ธ Advanced setup
ConfigurationOne click in the UI, no config fileWrite .github/workflows/codeql.yml
Language detectionGitHub detects automaticallyExplicitly specified in YAML
Queriesdefault set (GitHub recommended)default / security-extended / security-and-quality / custom
Triggerspush / PR / weekly schedule (automatic)You configure them
BuildNo build step needed for most languages (autobuild)You can specify your own build command
ScopeCan be rolled out to all repos with a clickFor cases requiring fine-grained tuning

๐Ÿ”‘ Unless you have a monorepo, special build requirements, or need custom queries, Default setup is best practice. You can switch to Advanced later.

๐Ÿ“˜ Details: Configuring default setup โ†—

Vulnerabilities CodeQL detects

CodeQL converts code into โ€œqueryable dataโ€ before analyzing it, so it understands semantics rather than just matching patterns like grep-based SAST.

  • ๐Ÿ› Injection โ€” SQL injection / Command injection / Path traversal / XSS / SSRF
  • ๐Ÿ”“ Auth & authorization โ€” Broken access control, weak cryptographic algorithms (MD5/SHA1), insecure randomness
  • ๐Ÿ’ฃ Memory safety (C/C++) โ€” Buffer overflow / use after free / null dereference
  • ๐Ÿงฉ Data flow tracking โ€” Tracks whether user input (taint source) reaches a dangerous function (sink)
  • ๐ŸŒ Supported languages โ€” C/C++, C#, Go, Java/Kotlin, JavaScript/TypeScript, Python, Ruby, Swift

๐Ÿ”ฌ CodeQL queries are open-sourced at github/codeql. You can write and extend with your own custom queries.

Copilot Autofix โ€” AI fixes it for you โ˜…

The killer feature of Code Scanning. When CodeQL raises an alert, AI generates a fix that you can commit directly to the PR.

  • ๐Ÿค– How it works โ€” The alert is passed to an LLM (GPT-4 family), which generates a diff based on the relevant code + surrounding context + CodeQLโ€™s description
  • ๐Ÿ’ฌ Where it shows โ€” On the alert page and inline in the PR; commit options: Commit to existing branch or Commit to new branch
  • โšก Reduces MTTR โ€” GitHub internal data shows fix time is 3โ€“4ร— faster
  • ๐ŸŒ Coverage โ€” JavaScript/TypeScript, Python, Java/Kotlin, C#, and other CodeQL-supported languages
  • ๐Ÿ†“ Free for OSS โ€” Copilot Autofix on public repos has been completely free since 2024 (no Copilot subscription required)

๐Ÿ’ก Not just โ€œfind vulnerabilitiesโ€ โ€” โ€œlet AI fix them tooโ€ is the new standard. Review burden drops dramatically.

๐Ÿ“˜ Details: About Copilot Autofix โ†—

Assign to Copilot โ€” delegate the fix to the agent (Public Preview)

What it does โ€” Assign a Code Scanning alert directly to Copilot Coding Agent. Copilot analyzes the vulnerability, plans the fix, and opens a draft Pull Request for you to review.

  • ๐ŸŽฏ Two ways to assign โ€” bulk (select multiple alerts in a Security Campaign โ†’ โ€œAssign Copilotโ€ โ†’ 1 consolidated PR) or single (assignee picker on the alert page)
  • ๐Ÿค– What Copilot does โ€” analyzes the vulnerability โ†’ drafts a fix plan โ†’ opens a draft PR; iterate via @copilot comments on the PR
  • ๐Ÿ“ฆ Output โ€” multi-file, repository-wide changes (vs Autofixโ€™s inline single-file patch)
  • ๐Ÿ›‚ Requirements โ€” GitHub Code Security or GHAS + Copilot Coding Agent (GHEC); the alert must already have an Autofix suggestion (Autofix-supported queries only)
  • ๐Ÿ“… Status โ€” Public Preview (2025-10-28)

๐Ÿ“˜ Details: Assign code scanning alerts to Copilot (changelog) โ†—

Autofix vs Assign to Copilot

Aspect๐Ÿ”ง Autofix (suggestion)๐Ÿค– Assign to Copilot
OutputInline patch โ€” commit to existing branch or new branchDraft Pull Request opened by Copilot bot
Fix scopeSingle file, minimal local fixMulti-file; repository-wide context
GranularityPer-alert only (Generate fix one by one)Per-alert or bulk (Security Campaign โ†’ 1 PR for many alerts)
ValidationNone at suggestion time (post-merge re-scan)Sandboxed analysis; CodeQL / CI run on the PR before merge
IterationOne-shot, no regenerate; discard if you dislike itComment @copilot on the PR to refine / re-fix
SpeedSeconds (synchronous)Minutes (async background)
License & costFree with GHAS / GitHub Code Security โ€” no extra licenseRequires Copilot Coding Agent license; consumes premium requests
PrerequisiteCodeQL query must support Autofix (otherwise no โ€œGenerate fixโ€ button)An Autofix suggestion must already exist on the alert

๐Ÿ”‘ Rule of thumb โ€” start with Autofix for quick local fixes; escalate to Assign to Copilot when the fix spans multiple files, needs refactoring, or warrants a full PR conversation.

Security Campaigns โ€” drive remediation at scale

What it is โ€” A time-boxed, org-wide remediation initiative. Curate alerts, assign owners, set a deadline, track progress on a dashboard.

  • ๐ŸŽฏ Use case โ€” โ€œFix all critical SQLi in product X by Q2โ€ / clear security-extended backlog / chase a CVE post-incident
  • ๐Ÿงญ Targeting โ€” filter by severity, CWE, query, language, repo, team, age (with preview)
  • ๐Ÿ‘ฅ Ownership โ€” routed to CODEOWNERS / teams; per-team progress
  • โฐ Deadline & dashboard โ€” due date + open / fixed / overdue tracker
  • ๐Ÿค– Pairs with Assign to Copilot โ€” bulk-assign Autofix-eligible alerts โ†’ 1 PR per repo
  • ๐Ÿ›‚ Permissions โ€” security managers / org owners at org level

How to create one

  • Org โ†’ Security and quality โ†’ Campaigns โ†’ New campaign โ€” pick From template, From code scanning filters, or From secret scanning filters

๐Ÿ“˜ Details: About security campaigns (GitHub Docs) โ†—

Getting started (fastest path)

Step 1 โ€” Enable Default setup (this alone is enough)

Repo โ†’ Settings โ†’ Code security โ†’ Code scanning
  โ†’ Set up CodeQL โ†’ Default

GitHub auto-detects your language and generates a CodeQL workflow behind the scenes. Runs automatically on push and PR โ€” results appear in the Security tab + inline comments on the PRโ€™s Files Changed tab.

Step 2 โ€” Enable Copilot Autofix

Enable Copilot Autofix inside Code scanning settings. A โ€œGenerate fixโ€ button will appear on alert pages.

Step 3 โ€” Migrate to Advanced setup (if needed)

# .github/workflows/codeql.yml
name: CodeQL
on:
  push: { branches: [main] }
  pull_request: { branches: [main] }
  schedule: [{ cron: '30 5 * * 1' }]
jobs:
  analyze:
    runs-on: ubuntu-latest
    permissions: { security-events: write, contents: read }
    strategy:
      matrix: { language: [javascript, python] }
    steps:
      - uses: actions/checkout@v4
      - uses: github/codeql-action/init@v3
        with:
          languages: ${{ matrix.language }}
          queries: security-extended
      - uses: github/codeql-action/analyze@v3

Step 4 โ€” Integrate third-party SAST tools (SARIF)

Tools like Semgrep, ESLint security, and Snyk can upload results in SARIF format to appear alongside CodeQL in the Security tab.

- uses: github/codeql-action/upload-sarif@v3
  with:
    sarif_file: results.sarif

Step 5 โ€” Enable org-wide / enterprise-wide

Use Org โ†’ Settings โ†’ Code security โ†’ default settings to apply to new and existing repos at once. Security campaigns let you manage goals like โ€œfix all critical alerts across all repos within 30 daysโ€ (Code Security).

Eligibility and pricing

FeaturePublic repoPrivate repo (No GHAS / Code Security)Private repo (With GHAS / Code Security)
CodeQL (default + advanced)โœ… FreeโŒโœ…
Third-party SARIF uploadโœ… FreeโŒโœ…
Copilot Autofixโœ… Free (since 2024)โŒโœ…
Security overview / campaignsโœ… FreeโŒโœ…
PR inline commentsโœ… FreeโŒโœ…
Custom CodeQL queriesโœ… FreeโŒโœ…

๐Ÿ’ฐ In 2025, GHAS was split โ€” if you only need code scanning, GitHub Code Security ($30/month/active committer) is enough (no full GHAS contract required). Combine with Secret Protection if you also want secret scanning.
๐Ÿ†“ Public repos get CodeQL and Autofix completely free. If youโ€™re OSS, thereโ€™s no reason not to enable this right now.
โš™๏ธ Code scanning workflows run on GitHub-hosted runners โ€” free for public repos; included in GHAS/Code Security for private repos (no additional Actions charges).

๐Ÿ“˜ Details:

Code Security Risk Assessment (free inventory scan)

What it does โ€” scans the up to 20 most active repositories in your org with a single click using CodeQL, surfacing where vulnerabilities are hiding. No GHAS / Code Security license required โ€” completely free (GA April 2026).

  • ๐Ÿ”Ž Scope โ€” up to 20 repos with the most recent active commits (re-selectable each run)
  • ๐Ÿ“Š Output โ€” aggregated report by severity, language, rule type, including how many are fixable by Copilot Autofix
  • ๐Ÿ•’ Frequency โ€” re-runnable once every 90 days (point-in-time inventory)
  • ๐Ÿ›‚ Permissions โ€” Organization owners / security managers only
  • ๐Ÿš€ How to run โ€” Org โ†’ Security โ†’ Assessments โ†’ Run code security risk assessment
  • ๐Ÿ†“ Cost โ€” no license, no Actions minutes charged โ€” perfect for evaluating Code Security before purchase

๐Ÿ“Š Pair this with Secret Risk Assessment (see Secret Scanning โ†—) to get a complete picture of your organizationโ€™s security posture in a single day. Use the results to decide whether to adopt Code Security.

๐Ÿ“˜ Details: