Skip to content

Code scanning

accepted ADR-0024 engineering/ADR-0024-code-scanning

Decided traits
code_scanning:
tool: codeql
fail_on: high

Accepted

ADR-0019 scans what the repository depends on. Nothing reads the code the repository writes: an HTTP route that builds SQL from a parameter, a path taken from user input, a command assembled with a string.

While these keys are empty, an agent writing such code does not know whether a tool will analyse it. Facing an alert, it does not know whether the alert blocks, nor whether it may dismiss it or exclude the file.

Static analysis reads the code without running it. CodeQL, GitHub’s engine, supports Python and JavaScript/TypeScript among other languages, and is free on public repositories. Private repositories need GitHub Code Security. Semgrep is a rule-based scanner that runs anywhere.

Narrowing a scan silences it without saying so. A dismissed alert stays in the Security tab, with who dismissed it and why. A path in paths-ignore, or a query removed by query-filters, leaves nothing to see: the alert never exists.

A scan of small code finds little. Measured on governance itself, a TypeScript CLI that validates its inputs: CodeQL’s 87 default queries reported one alert, a false positive in a test helper. The question is asked for the repositories where routes, queries and paths do come from outside.

Not concerned: the workflows themselves (ADR-0011’s forge.audit), secrets (ADR-0015), dependencies (ADR-0019).

What governance recommends, and why.

Key Recommended value Reason
code_scanning.tool codeql free on public repositories, supports both languages ADR-0004 recommends, and its results carry the severity GitHub’s merge protection reads. semgrep for a private repository without GitHub Code Security
code_scanning.fail_on high the finding is in code this repository wrote, and the agent that wrote it can fix it in the same change. ADR-0019 stops at critical because a dependency’s fix waits on someone else’s release; this one waits on nobody

none is an answer for tool, for a repository with no code that handles outside input. Any tool that writes SARIF answers it too.

What governance fixes, whatever you rule:

  1. No blocking scan without forge.gate: blocking (ADR-0011). With informative or none, a required check does not exist.
  2. The scan runs in a workflow, pinned, on every change.
    • It runs in a workflow (for CodeQL, the advanced setup), on every pull request and every push to the default branch, with its actions pinned by SHA (ADR-0011 rule 3).
    • For CodeQL, set tools: linked. A SHA pin alone does not freeze the queries: on github.com the action uses the bundle GitHub recommends at run time. With linked, the bundle and its queries change only when Dependabot updates the action, in a pull request that is scanned. A scheduled scan then adds nothing.
    • The results go to GitHub code scanning as SARIF, where ADR-0019’s scanner already sends its own. Where the plan does not allow the upload, the SARIF stays a job artifact.
    • Default setup alone does not answer this ADR: it is a setting no file records, and it runs the version GitHub picks.
  3. How a finding blocks. CodeQL blocks through the ruleset rule “Require code scanning results”, with its security-alerts threshold at fail_on (high_or_higher for high). Any other tool blocks through its own exit code at fail_on, for example semgrep scan --error --severity ERROR for high. Its SARIF is not documented to carry the security-severity that threshold reads.
  4. All code is scanned, tests included. governance cannot tell what counts as test code in another repository, and a fixture that shells out is still a command built from a string.
  5. Narrowing the scan is a person’s call. Dismissing an alert, excluding a path (paths-ignore, paths, a tool’s ignore file) and removing a query or rule (query-filters, a narrower suite) all silence a finding. The agent fixes the code, or proposes one of these with its reason, and a person dismisses or merges it, as ADR-0019 rule 4 has for an ignore rule and ADR-0022 for any merge.

What codeql looks like in practice:

.github/workflows/codeql.yml
on:
pull_request:
push:
branches: [main]
permissions:
contents: read
jobs:
analyze:
runs-on: ubuntu-latest
permissions:
contents: read
security-events: write
strategy:
matrix:
language: [javascript-typescript] # or python
steps:
- uses: actions/checkout@<sha> # vX.Y.Z
with:
persist-credentials: false
- uses: github/codeql-action/init@<sha> # vX.Y.Z
with:
languages: ${{ matrix.language }}
tools: linked
- uses: github/codeql-action/analyze@<sha> # vX.Y.Z

With semgrep, the job runs semgrep scan --sarif --output semgrep.sarif then github/codeql-action/upload-sarif (or actions/upload-artifact), and a separate semgrep scan --error --severity ERROR step that fails the job.

Adopted as recommended. The repository is public and written in TypeScript. CodeQL runs from .github/workflows/codeql.yml (trivoallan/ontrack#171), and GitHub’s default setup is off. The ruleset rule “Require code scanning results” at high_or_higher, which makes a high alert block, is a GitHub setting this file cannot set.

  • An agent that changes src/ knows a tool reads it, and that a high finding blocks.
  • Until the ruleset holds the rule, an alert is reported and does not block.
  • A false positive at high blocks a merge until a person dismisses it.
  • The ruleset that makes an alert block is a GitHub setting, outside the repository, and nothing here checks it.

One click in the repository’s settings, and GitHub picks the languages, the queries and their version. Nothing in the repository records it, the check cannot see it, and the version moves without a pull request. It is fine to try, as governance did, before writing the workflow.

ADR-0019’s threshold. Fewer blocked merges, and high findings that only report. It suits code whose fix the agent cannot make, which is not the case for a repository’s own code.

It runs anywhere, with no plan condition, and its rules are easy to read and write. Its results do not carry the severity GitHub’s merge protection reads, so blocking goes through each workflow’s flags instead of one ruleset.

Simpler: the job fails or passes. Alerts then live in CI logs, and a finding is silenced by changing a flag instead of dismissing an alert with its reason.

Less noise, as with governance’s false positive. It needs a list of test paths per language that governance would guess for every repository, and it is an exclusion nobody decided.

ADR-0019 asks what a release contains. This question is about the code the repository writes. One ADR for both would be the catch-all the supply-chain ADRs were split to avoid.

The keys.

Key What it holds Allowed values
code_scanning.tool what analyses the repository’s own code codeql, another SARIF-writing tool, or none
code_scanning.fail_on the lowest severity that blocks a merge critical, high, medium, low, none

An empty key is not an answer. The value is written in this file and nowhere else; whoever needs it links here. See ADR-0001 for the check command.