Skip to content

Domain 5: Use code scanning with CodeQL (20%) โ€‹

โ† Domain 4 ยท Next Domain โ†’

Exam Tip

Know the difference between default setup and advanced setup, and when to use each. Understand the different CodeQL query suites and what CodeQL packs are used for.


What is CodeQL? โ€‹

CodeQL is a semantic code analysis engine that treats code as data, allowing you to query it for vulnerability patterns. It powers GitHub's native code scanning feature.

Supported Languages โ€‹

  • C / C++
  • C# / .NET
  • Go
  • Java / Kotlin
  • JavaScript / TypeScript
  • Python
  • Ruby
  • Swift (for iOS/macOS apps)

CodeQL Setup Options โ€‹

Default Setup โ€‹

The fastest way to enable CodeQL โ€” GitHub automatically:

  • Detects the languages in your repository
  • Selects the appropriate query suite (security-extended)
  • Configures scan triggers (push to default branch, PRs to default branch)
  • No workflow YAML file needed

Enable via: Settings โ†’ Code security โ†’ Code scanning โ†’ Set up โ†’ Default

Best for

Repositories where you want immediate, zero-configuration scanning. Ideal for most projects.

Advanced Setup โ€‹

A GitHub Actions workflow file (.github/workflows/codeql.yml) gives you full control over:

  • Which query suites to run (default, extended, custom)
  • Which branches to scan
  • Scan schedule (cron)
  • Build commands for compiled languages
  • Custom CodeQL packs

Enable via: Settings โ†’ Code security โ†’ Code scanning โ†’ Set up โ†’ Advanced

Example Advanced CodeQL Workflow โ€‹

yaml
name: CodeQL Analysis

on:
  push:
    branches: [main, develop]
  pull_request:
    branches: [main]
  schedule:
    - cron: '0 2 * * 1'   # Every Monday at 2am UTC

jobs:
  analyze:
    name: Analyze
    runs-on: ubuntu-latest
    permissions:
      security-events: write
      contents: read

    strategy:
      matrix:
        language: [javascript, python]

    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: Initialize CodeQL
        uses: github/codeql-action/init@v3
        with:
          languages: ${{ matrix.language }}
          queries: security-extended   # or: security-and-quality

      - name: Autobuild
        uses: github/codeql-action/autobuild@v3

      - name: Perform CodeQL Analysis
        uses: github/codeql-action/analyze@v3

Comparing Default vs Advanced Setup โ€‹

Default SetupAdvanced Setup
ConfigurationZero YAML โ€” GitHub auto-configures.github/workflows/codeql.yml required
Language detectionAutomaticManual (matrix configuration)
Query suitesecurity-extended (auto)Configurable (any suite or custom queries)
ScheduleOn push and PR to default branchFully configurable (cron, any branch)
Build stepAutomatic (autobuild)Manual (specify build commands)
Best forQuick start, standard projectsMonorepos, compiled languages needing custom build, custom queries

CodeQL Query Suites โ€‹

CodeQL includes predefined query suites to group vulnerabilities and checks together:

SuiteDescriptionWhen to use
security-extended (default)Security queries + additional CWE coverageMost repositories
security-and-qualitySecurity + code quality queries (can be noisy)When you want code quality coverage too
Custom packsYour own or third-party CodeQL queriesSpecialized security requirements

Exam Trap

Default setup uses the security-extended query suite by default โ€” not security-and-quality. The quality suite generates more alerts and is not enabled by default because it may produce more noise.


Troubleshooting CodeQL Scanning โ€‹

ProblemLikely CauseFix
No alerts generatedLanguage not supported or wrong language configVerify language matrix in workflow
Autobuild failsCompiled language requires specific build stepsUse advanced setup with manual build commands
Too many alerts (noise)security-and-quality suite enabledSwitch to security-extended

Domain 5 Quick Quiz

1 / 3
โ“

What is the difference between CodeQL default setup and advanced setup?

(Click to reveal)
๐Ÿ’ก
Default setup: Zero YAML, GitHub auto-detects languages and configures scanning โ€” fastest to enable. Advanced setup: You write a codeql.yml workflow for custom query suites, build steps, and schedules โ€” maximum control.

โ† Domain 4 ยท Next Domain โ†’

Happy Studying! ๐Ÿš€ โ€ข Privacy-friendly analytics โ€” no cookies, no personal data
Privacy Policy โ€ข AI Disclaimer โ€ข Report an issue