How to Scan Code for Vulnerabilities with CodeQL and AI Autofix

Knowing how to scan code for vulnerabilities used to mean booking an expensive annual pen test and hoping nothing slipped through in between. After this week’s news from the UK, waiting a year looks like a risky habit.

The UK government confirmed that AI tools in its Project Dromos trial found more than 1,300 security flaws across 18 departments, a story we covered this morning in AI Vulnerability Scanning: UK’s Project Dromos Finds 1,300+ Flaws. A government spokesperson said all identified critical weaknesses were fixed and no evidence of exploitation was found. The NCSC says the approach worked by combining the speed of frontier AI models with expert human review. You do not need a government budget to copy that pattern on your own code. This guide shows how to scan code for vulnerabilities in a similar way, using GitHub’s CodeQL scanner and Copilot Autofix, with humans checking every result.

In short: Turn on CodeQL default setup in your GitHub repository settings, run the CodeQL CLI locally when you need to scan before pushing, triage alerts with a named reviewer, use Copilot Autofix to draft fixes that people review and test, and wrap it all in a simple vulnerability management process based on NCSC guidance.

Time needed: 1 to 2 hours for the first repository, then minutes per extra repo | Difficulty: Medium | Who this is for: development leads, CTOs and security owners at European software teams using GitHub

What You Need Before You Start

  • A GitHub repository where you are the owner, an organisation owner, a security manager or have the admin role.
  • GitHub Actions enabled on that repository.
  • Either a public repository, or a private organisation-owned repository on GitHub Team, GitHub Enterprise Cloud or GitHub Enterprise Server with GitHub Code Security enabled.
  • Code in a CodeQL-supported language, such as C/C++, C#, Go, Java/Kotlin, JavaScript/TypeScript, Python, Ruby, Rust or Swift.
  • A list of your repositories and who owns each one.
  • One person with authority to accept risk when a fix cannot be made quickly.

Step 1: Build an Inventory of the Code You Actually Own

You cannot scan what you do not know exists. The NCSC’s vulnerability management guidance makes this an early principle: understand what systems and software you have, who owns each asset and which vulnerabilities affect it.

For code, that means a simple spreadsheet or table with:

Field Example
Repository payments-api
Owner (a named person) Lead backend developer
Languages Java, TypeScript
Public or private Private
Internet facing? Yes
Handles personal data? Yes

Rank repositories by exposure. Anything internet facing that handles personal or payment data goes first. Old repositories nobody touches still matter, because attackers do not care how old the code is. Note them, then decide whether to archive them or include them in scanning.

This list also tells you whether you need a paid licence, which is the next step.

Step 2: Check Licensing and Eligibility Before You Click Anything

GitHub’s billing documentation says all public repositories get code scanning, secret scanning and dependency review at no charge. So for open source work, the answer to “is CodeQL free?” is yes.

Private repositories are different. Code scanning in private repositories on GitHub.com requires a GitHub Code Security licence, available on GitHub Team or GitHub Enterprise plans. GitHub bills it per unique active committer. A committer counts as active if one of their commits was pushed to a covered repository in the last 90 days, and someone who works across several repositories is counted once for the organisation.

The CodeQL CLI follows the same pattern. GitHub states it is free to use on public repositories. For private code, it is available to organisation-owned repositories on GitHub Team or Enterprise Cloud with a Code Security licence.

Practical tip: before buying, count who has pushed to your sensitive repositories in the last 90 days. That number is a fair estimate of your licence count. Check GitHub’s current pricing page for the per-committer rate, since prices can change.

Step 3: Enable CodeQL Default Setup on Your First Repository

Default setup is the quickest way to start, because GitHub chooses the languages and builds the configuration for you. From GitHub’s documentation:

  1. Open the repository’s main page and click Settings.
  2. In the Security and quality section of the sidebar, click Advanced Security.
  3. Under Code Security, find CodeQL analysis, select Set up, then click Default.
  4. In the CodeQL default configuration dialog, click Edit if you want to change languages or the query suite.
  5. Click Enable CodeQL. This starts a workflow that tests the generated configuration.

If your project pulls packages from private registries, grant code scanning access to them so analysis does not fail. For compiled languages, default setup uses the none build mode for C/C++, C#, Java and Rust, and autobuild for the others, so you usually do not need to write a build script.

