Code scanning
accepted ADR-0024 engineering/ADR-0024-code-scanning
code_scanning: tool: codeql fail_on: highStatus
Section titled “Status”Accepted
Context
Section titled “Context”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).
Decision
Section titled “Decision”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:
- No blocking scan without
forge.gate: blocking(ADR-0011). Withinformativeornone, a required check does not exist. - 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. Withlinked, 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.
- How a finding blocks. CodeQL blocks through the ruleset rule
“Require code scanning results”, with its security-alerts threshold at
fail_on(high_or_higherforhigh). Any other tool blocks through its own exit code atfail_on, for examplesemgrep scan --error --severity ERRORforhigh. Its SARIF is not documented to carry thesecurity-severitythat threshold reads. - 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.
- 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:
on: pull_request: push: branches: [main]permissions: contents: readjobs: 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.ZWith 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.
Consequences
Section titled “Consequences”Positive
Section titled “Positive”- An agent that changes
src/knows a tool reads it, and that a high finding blocks.
Negative
Section titled “Negative”- Until the ruleset holds the rule, an alert is reported and does not block.
- A false positive at
highblocks a merge until a person dismisses it.
Neutral
Section titled “Neutral”- The ruleset that makes an alert block is a GitHub setting, outside the repository, and nothing here checks it.
Alternatives Considered
Section titled “Alternatives Considered”Default setup
Section titled “Default setup”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.
fail_on: critical
Section titled “fail_on: critical”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.
semgrep as the default
Section titled “semgrep as the default”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.
The exit code everywhere, no SARIF
Section titled “The exit code everywhere, no SARIF”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.
Excluding tests by default
Section titled “Excluding tests by default”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.
A key in ADR-0019
Section titled “A key in ADR-0019”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.
References
Section titled “References”- Original to governance; no surdesrails SDR asks this question.
- ADR-0001: how governance ADRs are ruled on.
- ADR-0011: the gate, the pinning rule, and
forge.auditfor workflows. - ADR-0019: the dependency scan, its SARIF upload and its rule 4.
- ADR-0022: who merges.
- GitHub:
- about code scanning with CodeQL;
- customizing advanced setup;
- uploading a SARIF file;
- SARIF support;
- merge protection;
- GitHub Advanced Security;
github/codeql-action’sinitinputs (tools: linked).
- Semgrep: CLI reference, rule syntax, JSON and SARIF fields.
- Read on 2026-11-15.
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.
