## Problem
Dependabot security fixes merged to `main` are never backported. None of
the 388 Dependabot PRs since #24484 got the `backport` label. Three
defects cause this:
1. `fetch-metadata` reads only the oldest 100 of the repo's 596 alerts,
so `alert-state` is always empty.
2. It compares versions in a format that doesn't match the alert data
(`= v0.4.0` for Go).
3. `dependabot.yaml` enables auto-merge with `GITHUB_TOKEN`, and a merge
made with that token starts no workflows. Even a labeled PR wouldn't
reach `backport.yaml`.
The label step also runs in a Dependabot `pull_request` run, which can't
use the `main` environment or a KMS App token (the signing pool requires
a protected ref). `pull_request_target` is not an option because it is
being removed before 2026-12-02.
## Fix
- `backport.yaml`, `detect` job: also run for merged Dependabot PRs that
aren't labeled yet. Get the backporter App token (environment `main`,
same KMS key as the `backport` job) and run
`.github/scripts/dependabot-alert-match.sh`. If the PR fixed an alert,
add `backport` with the App token. That `labeled` event runs the normal
backport. The script runs from the base branch and never checks out PR
code.
- `dependabot-alert-match.sh`: matches the PR's updated dependencies
against open or fixed alerts by package, by manifest among the PR's
changed files, and by the update crossing the alert's first patched
version (old < patched <= new). Paginates, and normalizes a leading `v`.
- `dependabot.yaml`: remove `fetch-metadata`, the label step that never
ran, and auto-merge. The job now only sends the Slack notice. **A person
now merges Dependabot PRs**, as they already approve them since #32303.
## Verification
- `bash .github/scripts/dependabot-alert-match.test.sh` passes.
- Replaying the script against the last 120 merged Dependabot PRs
matches 12. That includes dompurify #31213, next #31217, storybook
#31215 and #31216, axios #30239, and moby/sys/user #30534. It doesn't
match grpc #31954 or cel-go #31959, whose alerts were fixed earlier.
## Before merging
The App needs the "Dependabot alerts: read" permission first (ENT-263,
coder/github-org-terraform manifest PR). Until then the token step fails
for unlabeled Dependabot PRs. Runs for manually labeled PRs are
unaffected.
Known limits: a prerelease version compares by `sort -V`, and a grouped
PR's alerts are matched per dependency.
Tracked in ENT-245. Not in this PR: the audit of past fixes (ENT-270)
and a fallback for lockfile conflicts (ENT-271).
---------
Co-authored-by: Lisa Fiander <lisa@coder.com>