Two behaviours worth knowing: if you switch an existing advanced setup to default, default setup disables the old workflow file. And if a repository has no pushes or pull requests for 6 months, its weekly scan schedule turns off.

Step 4: Run CodeQL Locally When You Need to Scan Before Pushing

Sometimes you want results before code reaches GitHub, for example on a sensitive branch or a supplier’s code drop. That is where the CodeQL CLI helps. GitHub’s documentation gives a three-part workflow:

# 1. Build a CodeQL database from your source
codeql database create codeql-dbs --source-root=src --db-cluster --language=java,python --command=./myBuildScript

# 2. Run the code scanning queries and write SARIF results
codeql database analyze codeql-dbs/java java-code-scanning.qls --format=sarif-latest --sarif-category=java --output=java-results.sarif

# 3. Optional: upload results to GitHub as code scanning alerts
codeql github upload-results --repository=my-org/example-repo --ref=refs/heads/main --commit=<your-commit-sha> --sarif=java-results.sarif

The upload step needs a GitHub token in the GITHUB_TOKEN environment variable. SARIF is a standard results format, so you can also open the file in tools that read it.

A few practical notes from the docs. The CLI does not work on musl-based Linux distributions such as Alpine, so use a glibc-based image in CI. And remember the licence rule from Step 2: running the CLI against private commercial code needs a Code Security licence unless the code is public.

Step 5: Triage Every Alert with a Named Human Reviewer

This is the lesson from Project Dromos that matters most. The NCSC says the programme paired frontier AI models with specialists who assessed and prioritised findings, and built governance and assurance processes to manage false positives. The machine finds; people decide.

Set up a weekly triage routine:

  1. Open the repository’s Security tab and review new code scanning alerts.
  2. For each alert, the repository owner from Step 1 confirms whether it is real, reachable and exploitable in your context.
  3. Rank confirmed issues by exposure. An injection flaw in an internet-facing API beats a theoretical issue in an internal script.
  4. Dismiss false positives with a written reason, so the next reviewer understands the decision.
  5. Record who reviewed what and when.

Do not let alerts pile up untouched. A long, ignored alert list trains developers to stop looking, which is worse than not scanning at all. If the first scan produces hundreds of alerts, start with critical and high severity findings in your top-ranked repositories and work downward.

Step 6: Draft Fixes with Copilot Autofix, Then Review and Test Them

Copilot Autofix is the AI part of this workflow. According to GitHub, it generates a suggested code change for a single code scanning alert, using large language models, your codebase and the code scanning analysis. You review it and apply it yourself.

Setup is simple: there is no separate step. GitHub says enabling code scanning with CodeQL is enough, and Autofix is on by default unless an administrator disables it. It is available for public repositories on GitHub.com and for private or internal organisation repositories with a GitHub Code Security licence. GitHub also states that Copilot Autofix suggestions do not consume AI credits.

For larger backlogs, GitHub also offers agentic autofix. You assign one or more alerts to Copilot, and it investigates the wider codebase, generates and validates a fix, and opens a draft pull request. It uses Code Security AI credits and GitHub Actions minutes, but does not need a Copilot licence. GitHub notes it cannot fully validate fixes for alerts from custom queries, the security-extended suite or third-party tools.

Whichever you use, apply the same rule GitHub gives: review and test generated changes before you merge. Treat AI fixes like a junior developer’s pull request, helpful and fast, but never merged without a second pair of eyes and passing tests.

Step 7: Turn Scanning into a Living Vulnerability Management Process

A scan is a snapshot. Learning how to scan code for vulnerabilities is only half the job; security comes from the routine around it. The NCSC’s vulnerability management guidance gives a useful backbone for smaller European teams too:

  • Update by default: apply fixes and updates as soon as possible, ideally automatically.
  • Know your assets: keep the inventory from Step 1 current as repositories are added or retired.
  • Triage and prioritise: have a process for issues with no patch or no quick fix.
  • Own the risk: the NCSC says a decision not to update is a senior-level risk decision. Record it and have a manager sign it off.
  • Verify and review: the process should keep evolving as your estate changes.

Put numbers on it. Track how many alerts are open, how old the oldest critical alert is, and how many fixes merged each month. Review those three figures in your monthly engineering meeting. If you work under NIS2 or similar rules, these records also show auditors that vulnerability handling is a real, repeatable process rather than a one-off exercise.

