LV.1
EXP 0/1000
โ—€ Playbook index
NO.19.4

๐Ÿ” Code Scanning

In one sentence

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 โ€” Hardcoded credentials, weak cryptographic algorithms, weak random
  • ๐Ÿ’ฃ 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
  • ๐Ÿ’ฌ Shown in the PR โ€” โ€œGenerate fixโ€ button โ†’ review the proposed patch โ†’ commit as-is
  • โšก 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 โ†—

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)

Code Security Risk Assessment scans the up to 20 most active repositories in your org with a single click using CodeQL, making visible "what code vulnerabilities are hiding and where" (GA April 2026).

No GHAS / Code Security license required โ€” completely free. Available to all Team and Enterprise Cloud orgs, and the Actions minutes used don't count against your Actions quota.

  • ๐Ÿ”Ž Scope โ€” selects up to 20 repos with the most recent active commits in the org (you can re-select each time)
  • ๐Ÿ“Š Output โ€” aggregated report of vulnerabilities by severity, language, and rule type, including how many are fixable by Copilot Autofix
  • ๐Ÿ•’ Frequency โ€” can be re-run once every 90 days (point-in-time inventory)
  • ๐Ÿ›‚ Permissions โ€” only Organization owners / security managers can run it
  • ๐Ÿš€ How to run โ€” Org โ†’ Security โ†’ Assessments โ†’ Run code security risk assessment
  • ๐Ÿ†“ No license required, 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: