# Vulnerability scanning

Coop scans its dependencies and published images for known vulnerabilities. This page covers what runs, where the results go, and how to find which releases a vulnerability affects.

## What runs

| Check                       | When                                              | What it covers                                                                                        | Results                  |
| --------------------------- | ------------------------------------------------- | ----------------------------------------------------------------------------------------------------- | ------------------------ |
| Dependabot alerts           | Continuously                                      | npm dependencies, GitHub Actions                                                                      | Security → Dependabot    |
| Dependabot security updates | When an alert has a fix                           | Opens PRs that bump the vulnerable dependency                                                         | Pull requests            |
| Dependency review           | Every PR                                          | Dependencies the PR adds or changes; fails on high severity                                           | PR check                 |
| Image scan on publish       | Each image published from `main` and each release | OS and npm packages in each published image (linux/amd64)                                             | Code scanning            |
| SBOMs                       | Each release                                      | OS and npm packages in each image (linux/amd64)                                                       | Release assets, registry |
| Nightly scan                | Daily at 06:17 UTC                                | Lockfiles on `main` and at the latest release (OSV-Scanner); `edge` and latest release images (Trivy) | Code scanning            |

Dependabot does not look inside images, so OS packages from base images only show up in the Trivy scan.

## Where results go

Scan results go to [code scanning](https://github.com/roostorg/coop/security/code-scanning), which only people with write access to the repository can see. The workflows don't print findings to their logs or save them as artifacts, because both are public.

Results are grouped into code scanning categories:

- `trivy-<image>-edge`: the latest build of each image from `main`
- `trivy-<image>-release`: each image in a release, under the release's tag (`refs/tags/x.y.z`), and the latest release's images under `main`
- `osv-main` and `osv-release`: the lockfiles on `main` and at the latest release tag, under `main`

A release's scan under its tag records what was known when it was published and is not updated afterwards. The nightly scan refreshes everything under `main` against current vulnerability databases, so a vulnerability disclosed after the latest release or the last `edge` build shows up there within a day. The latest release is the one marked Latest on GitHub.

## Triaging alerts

In **Security → Code scanning**, filter by tool `Trivy` or `osv-scanner`. For each alert:

- **Fix it** by bumping the base image or dependency. The alert closes once no category finds it any more, so an alert that is also in a `-release` category stays open until the fix ships in a release.
- **Dismiss it** with a reason and a comment when it is not reachable or not exploitable. Alerts are matched by vulnerability and file path, so a dismissal carries over to later scans and to every category that finds it, as long as the package stays where it is.
- **Start a security release** when it is reachable and exploitable.

Reachability and exploitability notes go in the dismissal comment or the draft security advisory, never in a public issue or PR.

## SBOMs

Each release has a [CycloneDX](https://cyclonedx.org/) SBOM per image attached as a release asset, named `<image>-x.y.z.cdx.json`. It lists the OS packages, npm packages and Node.js version in the linux/amd64 image and contains no vulnerability data. For `coop-client`, the npm packages are the client's production dependencies, which Vite bundles into its JavaScript; the image carries their SBOM at `/usr/share/sbom/coop-client.cdx.json`. Versions backfilled with a manual workflow run get no release SBOM.

The images in GHCR also carry SPDX SBOM and provenance attestations for both linux/amd64 and linux/arm64:

```bash
docker buildx imagetools inspect ghcr.io/roostorg/coop-server:x.y.z --format '{{json .SBOM}}'
```

## Which releases does a vulnerability affect?

Use exact `x.y.z` tags throughout; `x.y` and `latest` move with each release. Run these locally: their output is a list of vulnerabilities, so don't paste it into public issues, PRs or CI logs.

To find which releases ship a given package, download the release SBOMs and search them:

```bash
for tag in $(gh api --paginate repos/roostorg/coop/releases --jq '.[].tag_name'); do
  gh release download "$tag" --repo roostorg/coop -p '*.cdx.json' -D "sboms/$tag" 2>/dev/null || continue
  for f in "sboms/$tag"/*.cdx.json; do
    jq -r --arg f "$f" '.components[] | select(.name == "undici") | "\($f)\t\(.purl)"' "$f"
  done
done
```

To list everything currently known to affect a release, scan its SBOM with [Trivy](https://trivy.dev/) against today's vulnerability database:

```bash
trivy sbom sboms/x.y.z/coop-server-x.y.z.cdx.json
```

Releases up to 1.2.0 have no SBOMs. Scan their images in GHCR instead:

```bash
trivy image --platform linux/amd64 ghcr.io/roostorg/coop-server:1.2.0
```

To see what the release-day scan found for a release:

```bash
gh api --paginate "repos/roostorg/coop/code-scanning/alerts?tool_name=Trivy&ref=refs/tags/x.y.z" \
  --jq '.[] | [.rule.id, .rule.security_severity_level, .most_recent_instance.location.path] | @tsv'
```

These tell you which releases ship a vulnerable package, not whether Coop is affected. That still takes the triage above.