Checklist: How to Scan Code for Vulnerabilities at a Glance

  • List every repository with an owner, languages and exposure level.
  • Confirm licensing: public repos are free; private repos need GitHub Code Security.
  • Enable CodeQL default setup under Settings, Advanced Security, CodeQL analysis.
  • Use the CodeQL CLI for pre-push or third-party code scans (not on Alpine).
  • Triage alerts weekly with a named reviewer; document dismissals.
  • Use Copilot Autofix or agentic autofix to draft fixes; always review and test.
  • Have a senior person sign off any risk you choose not to fix.
  • Track open alerts, oldest critical alert and fixes merged each month.

Common Mistakes to Avoid

Merging AI fixes without review. Autofix is a draft. Project Dromos succeeded because specialists checked the AI’s findings, and the same applies to AI-written fixes.

Scanning only new code. Legacy repositories and services nobody has touched in years are often where the worst flaws live. Include them in the inventory, even if you scan them later.

Ignoring the alert backlog. Turning on scanning and never triaging creates a false sense of security and a long list an auditor will happily read.

Assuming a clean scan means secure code. CodeQL finds patterns its queries know about. It does not replace threat modelling, dependency management, secret scanning or a proper penetration test for critical systems.

Forgetting licence rules for the CLI. Running CodeQL on private commercial code without a Code Security licence breaks GitHub’s terms. Check before you script it into CI.

Frequently Asked Questions

Is CodeQL free?

Yes for public repositories. GitHub says all public repositories get code scanning at no charge, and the CodeQL CLI is free to use on public repositories. For private repositories on GitHub.com, you need a GitHub Code Security licence on GitHub Team or an Enterprise plan, billed per unique active committer over the last 90 days.

What is CodeQL used for?

CodeQL is GitHub’s code analysis engine. It builds a database from your source code and runs queries against it to find security vulnerabilities and coding errors. Results appear as code scanning alerts in GitHub, or as SARIF files when you run the CLI locally. It supports languages including Java, Python, JavaScript, TypeScript, C#, Go, Ruby, Rust and Swift.

What is Copilot Autofix?

Copilot Autofix is a GitHub feature that suggests a code change for a single code scanning alert, using large language models plus CodeQL’s analysis of your code. It is on by default wherever CodeQL is enabled, unless an admin turns it off. You review the suggestion and apply it yourself. Its suggestions do not consume AI credits.

How to run CodeQL locally?

Install the CodeQL CLI from GitHub’s official release, then run codeql database create on your source, followed by codeql database analyze with a query suite and --format=sarif-latest. You can upload the SARIF to GitHub with codeql github upload-results. Use a glibc-based Linux, not Alpine, and respect the licence rules for private code.

How to enable CodeQL in GitHub?

Go to your repository’s Settings, open Advanced Security under the Security and quality section, find CodeQL analysis under Code Security, choose Set up and then Default. Review the configuration and click Enable CodeQL. You need admin-level access, GitHub Actions turned on, and either a public repository or GitHub Code Security for private code.

Key Takeaways

  • AI plus humans works: Project Dromos found over 1,300 flaws across 18 UK departments by pairing AI with expert review.
  • Start with default setup: CodeQL default setup takes a few clicks and picks languages for you.
  • Licensing is simple: public repositories are free; private ones need GitHub Code Security.
  • Autofix drafts, people decide: review and test every AI-generated fix before merging.
  • Process beats tools: inventory, triage, senior risk sign-off and monthly metrics turn scanning into real security.

Need Expert Help?

If this feels like a lot to manage alone, TecniForge can handle the heavy lifting. Our team specializes in custom software development and AI integration. We can help you set up CodeQL across your repositories, clear the first wave of alerts and build a triage routine your team will actually keep, alongside the incident planning in our guide on how to create an incident response plan. Get in touch with our experts.

Also read: AI Vulnerability Scanning: UK’s Project Dromos Finds 1,300+ Flaws, our earlier coverage on why this matters today.

Here is your challenge: enable CodeQL default setup on your most exposed repository before Friday, and put the first triage meeting in the calendar. If the UK government can find and fix critical flaws across 18 departments, your team can clear one repository.

Sources


Discover more from TecniForge

Subscribe to get the latest posts sent to your email.