diff --git a/.github/skills/community-packs-migration/SKILL.md b/.github/skills/community-packs-migration/SKILL.md new file mode 100644 index 00000000..0baf8381 --- /dev/null +++ b/.github/skills/community-packs-migration/SKILL.md @@ -0,0 +1,162 @@ +--- +name: community-packs-migration +description: Move a gap-issue query or data extension model from a Copilot pull request in this repository into GitHubSecurityLab/CodeQL-Community-Packs as a neutral, tested, reviewable pull request, then verify that the released query detects the original finding and that the scans did not get much slower. Use when asked to migrate, port, upstream or contribute a gap issue to Community Packs, to check or measure a Community Packs unit, to run the Copilot code review loop on such a pull request, to update the tracker after one merges, to check that a language pack and its audit suite are named in the configs and selected by a suite, to verify and count detections after a release, or to compare the code scanning job times before and after a release. Runs in a local, human-gated session. Do not use it from the cloud agent. +--- + +# Community Packs migration + +A gap issue in this repository has a Copilot draft pull request with a prototype query or model +rows. When the triage says the destination is +[CodeQL Community Packs](https://github.com/GitHubSecurityLab/CodeQL-Community-Packs) (CCP), this skill turns +the prototype into a CCP pull request that stands on its own, and afterwards checks that the released +query finds what it was written for. + +Develop and test the prototype with the `ql-tdd-agent`. Use this skill once a prototype exists. +Paths are relative to this skill's directory (`.github/skills/community-packs-migration`). + +## Do not use it when + +- The triage destination is `github/codeql` (a data extension edit or an unambiguous add, or a + query with very-high precision and no concerns). Raise it there instead. +- The pull request spans more than one language. Split it first (`plan` refuses it). +- You are the Copilot cloud agent. It cannot publish to another repository, and every public + write below needs a human. + +## Rules that cost the most when missed + +1. **Nothing public without a human's approval.** No push, pull request, issue, comment or tracker + edit until the human has reviewed the whole diff and every outbound string. The scripts never do + it for you. +2. **Public text is neutral.** It never mentions this repository, its issues or pull requests, the + tracker, any internal repository, any customer or the synthetic applications. Replace their + identifiers at plan time (`--replace OLD=NEW`) and deny them at check time. Set `CCP_EXTRA_DENY` + (comma separated) to the names that are not public; every gate applies it. +3. **Never change a pack `version:`.** A release sets every version, and merging never publishes. + `check` fails on it. (The CCP `CONTRIBUTING.md` still lists a version bump in its checklist. This + skill does not follow that line.) +4. **One pull request per gap issue**, opened as a draft. Experimental queries stay in the default + suite: do not change what an existing suite selects. `@precision` is the assessed value from + the triage, never the prototype's. +5. **A merged query does not run until a config names its pack and a suite selects it.** Adding + queries does not add the pack to `configs/default.yml` and `configs/synthetics.yml`, and an + audit query is selected only by `-audit.qls`, which `configs/audit.yml` names after + the release that carries the suite. This was missed for Actions and again for Rust. `check` + fails on both, `community_packs_onboard.py` reports every language and fixes them with + `--apply`, and a config on `main` must not name a suite or pack that the latest release lacks: + the CLI cannot read it, and a scan that uses that config would fail (`--published` finds those) + ([guide](references/migration-guide.md), section 4). +6. **Hide the user CodeQL config for every local gate** (`CODEQL_CONFIG_FILE` pointing at an empty + file; the scripts do it). Use the CLI version in `.codeqlversion` of CCP. +7. **Read Copilot code review in full.** Findings in unchanged code appear only in the review body, + with no thread. Reply once to each, fix the real ones test first, and stop when a review lists + nothing open. +8. **Cost is yours to judge.** The pack's CI runs queries only on tiny databases and `experimental` + does not keep a query out of the default suite, so `measure` is the only performance check. + Record the cost class it reports. A query that is not `low` needs a decision (fix, narrow, audit + only when it is audit-grade, a maintainer suite change, or withhold) before it leaves draft + ([guide](references/migration-guide.md), Performance risk). +9. **Passing tests do not prove detection.** A test database and a scan database can resolve the same + code differently, and a fixture that imports the same names explicitly elsewhere in the file + resolves what the real code does not (the Iron prelude, which `check` cannot see). Give a library + model a fixture with the imports of the real sample and nothing more. After the release, look for + the alert in the scan, and when it is missing read the call resolution of that database + (`scripts/scan_database.py`) before blaming the query + ([verify-detection.md](references/verify-detection.md), section 6). When the calls turn out to have + no target, the fix is a fallback by name with its own test pattern + ([guide](references/migration-guide.md), "A fallback for calls that have no target"), and its result + is checked on that scan database before the pull request opens. + +## Setup, once + +- `gh` signed in, the `codeql` CLI at the version in the CCP `.codeqlversion`, Python 3. +- A clone of CCP (fetch `origin/main`), and a sparse clone of `github/codeql` for stubs + ([guide](references/migration-guide.md), Tooling). +- A clone of this repository with the pull request heads fetched, because `plan` reads them from + `refs/prs/*`: `git fetch origin '+refs/pull/*/head:refs/prs/*'`. +- Short paths outside every repository for ``, ``, ``, ``. + +## Workflow + +| Step | Do | Details | +| ---------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------- | +| 1. Read | The gap issue (labels `precision:*`, `tags:experimental`, the CWE, and the triage comment that starts with ``) and its pull request. Go or no-go. | Guide, section 1 | +| 2. Plan | `plan --template --triage ... --replace OLD=NEW` (or the flags `--precision --experimental --placement --cwe --id-name` when there is no triage file) | Guide, sections 2 to 5 | +| 3. Port | `prepare`, then `apply`, then hand edits: readiness items, neutral fixtures, negative tests | Guide, section 6 | +| 4. Gate 1 | `check`: CCP rules, format, strict compile, tests | Guide, section 7 | +| 5. Gate 2 | `measure` on a real corpus (`community_packs_corpus.py`), classify every row, record the cost class | Guide, section 7 | +| 6. Packet | The evidence and the drafted pull request text; `scan` must have no `fail` | Guide, Human gate | +| 7. Publish | Human approves, then sign, push the branch, `gh pr create --draft` | Guide, Human gate | +| 8. Review | Copilot code review loop until a review lists nothing open | Guide, Human gate | +| 9. Track | `tracker_action.py set "" --apply` | Guide, Tracker | +| 10. Verify | After the release: run `community_packs_onboard.py --apply --published` on a fresh `main` (a pack or an audit suite that no config names is the usual reason nothing shows up), then predict locally, enable the language, point the scan at the pack, count. A linked alert that is missing although the query ran: read the scan database (`scan_database.py download`, then `calls`; [verify-detection.md](references/verify-detection.md), section 6) | [verify-detection.md](references/verify-detection.md), sections 1 to 6 | +| 11. Time | Last check, before recording: save the scan times before the release, then confirm that every repository uses the new pack (`packs`), compare the job times before and after (`compare`), and for a pair that got much slower read the logs (`explain`): new queries, other new queries of the release, or something else | [verify-detection.md](references/verify-detection.md), section 7 | + +```powershell +python scripts/community_packs_migrate.py plan --template --out \spec.json --replace OLD=NEW +python scripts/community_packs_migrate.py prepare --spec \spec.json --ccp --wt-root --work-root --stubs +python scripts/community_packs_migrate.py apply --spec --ccp --codeql +python scripts/community_packs_migrate.py check --spec --ccp --codeql --deny-file \deny.txt +python scripts/community_packs_onboard.py --ccp --language [--apply] # pack lines in the configs, the audit suite +python scripts/community_packs_migrate.py measure --spec --ccp --codeql --db --out \measure +python scripts/community_packs_migrate.py scan --ccp --deny-file \deny.txt --pr-body \pr-body.md +python scripts/tracker_action.py set "" --apply +python scripts/verify_alerts.py gap --issue --rule +python scripts/scan_database.py download --repo --language rust --out \scan-db # the database of the newest scan +python scripts/scan_database.py calls --db \scan-db\db\rust --codeql --file "%%" --unresolved # the calls that have no target (Rust) +python scripts/scan_timing.py collect --out \scan-before.json # before the release, and again after it +python scripts/trigger_scans.py --property Synthetic=true --language --apply # scan again after the release +python scripts/scan_timing.py packs --jobs \scan-after.json --version --since --ours +python scripts/scan_timing.py compare --jobs \scan-before.json --jobs \scan-after.json --cutoff --version +python scripts/scan_timing.py explain --jobs \scan-before.json --jobs \scan-after.json --cutoff --version --ours +``` + +`apply` never overwrites, `plan` is deterministic (change a flag and plan again, do not edit the +spec), and `check`, `measure`, `scan` and `baseline` run with the user config hidden. A model-only +unit has no query to measure; the guide says what replaces it. All options: `--help` on each +command. + +## Handing a unit to the Copilot coding agent in CCP + +The maintainer asked (2026-11-24) that work for CCP go to the coding agent (CCA) next time rather than be +done locally for hours. Do that when the design is clear: a fix with a failing test, a query with its +cases written down. The agent sees only the repository it runs in, not this one. Write the task yourself, +with no name of this repository, the tracker or a synthetic application: the weakness, what the query must +report and must not, the positive and negative cases as code, the contract in +[the guide](references/migration-guide.md) (ids, metadata, tests, no version change, experimental +tag), and the Copilot review rule above. Then +`gh agent-task create -R GitHubSecurityLab/CodeQL-Community-Packs -F `. Review the pull +request as you would your own, and run `scan` against its branch before it leaves draft. + +What the agent has and lacks (**checked** 2026-11-24 in its run logs, `gh run view -R +GitHubSecurityLab/CodeQL-Community-Packs --log`, the `GITHUB_COPILOT_MCP_JSON_FROM_INPUT` value decoded from base64): + +- It has the pinned CodeQL CLI, the pack dependencies and the `github/codeql` test stubs, which + `.github/workflows/copilot-setup-steps.yml` installs, so it can run `codeql test run` and + `codeql query compile`. Its instructions (`.github/copilot-instructions.md`) cover releases and CLI + bumps, not writing queries, so the task has to carry the query rules. +- **It has no CodeQL Development MCP server.** The MCP configuration of its 2026-11-19 run was only the + built in Playwright server. The template repository's agent has one (`ql-mcp`: `"type": "local"`, + `"command": "codeql-development-mcp-server"`, `"tools": ["*"]`), installed by setup steps: Node 26, then + `npm install --global codeql-development-mcp-server@` and `codeql-development-mcp-server-setup-packs`. + Giving the CCP agent the same takes a pull request for `copilot-setup-steps.yml` and the MCP configuration + in the repository settings (an admin, no API). Neither is done. Look again before relying on it. +- It cannot see a scan database, the org that scans, or this repository, so the diagnosis that needs them + (why a query found nothing live), the tracker, and the check after the release stay local. Give the agent the + small reproduction and the cases instead. +- A Rust test run takes 3 to 4 minutes wherever it runs (the extractor builds the crate and extracts its + dependency sources), and the CCP CI runs all of the language's tests when a pull request changes a file that + is not a query (8 Rust tests took 17 minutes on 2026-11-24). A hand-off does not make either faster, it moves + the wait to a place where nobody is waiting, so ask the agent for one batch of fixes per review round. + +## References + +- [references/migration-guide.md](references/migration-guide.md): the contract. Layout, ids, + metadata, suites, tests, quality bar, disclosure, human gate, tooling. +- [references/worker-brief.md](references/worker-brief.md): the operating rules for one delegated + worker that migrates a single issue into a local branch. +- [references/verify-detection.md](references/verify-detection.md): after the release, closing the + loop, counting alerts and timing the scans before and after. +- `scripts/`: `community_packs_migrate.py`, `community_packs_corpus.py`, `community_packs_onboard.py`, `tracker_action.py`, + `verify_alerts.py`, `scan_database.py`, `scan_timing.py`, `trigger_scans.py`, `rule_value.py`, `gap_overlap.py`, `default_setup_languages.py`, + `enable_workflows.browser.js` (run in a signed-in browser page) and their offline tests + (`python -m unittest` in that directory). diff --git a/.github/skills/community-packs-migration/references/migration-guide.md b/.github/skills/community-packs-migration/references/migration-guide.md new file mode 100644 index 00000000..6604fc28 --- /dev/null +++ b/.github/skills/community-packs-migration/references/migration-guide.md @@ -0,0 +1,901 @@ +# Moving a template fix into Community Packs + +This is the playbook for turning a prototype fix from the synthetic-app pipeline +into a contribution to +[GitHubSecurityLab/CodeQL-Community-Packs](https://github.com/GitHubSecurityLab/CodeQL-Community-Packs) +(CodeQL Community Packs, CCP). It covers mechanics and the quality bar. Whether an item +belongs in CCP at all is decided by the triage on the gap issue (its destination +and assessed precision), and +[section 4](#4-security-grade-or-audit-grade-and-what-a-suite-does-with-it) says how +an audit query is framed. + +The input is a gap issue in the template repo and its Copilot draft pull +request. Template pull requests keep their work under +`languages//custom/{src,test,models}`. They are prototypes: they have +passed their own small tests, nothing more. Two other records come with each +item. The **triage** holds the assessed precision, the destination and the +readiness items. The **tracker** is the template repo's tracking issue, whose +per-language tables have an Action column. + +Everything in CCP is public. Read [Disclosure](#disclosure) before you copy a +file. + +Commands run from the skill directory (`.github/skills/community-packs-migration`). +Locations on your machine are written as ``, ``, ``, +`` and ``: keep them short and outside every repository. + +## The pipeline + +| Step | Command | What it does | +| ---------------- | ------------------------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| Size the backlog | `plan-all` | A spec for every triaged pull request, and a tally of what needs a person. | +| Plan one item | `plan` | The spec for one pull request. Change a flag and plan again, do not hand edit the spec. | +| Port | `apply` | Copies files into a CCP worktree, rewrites `@id`, `@precision` and `@tags`. It leaves pack versions alone. | +| Hand edit | | Readiness items, neutral fixtures, negative tests. | +| Gate 1 | `check` | The CCP rules, formatting, compile with `--warnings=error`, tests, the suite for the query's group, the pack lines in the configs. | +| Configs | `community_packs_onboard.py` | Reports (and with `--apply` fixes) the pack lines and the audit suite that make a query run, and with `--published` the lines that name something the latest release lacks. | +| Corpus | `community_packs_corpus.py sample` or `targeted` | A database of real public code, built once per language and shared, read only. | +| Gate 2 | `measure` | Runs the query on a corpus, profiles it, keeps every row for triage. | +| Evidence | `community_packs_corpus.py links` | Commit pinned permalinks and repository metadata for the rows. | +| Packet | | A package for the human to review and publish. | +| Track | `tracker_action.py` | Records the pull request and its state in the tracker's Action column (see [Tracker](#tracker)). | +| Verify | `verify_alerts.py` | After the release: does the query find the original finding, and how many alerts does it raise. See [verify-detection.md](./verify-detection.md). | + +The commands live in [`scripts/community_packs_migrate.py`](../scripts/community_packs_migrate.py), +[`scripts/community_packs_corpus.py`](../scripts/community_packs_corpus.py), +[`scripts/community_packs_onboard.py`](../scripts/community_packs_onboard.py), +[`scripts/tracker_action.py`](../scripts/tracker_action.py) and +[`scripts/verify_alerts.py`](../scripts/verify_alerts.py). +Nothing in the pipeline pushes, opens a pull request or comments. The one script that can write +to GitHub is `tracker_action.py` (the tracker's comments), and only with `--apply`; +`verify_alerts.py` only reads. Publishing is a +public write and needs a human ([Human gate](#human-gate)). A worker that +migrates one issue follows [`worker-brief.md`](./worker-brief.md). + +## Decisions taken + +These were open after the pilot and are settled as below. If the maintainers decide +differently, change this table and the affected packets, not one pull request at a +time. + +| Question | Decision | Why | +| -------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| Suite posture | Ship security-grade with the `experimental` tag and leave the query in the default suite: experimental is what Community Packs is for, and a non-experimental query belongs in `github/codeql`. **Do not change what an existing suite selects in a query pull request.** The first audit query of a language brings its audit suite (`community_packs_onboard.py --apply` creates it), and every query needs its pack named in the configs ([section 4](#what-makes-a-query-run)). The packet records what `.qls` selects. | Confirmed by the maintainer (2026-11-18). The existing experimental queries in CCP are in the default suites, so the tag is informational there. The configs and the audit suite were missed for Actions and again for Rust (2026-11-24), so `check` now fails on both. | +| Language segment of `@id` | Always, following the stock prefixes in section 3. | Matches the requested `githubsecuritylab/java/...` form. Shipped ids stay as they are. | +| Pull request granularity | One pull request per tracker issue (confirmed by the maintainer, 2026-11-18). A worker builds one branch per **unit**: a query with its help and tests, or the model files with the tests no query owns. `plan-all` splits a template pull request into units (and a multi-language one by language), and the units of one issue are combined into one pull request when it is published. | Independent units can be reviewed or reworked alone, a worker's scope stays small, and the tracker Action cell holds one link per issue. | +| `decision_needed` items | Proceed when the recommended destination is CCP. | CCP is the conservative default for anything doubtful, and a later move to `github/codeql` stays possible. | +| Model rows for a language without an ext pack | A separate pull request adds the data extension pack first (confirmed by the maintainer, 2026-11-18). [GitHubSecurityLab/CodeQL-Community-Packs#254](https://github.com/GitHubSecurityLab/CodeQL-Community-Packs/pull/254) added the empty packs for JavaScript, Ruby and C++ (the languages with pending model rows) and merged on 2026-11-18, so those languages now take model rows. Swift and Actions have no ext pack and no pending model rows. | Creating an ext pack is its own change. | +| Example to cite | None by default. A pull request does not cite a live project. | A true positive on a live project is an unpatched vulnerability or a leak. The packet keeps the evidence for the maintainer. | +| Evidence per unit | Two tiers (section 7): a true positive on a real project for precision high and above, the shared corpus measure with every row classified for the rest. | The true positive search took 1 to 3 hours per unit in the first batch. The maintainer can still require it for any unit. | +| CodeQL config for gates | Empty (`CODEQL_CONFIG_FILE`, no user config) for `check`, `measure` and every test run. | A user config can enable every threat model, which CI does not. | +| A language whose tests cannot run on your platform (Swift has no extractor on Windows) | Migrate the files, record "tests not run locally", and let CI run them. | The gate cannot be met locally, so the packet says so instead of pretending. | + +## 1. Go or no-go + +Stop and send the item back if any of these hold: + +- The triage destination is not Community Packs. An item with `decision_needed` + proceeds when the recommended destination is Community Packs. Record the + alternative in the packet. +- It is a data extension **edit** or a straightforward unambiguous **add**. + Those belong in `github/codeql`. +- The pull request touches more than one language. Split it first + (`plan` refuses to continue). +- It is a bundle and you were given the whole of it. Migrate one unit at a time + (`plan-all` names them). The triage `split_note` says which parts are + separable and which could go to `github/codeql` instead; record that in the + unit's packet. +- A readiness item in the triage cannot be met. Record it as accepted by a + human, with a reason, or do not migrate. + +## 2. Where each file goes + +`` is the pack directory (`actions`, `cpp`, `csharp`, `go`, `java`, +`javascript`, `python`, `ruby`, `rust`, `swift`). The template language `html` +migrates into `javascript`. + +| Template pull request | Community Packs | +| ---------------------------- | --------------------------------------------------------------------------------------------- | +| Query `.ql` | `/src//CWE-NNN/.ql`, where `` is `security` or `audit` | +| Query help `.md` or `.qhelp` | same directory and stem as the query | +| Query tests | `/test//CWE-NNN//` with `.qlref`, `.expected` and the fixtures | +| Model rows `.model.yml` | `/ext/manual/.model.yml` | +| Model tests | `/test/security/CWE-NNN//` with a test `.ql` that imports the real flow module | +| Query library `.qll` | `/lib/...` | +| Pack version | not changed: a release sets every version (see the note below the table) | +| Change notes | not applicable, CCP has none | + +**A pull request does not change any pack version** (decision of 2026-11-18: the +maintainer cuts a release when everything is ready to publish). Merging never publishes +or cuts a release: `publish.yml` runs only when `.release.yml` changes, and that happens +through the maintainer-run `update-release.yml` or `update-codeql-version.yml` pull +request. Those run `patch-release-me`, whose `{version}` placeholder expands to any +semver, so it rewrites **every** `qlpack.yml` `version:` to the new release version, +whatever it was (precedent: the Java query pull request bumped `java/src` to 0.8.0, and +the next release pull request set it back to 0.7.6 with every other pack). A bump in a +pull request would therefore only make the pack differ from the rest until then, and a +manual one-off `publish.yml` run would publish the higher number. `check` fails when an +existing `qlpack.yml` version changes. A new pack starts at the repository's current +release version (0.9.0 for the JavaScript, Ruby and C++ ext packs). + +Do not reuse `github/codeql` paths such as `/ql/...`. A `.qlref` points at +the query relative to the `src` pack: `query: security/CWE-NNN/.ql`. + +A shared library of the template pack (a `.qll` outside every query directory, for example +`common/Keys.qll`) is planned with the unit: `plan` follows the `import` lines of the unit's queries +(and of the libraries they import) and `apply` copies each library to `/src/`, so the +imports keep resolving. The plan warns `shared library`; move it to a `/lib` pack only for a +language that has one. + +## 3. Query identity and metadata + +### `@id` + +```text +githubsecuritylab// security-grade +githubsecuritylab/audit// audit-grade +``` + +Example: `githubsecuritylab/java/uncontrolled-file-decompression`. + +| Pack directory | `` in the id | +| -------------- | ------------------ | +| `actions` | `actions` | +| `cpp` | `cpp` | +| `csharp` | `cs` | +| `go` | `go` | +| `java` | `java` | +| `javascript` | `js` | +| `python` | `py` | +| `ruby` | `rb` | +| `rust` | `rust` | +| `swift` | `swift` | + +The language segment follows the stock CodeQL id prefixes. Existing ids in CCP +are mixed (62 of 95 Java queries have a `java/` segment, Python, Ruby and C++ +queries have none, and the CCP audit ids omit the language). The rule applies to +new queries. Do not rename shipped ids: an id is part of a published pack. + +The name describes the weakness. It never carries the gap key, an issue number or +an application name. The id must not clash with any id in CCP. `check` tests this. + +### The rest of the header + +| Tag | Rule | +| ----------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------- | +| `@name`, `@description`, `@kind`, `@problem.severity` | Required. The description says what is reported, not how. | +| `@precision` | The **assessed** precision from the triage, never the value the prototype declared. Never raise it to reach a suite. | +| `@tags` | `security`, `external/cwe/cwe-NNN`, and `experimental` for every item the tracker labels `tags:experimental`. Audit queries add `audit`. | + +## 4. Security-grade or audit-grade, and what a suite does with it + +Decide first. Complete this table before you implement or migrate: + +| Question | Security query | Audit query | +| ---------------------------------------------------------------- | --------------------- | ----------------------- | +| Requires an attacker-controlled source to reach a sensitive sink | Yes | No | +| Acceptable in default suites | Yes | Usually not | +| Precision expectation | High | Explicitly lower | +| Alert framing | "This is exploitable" | "Review this construct" | + +Detection without provable reachability is often a legitimate audit query. Say so +plainly and label it as such rather than lowering the precision of a default security +query. A conclusion that a precise query is impossible is not a conclusion that nothing +can be done: before reporting that CodeQL cannot help, evaluate an audit query against +the audit bar (a warning that asks for review, `@precision very-low`, tag `audit`). A +measurement that disqualifies a security query, such as a candidate sink firing on both +the safe and the unsafe route, is often exactly the intended behavior for an audit +query, because it honestly reports what the database cannot distinguish. + +Then check what the CCP suites will do with the result, because that is what users get. + +| Posture | Placement | Metadata | Selected by | +| -------------- | ----------------------- | ---------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| Security-grade | `src/security/CWE-NNN/` | `@precision` very-high to low | `.qls` | +| Audit-grade | `src/audit/CWE-NNN/` | `@precision very-low`, tag `audit` | `-audit.qls` only (cpp, csharp, go, java, javascript, python and rust have one; actions, ruby and swift do not, and a query of kind `table` or `treemap` is an exploration query that no audit suite selects) | + +**The `experimental` tag does not keep a query out of the default suite.** The +`.qls` suites select by kind and precision (very-high, high, medium, low) +and exclude only the `audit` and `debugging` tags. A medium-precision query +tagged `experimental` is part of `actions.qls`, `java.qls` and the rest from the +moment it ships. `codeql resolve queries --additional-packs /src/suites/.qls` +shows it. If a query must not run by default, make it audit-grade, or raise a separate +suite change, and say which in the packet. Do not assume the tag does it. Audit-grade is for a +query that cannot claim reachability, not for a slow one: a slow security query is handled under +[Performance risk](#performance-risk-and-what-to-do-with-it). + +### What makes a query run + +A merged query runs for nobody until all of these hold. A migration forgot the first two for Actions +and again for Rust, which is why `check` now fails on them. + +| Needed | Where | Checked by | +| -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------- | -------------------------------------------------------------- | +| The queries pack is named in `configs/default.yml` and `configs/synthetics.yml`, and the ext pack in `synthetics.yml` when it has data extensions (`default.yml` and `audit.yml` name the ext packs that were chosen on purpose) | `configs/` | `check`, `community_packs_onboard.py` | +| A suite selects the query: `.qls` for a security query, `-audit.qls` for an audit query and not `.qls`. The audit suite is a new file in the same pull request as the first audit query of the language. | `/src/suites/` | `check` | +| `configs/audit.yml` names `:suites/-audit.qls` | `configs/audit.yml` | `community_packs_onboard.py` | +| A release has published the pack, and every path that a config names in it | the registry | `community_packs_onboard.py --published` | +| The repository's default setup lists the language, and the config's `query-filters` keep the query | the repository, the config | [verify-detection.md](./verify-detection.md), sections 3 and 4 | + +Which lines go in the query pull request and which wait: a config on `main` is read at scan time and resolves +against the **latest published pack**, so a line is safe only when the release already holds what it names. The +pack lines of a pack that is already published (the bare `githubsecuritylab/codeql--queries` and +`-extensions`) are safe and go in the query pull request. **Checked** (2026-11-24): every pack that the configs name, and the +extension packs of cpp, javascript and ruby (which no config names yet), download at `0.9.2`. The `audit.yml` line names a suite that exists only +after the release, and the lines for a pack that was never published wait for its first release too (the configs +README says so). A line that names a path the latest release lacks cannot be resolved by the CLI, so a scan that uses +that config would fail on it (the Action itself was not tried). +**Checked** (2026-11-24): `configs/audit.yml` on `main` named `suites/rust-audit.qls` while the published `0.9.2` +pack had no such file, and `codeql resolve queries githubsecuritylab/codeql-rust-queries:suites/rust-audit.qls` +against that pack failed with `Could not read ...\suites\rust-audit.qls` (a scan that uses the config would resolve +the same way; not tried). `community_packs_onboard.py --published` reported exactly that one line on `main` and no other +(it takes about 3.5 minutes with four downloads at a time). + +```powershell +python scripts/community_packs_onboard.py --ccp [--language ] # report: queries, suites, names, gaps +python scripts/community_packs_onboard.py --ccp --language --apply # what is safe now +python scripts/community_packs_onboard.py --ccp --apply --published --codeql # after a release +``` + +The report lists, for every language, the security, audit and exploration queries, the suites, the pack names and the +gaps, each with `when` it can be fixed (`now` or `after-release`). `--apply` adds the missing pack lines beside the +lines of the same kind in language order, with the comment and the line endings of the file, switches on a commented +out line (`audit.yml` keeps one for Ruby), and creates a missing audit suite in the shape of the others; it never +overwrites a suite. With `--published` the script downloads the latest published pack of every name the configs +mention (each comes with its dependencies, four at a time, so expect minutes), fails on a pack or a path that is not +there, and treats an `audit.yml` line as safe when the release holds +its suite, so `--apply --published` after a release adds exactly those lines. `--after-release` forces the lines +that wait for a release without asking the registry, for the pull request that is itself the release. Themed +configs (`hardcoded-credentials.yml`, `quality.yml`) name queries on purpose: adding a credential query there is a +decision, not a gate. + +**Checked** (2026-11-24, the report on three checkouts of `main`): on the parent of the Actions configs pull request it +listed the Actions pack as missing from `default.yml` and `synthetics.yml` (and the Rust ext pack from +`synthetics.yml`). On the parent of the Rust configs pull request it listed, for Rust and for no other language, the +pack in both configs, the ext pack, `rust-audit.qls`, and the `audit.yml` line as `after-release`. On `main` after +that pull request no language has a gap. Ruby has audit tagged queries but none of a kind that an audit suite +selects (they are `table` and `treemap` explorations), which is why its `audit.yml` line stays commented out. + +## 5. Data extensions by language + +Only `cpp`, `csharp`, `go`, `java`, `javascript`, `python`, `ruby` and `rust` have an +`ext` pack (`EXT_LANGUAGES` in the script). `plan` warns when model rows target any +other language. + +| Language | Options for model rows | +| --------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| `cpp`, `csharp`, `go`, `java`, `javascript`, `python`, `ruby`, `rust` | `/ext/manual/.model.yml`. Keep `extensionTargets` as `'*'`. The test pack must depend on the ext pack. Do not run `codeql pack install` on an ext pack. | +| `swift`, `actions` | Model the API in QL inside the query pack or `lib`, or ask the maintainers to create an ext pack first. This is a maintainer decision, not a worker's. | + +A model-only change has no query to measure, so Gate 2 for it is different +(see [Gate 2 for model-only units](#gate-2-for-model-only-units)). + +## 6. Tests + +- Positive and negative controls for every behavior. A negative control for every + false positive class found in [Gate 2](#7-quality-bar). +- **A positive control has the imports of the real code and nothing more.** The extraction of a crate + that is used through a glob import of its prelude can leave every call into it without a target + (`use iron::prelude::*;` does, in the test harness and in a scan database), and the same file resolves + once the names are also imported explicitly elsewhere in it. A fixture that does both passes while the + real sample finds nothing. For a model or a query that matches the canonical path of a library call, + list the call targets of the fixture (`getStaticTarget().getCanonicalPath()`) once, and copy the + import style of the sample ([verify-detection.md](./verify-detection.md), section 6). When the real code + does not resolve, the fix is a fallback by name, tested as in + [A fallback for calls that have no target](#a-fallback-for-calls-that-have-no-target). +- Neutral identifiers only: no application names, no domain vocabulary from the + synthetic app. Use `--replace OLD=NEW` when you plan and `--deny` when you check. +- Learn `.expected` only after you have read the diff. Never commit an `.actual` + file. A learn run of a query that does not compile can write the error into the `.expected` file instead of + failing (**checked** 2026-11-24: a 67 byte file, `ERROR: 'name' is not bound to a value`), so compile with + `--warnings=error` first, as `check` does, and look at the size and the removed lines of the diff + (`git diff -U0 origin/main -- `: an unchanged fixture must not lose a row). +- Small fixtures. Tests that need stubs use the stubs CI makes available (see + [Tooling](#9-tooling)). + +## 7. Quality bar + +A migrated query is done when all of these hold. + +1. `check` passes. It runs the CCP rules (metadata, help file present, forbidden + constructs, id uniqueness, denied names in every changed file and file name, + no `postprocess:` line) and the same commands CI does: a format check on the + LF content (a Windows checkout may have CRLF), `codeql pack install +--additional-packs /{lib,src,test}`, `codeql query compile +--check-only --warnings=error` over the queries **and the test queries**, the + help renders, `codeql test run --additional-packs `, and for model rows + `codeql pack create` on the ext pack and a test pack that depends on it. It fails + when a lock file already differs before the gates run (the unit must not touch + lock files unless `--allow-lock` names the file), restores any lock file that `codeql pack install` rewrites, and reports which of the language's suites select the + query. It fails a query that the suite for its group does not select (`.qls` for a security + query, `-audit.qls` for an audit query; `--allow-unselected` accepts it) and a language pack that + the configs do not name or an audit query that has no audit suite (`--allow-config-gap NOTE` accepts it, + and the note goes to the packet). The lines that must wait for the release are listed under + `after_release` in the report ([section 4](#what-makes-a-query-run)). It runs with the user CodeQL config hidden (see [Tooling](#9-tooling)). +2. The query meets `CONTRIBUTING.md`: no internal libraries, no `getAQlClass`, no + regexp matching on `toString`, resilient to later library changes. +3. Evidence on a real project, by tier (below). +4. `measure` passes on a public corpus (below). +5. Every result on that corpus has been read and classified. +6. No pack version changed (a release sets them). `check` fails when an existing + `qlpack.yml` version changes. +7. `scan` passes on the committed branch and on the drafted pull request text. + +### Evidence tiers + +The true positive on a real project is the slowest step (it needs a database of +the right project, and building one took 1 to 3 hours in the first batch). Spend +it where it matters. + +| Tier | Units | Evidence required | +| ---- | ------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| 1 | Assessed precision very-high or high | A true positive on a real project, from the shared corpus or one small targeted database (at most 3 repositories, at most 45 minutes of build time). | +| 2 | Medium, low, or audit-grade | The measure on the shared corpus with every row classified. A true positive is welcome. If there is none after that, the packet says "no true positive found in repositories" and the maintainer decides. | + +Never exceed the build budget for a targeted database. Stop and report instead. + +### Gate 2: measure on a real corpus + +A query that passes its tests can still be unusable. The tests run on a +database of three files, where a join over every expression is invisible. On a +real corpus the same join is unbounded. + +The pilot query (an Actions query, 329 public workflow files, about 84,000 +lines) shows it: + +| | Original port | After the fix | +| ------------------ | ------------------------------ | -------------------------------------------------------------- | +| 40 workflow files | 8 min 15 s | 30 s | +| 329 workflow files | did not finish in 20 min, 8 GB | about 2 min, of which the query's own predicates are about 3 s | + +The cause was a predicate with a free variable that the compiler inlined into a +cartesian product of every statement with every expression (6.3 million tuples) +and then ran regular expressions on each row. The fix was to materialize the +small relation first (`pragma[nomagic]`, a predicate of its own). The test +database could not show it. + +```text +measure --spec S --ccp --codeql --db --out +``` + +`measure` runs the query with an evaluator log, then reports the wall time, the +time spent in the query's own predicates (library cost excluded, shown but not +judged), the top predicates, and writes `rows.json` for triage and `measure.json`. +It **passes when the query's own predicates take at most 60 s** (`--budget`) and +the evaluation finishes within `--max-wall` (2 hours, then it is killed). Read the +top predicates even when it passes. + +- **It does not count tuples by default.** Counting changes how the evaluator runs: + one Java corpus took 23 minutes counted and 36 seconds plain. Add + `--tuple-counting` to diagnose a failure, and then a cartesian product of a + million tuples or more in the query's own predicates fails the gate. +- **`--timeout` is per evaluation layer**, not a total limit. `--max-wall` is the + total limit. +- **Own cost** is every predicate with the query's name in it, including data flow + instantiations such as `MakeImpl<...>::DefaultState<::Config>::isSource`. + A data flow query on a very large database can spend most of its own cost in + those instantiations. If it is over budget there, report it and let the + maintainer decide, do not hide it. +- At most 3 heavy evaluations run at once on the machine (`--slots`). `measure` + waits for a slot, so start it early and write the packet while it runs. +- **Measure again after every fix, and copy the new figure into the pull request body.** + Review fixes change the query: the cost line of one published body (about 0.3 s) was + three times lower than the next measurement (about 0.9 s). Run to run variation is real + too (the same query took 1.7, 0.8 and 0.7 s), so say "about" and cite the largest corpus. + Measure on an otherwise idle machine: with a test run and another gate going at the same + time, one query took 1.5 s (and an unchanged one 4.6 s instead of 3.1 s) against 1.0 s alone. +- **A run that evaluated 0 predicates is a cache hit, not a cost.** The CLI keeps results + in the database's cache, and an identical earlier evaluation makes the next one free + (`predicates` is 0 and `own_ms` is 0 in `measure.json`). Quote the figure from a run in + which the query's own predicates were evaluated. + +Corpus rules: + +- One database per language, built once with `community_packs_corpus.py sample` + (a seeded random sample, 25 to 30 public repositories, 300 KB to 10 MB each), + kept outside the repository (`/`) and read only. Workers wait + for `READY` in that directory. A random sample measures cost and the base rate + of false positives. +- Add a targeted database for the construct with + `community_packs_corpus.py targeted --code-search ""` or + `--repo owner/name@sha`. A niche framework is not in a random sample. +- The corpus script uses build mode `none` for Python, JavaScript, Ruby, Java and + C#. Go needs a build, so its corpus is a few small modules built with a manual + command. C/C++ and Swift cannot get a corpus on Windows (see + Tooling). +- Actions databases need the workflow files flattened to `.github/workflows` at + the source root. +- Corpora and results stay local. Never commit them. + +### Performance risk and what to do with it + +The CCP CI runs a query only on test databases of a few files and has no time limit for it, so +`measure` is the only performance check a query ever gets. Nothing after it protects users: the +default suites (`.qls`) run every query they select on every database that uses the pack, +and the `experimental` tag does not exclude a query from them (section 4). The stock CodeQL packs +work differently: their default suites leave out queries under `experimental/` by path +(`code-scanning-selectors.yml`), and an opt-in suite such as `python-security-experimental.qls` +brings them back. The CCP suites have no such exclusion, so a slow query is not contained by being +experimental. The tag does not change that, and neither does the precision. + +`measure` gives every query a **cost class** (`cost_class` and `cost_notes` in `measure.json`, +and the worst class of the unit at the top of the report): + +| Class | When | What to do | +| ---------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------- | +| `low` | The own predicates take at most 10 s, none of them takes more than 5 s, and the whole run, library included, takes at most 10 minutes. | Record the figures. | +| `moderate` | It passes the gate but exceeds one of those three limits. | A bigger database makes it slower: 10 s on a corpus of about 19,000 files is minutes on a large monorepo. Do the scaling check, then decide (below). | +| `high` | It fails the gate: the run did not finish within `--max-wall`, the own predicates contain a cartesian product (visible with `--tuple-counting`), or they take more than `--budget` (60 s). | It does not ship as it is. | + +The class is a floor, not a verdict. Three things raise the risk and are not measured: a language +without a corpus on your platform (C/C++ and Swift, and Go is built by hand), so treat that query +as moderate until someone has measured it; a source or sink that matches by a very common name or +over every call of a database, which is cheap on one corpus and costly on another (a fallback by name that has no +file guard is one, see [A fallback for calls that have no target](#a-fallback-for-calls-that-have-no-target)); and a database +much larger than the corpus. + +**The scaling check.** Measure on two corpora of clearly different size and compare. Own cost that +grows faster than the database, or one predicate that dominates the profile, is the sign of a join +that will not scale. Measure on an idle machine and quote the larger corpus. + +**What to do with a `moderate` or `high` query**, in this order. Stop at the first step that works. + +1. **Fix it.** Most cases are a join the compiler cannot narrow: a free variable that is inlined + into a cartesian product, a regular expression run over every row, a flow configuration whose + source or sink is every call. Materialize the small relation first (`pragma[nomagic]`, a + predicate of its own), bind the variable, restrict the sink by what makes it a sink, and + measure again (add `--tuple-counting` to see the product). +2. **Narrow it.** Make the query ask for less: a specific library or argument instead of every + call, with a negative fixture for what it no longer reports. +3. **Make it audit-grade, only if it is one.** The `audit` tag takes the query out of + `.qls` and puts it in `-audit.qls` (where the language has one), so it stops costing + everyone. It is not a performance flag. Audit means "review this construct" at + `@precision very-low`, with the framing of section 4. A security query that is only slow does + not become an audit query, because that hides a finding from the default run. +4. **Propose a suite change to the maintainers.** For a valuable, expensive security query the + honest options are an exclusion tag with an opt-in suite, or the stock packs' `experimental/` + split. That is a maintainer decision and its own pull request, never an edit to a suite inside + a query pull request. +5. **Do not ship it.** Keep the query in the template repository, or ship only the model rows. + Say which in the packet. + +The packet records, for every query: the cost class and its notes, the figures on both corpora +(wall time, own-predicate time, the top predicate), the suites that select it (`check` reports +them) and the step taken, or "low, nothing to do". A query that `.qls` selects and whose class +is not `low` needs that decision written down before the pull request leaves draft. + +**The release is the real test.** `measure` ran on public corpora, not on the repositories that scan with the pack. +After the release, `scripts/scan_timing.py` compares the code scanning job times of the synthetic repositories before +and after it and, for a pair that got much slower, reads the logs to see whether the new queries, other new queries of +the same release, or something unrelated caused it +([verify-detection.md](./verify-detection.md), section 7). A query that measured `low` should not show up there. One +that does goes back to the steps above. + +### Choose the true positive + +CONTRIBUTING asks for a true positive on a real project. A true positive of a +security query is an unpatched vulnerability or a live leak unless you choose +carefully. In order of preference: a revision where the bug is already fixed (a +published advisory or a later commit), an archived project, a deliberately +vulnerable application, a test repository that exists to show the pattern. Never a +live project with the bug. Keep every permalink in the local packet and let the +maintainer choose what the pull request cites. + +### Triage every row + +Classify each result as true positive, false positive or unclear. + +- For each systematic false positive class, fix the query and add a negative test + that has the same shape as the real case. +- Accept a class only when it cannot be separated cheaply, and then write it under + "Known limitations" in the query help. +- Record the counts (rows, true positives, false positives, classes fixed) in the + packet. + +The pilot found 14 rows. Eight were decode-to-file steps (`base64 --decode -o`, +process substitution). The six others were real leaks (one duplicate). After the +fixes the corpus gives five alerts and every one is a true positive. + +### A fallback for calls that have no target + +When the extraction leaves the calls into a library without a target (the Iron prelude, +[verify-detection.md](./verify-detection.md), section 6), the data extension rows and every sink that is +written as a canonical path stop applying, and the way out is a fallback in the query that recognizes the API +by its names. It is a precision trade, so it follows rules. **Checked** (2026-11-24, `IronResponseXss`, Rust, +CLI 2.27.5, rust-all 0.2.26): + +- **Match only what has no target, and only in files that use the library.** A step or a sink of the fallback + requires `not exists(call.getStaticTarget())` (for a field read, `not exists(field.getStructField())`) and a + file guard (a `use` whose root segment is the crate, or `extern crate`). Resolved code then keeps its + results: the learned `.expected` of the existing fixture gained the rows of the one case that was added and + lost none. With the file guard made true everywhere (a mutation), the query took more than two minutes on the + four file test database instead of 13 s, because the database also holds the dependency sources. +- **A source by the shape of the API.** A parameter whose type is named `Request`, `&Request` or `&mut Request` + is the request of a handler when its file uses the crate. The type cannot be resolved, so the name is all + there is: say so under "Known limitations". It is a source in resolved code too, where it also finds a + handler that nothing registers (a router registers it, for example). +- **Steps over what has no target.** A method call with no target passes its receiver on to its result, except + for the methods that tell a property and no content (`len`, `is_empty`, `contains`, ...) and the methods whose + name says that they encode for HTML (`escape_html`, `html_escape`, `encode_html`). Match the name against that + shape and not against the words `escape` or `encode` anywhere in it: Copilot code review caught that a + substring match also hides `escape_default` (it keeps `<` and `>`) and `unescape_html` (it undoes the + encoding), which locked a false negative into the test. The stock `HeuristicHtmlEncodingBarrier` is broad for + resolved calls, but the fallback has no type to fall back on, so it has to be stricter. A function call is not + a step of the fallback. A fixture whose sanitizer call (`clean(&body)`) has no target gives no alert, because + the analysis does not follow data through a call that it cannot resolve. On the scan database the real + sanitizer (`ammonia::clean`) resolves, and the sample that uses it gives no alert either, because no taint + comes out of its body. The query has no barrier for it. +- **Give the fallback source every sink, resolved ones too.** A fallback source (a parameter by its type) also + reaches sinks that do resolve, and nothing else reports that flow when the handler is not registered, because the + data extension source needs the registration. Add the resolved version of each sink class, or the handler that a + router registers is missed (Copilot code review caught the body on its own). +- **Report one path, and leave a flow to the standard query only when its analysis reaches it.** The modelled + source (the handler that `Iron::new` receives) and the fallback source (its parameter) reach the same sink. + Leave out the fallback path when a modelled source reaches that sink and the fallback node is not itself a + modelled source, or every handler is reported twice (26 rows instead of 17 in the fixture). A resolved sink + that the standard query reports (a registered handler, every call in between resolved) is reported by both + queries unless this one leaves it out (20 rows instead of 19). But a clause that tests the class of the + source ("a modelled source, so the standard query has it") is wrong: a call without a target between the + modelled source and the sink makes the standard analysis miss what this query's extra step finds, and the + clause then removes the only report. Copilot code review found that on the third round, and it reproduced: the + pushed query missed a registered handler whose body went through a call that has no target. The clause has to + test what the standard analysis reaches. **Open** at the time of writing (fix in progress in the Iron pull + request): two facts are checked, the rest is not. The sink of a data extension row is a flow summary node, not + the expression node of the argument (a class that extends the expression node and `Xss::Sink` has no + instance, and `sinkNode(n, ...)` with `n.asExpr()` fails to compile with `TFlowSummaryNode is incompatible +with TExprNode`), so an auxiliary configuration cannot name the argument as its sink. And the standard query + does not live in a library (its configuration is in `XSS.ql`), so a mirror of it has to be written in the + query. +- **Test it as a fallback.** + 1. A fixture file with only the glob import, in a file of its own. The files of a Rust test directory are + modules of one generated library crate and `main.rs` is a binary, so the glob-only file stays apart from the + explicit imports in `main.rs` that would make it resolve. + 2. A premise test that lists the calls of that file that have no target (`GlobCalls.ql`). If the extraction + resolves them some day its expected file changes, and the fixture no longer exercises the fallback. + 3. A file with the same names from another framework and no `use` of the crate, which must give no alert. + 4. The negative cases of the original fixture again, in the glob-only form, a handler that nothing + registers (with a tuple, and with a body on its own to a call that resolves), a sanitizer call, a method + that says that it encodes for HTML, and a method that only looks like it does (`escape_default`), which + alerts. And a registered handler whose value goes through a call that has no target before a resolved + sink: put that call directly on the modelled value (`req.url.path()` and then the call), because taint + stops at a resolved call that has no summary (a fixture with `Vec::join` in between gave no alert in + either query, which looked like the bug and was the fixture). + 5. Mutation checks, each reverted: without the file guard the other framework's file alerts, without the + method step every glob alert goes, without the one-path clause the rows double, without the field guard the + path edges and nodes of the existing rows change, with a substring encoder match the `escape_default` + alert goes, without the resolved body sink the unregistered body-only alert goes, and without the clause + for modelled sources the registered body-only handler is reported twice. The file guard is used by the + source, the steps and the sink, and a flow needs all three, so the mutation makes it hold everywhere: the + fixture cannot show which single use was removed. +- **Check the result on the scan database** ([verify-detection.md](./verify-detection.md), section 6) before the + pull request opens: the original finding is reported, the safe sample is not, and every other new row is read. +- **QL gotchas** (rust-all 0.2.26): `getStaticTarget()` and `getPositionalArgument(i)` are members of `Call`, not + of `CallExpr`, so reach the callee with `call.(CallExpr).getFunction().(PathExpr).getPath()`. + `FieldExpr.getStructField()` tells whether a field resolved. A predicate with a `string` parameter that + its body only tests (a `regexpMatch` on the name) needs `bindingset[name]`, or the query fails with `'name' is +not bound to a value`. `check` forbids importing anything `internal`, so + the type inference predicates are out of reach and these three signals (no target, no field, the file) are what + there is. + +### Gate 2 for model-only units + +There is no query to measure. The evidence is different, and the first model-only +migration (Java summary models for a JSON library) set the bar: + +- **Every row is real.** Each signature resolves against the real library (for + example `javap` on the released jar, and a database built against that jar). + A row that does not resolve is dropped or fixed, never shipped. +- **A test that proves each row.** A custom test `.ql` that imports the real flow + module, one positive expectation per row, negative controls (nothing tainted, + another package with the same class name), known gaps written as `MISSING` + expectations, and a leave-one-out run showing that removing any single row + fails the test. A test that three of thirty-one rows satisfy is not coverage. +- **Before and after on a real project** (a safe example, see above): the stock + query without the rows, then with them. Record the alert counts, check that + every new alert is a true positive and that no alert is lost. +- **Pack checks the CI extensions job runs**: `codeql pack create` on the ext pack, + the test pack depends on the ext pack, no lock file for the ext pack. + `codeql resolve queries /src/suites/.qls` must resolve exactly what + it did before. +- Say in the pull request that the rows apply to every taint tracking query for + users who load the extensions pack. + +## 8. Versions, branches and pull requests + +- Do not change any pack `version:` (see section 2). A release sets every version. + Never hand edit a value a release tool derives as a delta. +- **One branch per unit** (see "Decisions taken"). `plan-all` writes one spec per + unit, `.spec.json` or `..spec.json`. Queries that share a + template directory cannot be told apart by path and stay together (the "several + queries" warning), and a worker may still split them by hand with + `plan --only ` (repeatable, matches a path segment). +- Branch: `/` (for example `actions/encoded-secret-in-log`). +- Title in the repository's style: `Add Actions encoded secret in log query`. +- Open it as a draft. Then wait for automated review, check each comment against + evidence, and reply on every thread, resolving the ones you fixed. + +## Disclosure + +This is the rule that cannot be traded for speed. + +- The public text (commit, branch, pull request, comments, query help, fixtures) + never mentions the template repo, its issues or pull requests, the tracker, any + internal repository, any customer, or the synthetic applications the weakness + was first seen in. The pull request stands on the weakness, the tests and the + real-project evidence. The origin stays in the tracker Action column. +- Replace application identifiers at plan time and deny them at check time. A + renamed fixture that is still recognizable is not neutral. +- Evidence from public repositories can still hurt the people it names. A true + positive is often a live leak. Keep the permalinks in the local packet. Prefer + a repository that shows the pattern on purpose (a test repository or a proof of + concept) or an archived revision, and let the human choose what is cited. Never + paste a secret or a log excerpt. +- Review the complete diff and every outbound string (commit message, trailers, + title, body, links) immediately before any public write. +- If you are not sure a detail is safe, stop and ask. + +## Human gate + +Approval authorizes a write. It does not perform one. Signing may need the human at +the keyboard (a signing agent that asks for approval), so the human approves each +public write, and the session performs it while they are present. The packet is what +makes that quick. + +An `Upstream publication packet` for CCP contains: + +- Destination, branch name and the exact files and test location (no pack version change). +- Change note: not applicable. +- Suite behavior: what `.qls` does with the query, and the decision taken. For a query + whose cost class is not `low`, the decision from + [Performance risk](#performance-risk-and-what-to-do-with-it). +- Configs and suites ([section 4](#what-makes-a-query-run)): the pack lines and the audit suite that + the pull request adds, and the `after_release` lines from `check`, which a follow-up pull request + adds once the release holds them (`community_packs_onboard.py --apply --published`). Say so in + the packet, because nobody else will remember. +- Evidence: corpus, size, wall time, own-predicate time and cost class, row counts, true and + false positive classes, and the permalinks (local only). +- The readiness items from the triage, each marked resolved or accepted. +- The drafted public title and body, checked against [Disclosure](#disclosure). +- A note that local commits may be unsigned and need signing before they are + pushed. +- The commands that publish it, as run for the pilot: sign + (`git commit --amend -S --no-edit`, which may prompt the signing agent), push the + branch to `origin` (a maintainer with push access needs no fork), then + `gh pr create --draft`. The pilot's 27 CI checks, including the language's + `compile-and-test`, ran on the draft pull request and finished in about 3 minutes. + +After the pull request exists, expect Copilot's code review within minutes of the push +and of every later push. The repository ruleset turns it on for every push, drafts +included, which is why `reviewRequests` stays empty and says nothing. Poll +`gh api repos/GitHubSecurityLab/CodeQL-Community-Packs/pulls//reviews` for +`copilot-pull-request-reviewer[bot]` and read **both** its threads (`reviewThreads` in +GraphQL) **and the review body**: findings in code that did not change since the last +round are listed there as "previously missed issues" and get no thread, so checking only +the threads misses them. Triage each finding, prove the real ones with a failing test +first (one statement per fixture step, because alerts are per script), fix them, and +reply once to each thread with the fix and resolve it. For a finding that has no thread, +reply with one pull request comment. Prove that the new negative fixtures can fail by +mutating the query (make the new rule accept everything) and that the new fixtures fail on +the previous query, then say so in the reply. Every behavior that the reply or the body +states needs a fixture of its own: write the sentence first and look for the test that backs +it (a nested tuple that is held in a variable and a helper that wraps another helper were both +described and neither was tested), and remove the clause that a fixture is meant to guard to +see the fixture fail. If the signing agent does not answer (it +needs the maintainer at the machine), a fix can be pushed as a GitHub-verified commit +with the `createCommitOnBranch` GraphQL mutation, after which the local branch is reset +to it. Rounds keep finding small things in a heuristic query, so stop when a review lists +no open issue. The merge itself needs a code-owner review (the ruleset requires it from the +`codeql-community-packs-admin` team) and the required checks. + +## Tracker + +Record the pull request link in the Action column of the tracker with +`python scripts/tracker_action.py set "" --apply`. That column belongs to +the maintainer: the script changes only that cell and leaves every other character of +the comment alone. When a pull request merges or closes, +`python scripts/tracker_action.py refresh --apply` adds its state after each link +(`draft`, `open`, `merged `, `closed `). The issue body has an "Actions recorded" +count (`N of M`) for each language, and `python scripts/tracker_action.py counts --apply` sets it +from the language comments (it leaves a row alone when its M differs from the rows of the +comment, because the body would need to be regenerated). The maintainer's standing rule is one +batch comment on the tracker issue that lists what was created, merged or changed, with +full links. Without `--apply` all three commands print what would change and write nothing. + +## 9. Tooling + +- Pin the CLI to the version in `.codeqlversion` of the CCP checkout. A different + CLI resolves different library versions and makes results incomparable. +- Use short paths and one git worktree per issue (for example + `\`). Windows long paths break pack resolution. +- CI also clones `github/codeql` at the CLI branch (`codeql-cli-`) into + the repository root so tests can use its stubs (C# and Java tests reference + `codeql/csharp/ql/test/resources/stubs` and `codeql/java/ql/test/stubs`). Keep + one sparse clone outside the worktrees and give each worktree a junction + (the path is gitignored): + + ```powershell + $env:GIT_CONFIG_GLOBAL = '' + git clone --depth 1 --filter=blob:none --sparse --branch codeql-cli- https://github.com/github/codeql.git + git -C sparse-checkout set --cone csharp/ql/test/resources/stubs java/ql/test/stubs + cmd /c mklink /J \\codeql # Linux or macOS: ln -s //codeql + ``` + + Add a directory with `git -C sparse-checkout add `. `prepare --stubs ` + makes the junction for you. + +- Warm the pack cache once per language (`codeql pack install` for `lib`, `src` + and `test` in a throwaway worktree) before starting workers. Concurrent first + installs race on the shared cache. +- If git over SSH fails (an unavailable signing or key agent), clone public + repositories over HTTPS with a `GIT_CONFIG_GLOBAL` that has no `insteadOf` + rewrite, and commit local work with `git -c commit.gpgsign=false`. Sign before + anything is pushed. +- `scripts/community_packs_onboard.py` (offline except with `--published`) answers "will this pack's + queries run for anyone?" for one language or all of them, and `check` runs the same logic for the + unit's language. Run it on a fresh `origin/main` after every release too: a pack or an audit suite that + nobody added to the configs shows up there. +- `codeql pack install` rewrites a lock file when the pinned CLI bundles the locked packs (the Rust + libraries of CLI 2.27.5 do), and CI never commits that. `check` restores such files itself and fails only + for a lock file that the unit changed. A unit that changes one on purpose, for example for a new test pack + dependency, declares it with `--allow-lock ` (repeatable): it is not a finding, and the gates put the + file back to its content from before they ran when `pack install` rewrites it. Edit such a lock by hand, + because a local `pack install` writes `dependencies: {}` for packs that the CLI bundles (the Ruby test lock + shows the layout: the stock queries pack and `codeql/suite-helpers` are listed). +- **Rust test directories run one after the other in CI, and a pull request that touches a file other than a + query runs all of them.** The CI test step used to slice by test directory and run the slices in parallel, and + two Rust slices on a fresh runner downloaded the toolchain into the same `~/.rustup` at once (`could not rename +'downloaded' file`), so a Rust pull request could change only one test directory. Pull request 259 made Rust run + a single slice (`num_slices = 1 if language == "rust"` in `.github/workflows/ci.yml`, **checked** 2026-11-24 on + `main` and in the log of a later pull request), so several test directories are fine now. The other half: the step + runs only the tests of the queries that a pull request touches when the pull request changes nothing but `.ql` + files. Any other changed file (a `.qll`, a `.qhelp`, an `.expected`, a fixture) logs `not a leaf .ql file, +compiling everything in rust`, and all the language's tests run: 8 tests in 5 directories took 17 minutes + (against 4 to 9 minutes for a pull request that touched one query), so expect a wait and push fixes in batches. +- **A user level CodeQL config changes results.** `~/.config/codeql/config` with + `--threat-model all` applies to `codeql test run` and + `codeql query run`, so local sources (files, environment, standard input) become + active and results differ from CI. The scripts run every gate with + `CODEQL_CONFIG_FILE` pointing at an empty config file + (created under the temp directory, or `CCP_EMPTY_CONFIG`), which replaces the user config and leaves + the user profile alone. Overriding `USERPROFILE` instead also hides it but + breaks the Python extractor (the `py` launcher then finds no Python), and + `HOME`, `XDG_CONFIG_HOME` and JVM properties do nothing. If you run `codeql` + by hand, set `CODEQL_CONFIG_FILE` the same way. `check` fails when a user + config still applies. By hand, `codeql resolve extensions ` lists a + `threatModelConfiguration` row in `threatModels` exactly when one does. +- Line endings: the CodeQL formatter flags CRLF in `.ql` files and the editor + tool may write CRLF. `check` compares the LF content, as CI sees it. Fix with + `codeql query format --in-place` on every `.ql` and `.qll` you touch. + `apply` keeps the line endings of `qlpack.yml`. +- `apply` drops a `postprocess: utils/test/InlineExpectationsTestQuery.ql` line + from a `.qlref`: the CCP test packs cannot compile it, so the `.expected` file is the + only oracle. Re-learn it and read the diff. `apply` also renames every file that + carries the query name (`.qlref`, `.expected`, `.ext.yml`), applies `--replace` + to file names and every text file in every casing, converts Markdown help to + `.qhelp` for C# and Java, and sets the audit metadata for an audit query. +- **CI compiles the whole language when any non-`.ql` file changes** + (`pr-compile.sh`: any non-`.ql` change in the language runs a strict full + compile). `baseline` runs that compile on `main`. A language that is red there + makes every unit in it red for a reason that is not its own. Read + `\baseline\.json` before you blame a unit. +- The Python test pack does not list `githubsecuritylab/codeql-python-extensions` + as a dependency, so a Python model unit has to add it (`check` says so). +- `codeql test run` deletes the `*.testproj` databases after a pass. Add + `--keep-databases` to query a test database. +- Build modes in CLI 2.27.4: `none` exists only for C#, Java, JavaScript and + TypeScript, Python and Ruby. Go, C/C++ and Swift need `autobuild` or a manual + build command, which is slow on a multi-module tree and needs a toolchain + (a compiler for C/C++, macOS or Linux for Swift). Corpora for those + languages are built from a few small repositories, or on a Linux machine. + Even `none` runs Maven or NuGet restore for Java and C#: 7 repositories took + 99 minutes and 8 took 82. Budget for it, build the shared corpus once, and do + not build a targeted database in a worker unless the tier asks for it. +- A strict warnings mode stops at the first failure. Run a full sweep before you + trust a single report as the whole list. + +```powershell +python scripts/community_packs_migrate.py plan-all --template