# Security model

`cooldown` is a supply-chain control, so it is worth being precise about what it defends, what it doesn't, and the properties that make the defense hold.

## Threat model

The target is the **smash-and-grab window**: a malicious version is published to a registry and is detected and yanked within hours to a few days. A cooldown delays *adoption* until that window has passed, so the community's tooling and reports run before the code reaches your builds.

It is **not a malware scanner** — it never inspects code — and it does not replace the tools that do a different job. It pairs with `govulncheck`, `cargo audit`, and advisory feeds, which catch known vulnerabilities and published advisories rather than not-yet-known malicious releases. The optional [advisory feed](https://romnn.github.io/cooldown/docs/configuration/advisories/) closes the seam between the two: it flags (or fast-tracks) versions that fix a published advisory, but it never turns `check` into a vulnerability gate — a vulnerable pin is those tools' finding, not a cooldown violation.

## The risk surface is the resolved graph

What you declare is not what you ship — the resolved lockfile is. A single `^1.4` pulls in transitive dependencies, and a re-lock can silently advance any of them to a brand-new version. So [`check`](https://romnn.github.io/cooldown/docs/commands/check/) evaluates **direct and transitive** dependencies by default, and a [`floor`](https://romnn.github.io/cooldown/docs/configuration/precedence/) applies to transitives too.

For a too-fresh transitive you genuinely can't act on — one the graph pins, or one you'd rather not block CI on — the gate can be relaxed, but only deliberately:

- `check --transitive allow` — keep it visible but non-fatal.
- `check --transitive hide` — a direct-only gate.

The strict, whole-graph default stays **opt-out, never opt-in**.

## Mutations honor the selected graph gate

For Cargo, `upgrade` and `fix` evaluate resolver changes in an isolated project. If a re-lock leaves
a new too-fresh, non-acknowledged dependency in the graph, the trial rejects that change before
anything becomes visible in the source. The complete accepted manifest-and-lock state is published
under one project-visible recovery record whose exact digest is anchored in cooldown's
owner-private coordination namespace beneath Git's common directory on Unix. Recovery revalidates
the complete expected project state and the exact marker and authority identities immediately
before consuming that evidence. On Unix, a Cargo source mutation that reaches this path without
anchored authority — outside a Git worktree — fails closed, because untrusted bytes cannot authorize
restoration.

The other ecosystems resolve in one of two ways:

- **In a scratch copy:** Yarn (Berry and Classic), Hex, Maven, Gradle and pixi resolve in a scratch copy of the project and write back only the lock, or the POMs for Maven.
- **In place:** the other ecosystems currently run resolver trials in place under the project lease. `cooldown` records the files each trial may change, rolls a rejected trial back only when those files still match the observed resolver output, and stops if independent drift makes restoration unsafe.

These ecosystems do not yet use Cargo's persistent whole-project recovery record.

Cargo selects that same in-place path on platforms where `cooldown` cannot prove the coordination
namespace is private to the current user — Unix ownership bits today, so Windows always. Those runs
keep the rollback guarantees of the in-place path above but have no persistent recovery record, so an
interrupted mutation is repaired by hand rather than by `cooldown recover`. A project that does
carry recovery artifacts still refuses to consume them without authority there: the fallback
removes the ability to publish evidence, never the requirement to authenticate it.

Every mutation that reports success has passed the package manager's verification and the selected cooldown transitive policy:

- **The default whole-graph policy:** leaves the graph gate-clean by construction.
- **`--transitive allow`:** deliberately retains visible fresh transitives.
- **`--transitive hide`:** excludes transitives from the gate.

`cooldown` coordinates access through target-derived lock files, kept in one of two places:

- **Git repositories:** Git's common directory.
- **A non-Git project:** `.cooldown/locks`, including for read commands, so add `.cooldown/` to that project's ignore rules if it is not already ignored. These non-Git lock files coordinate cooperating `cooldown` processes but do not authorize recovery.

Each project lock is held per manifest family (`Cargo.toml`, `package.json`, `pyproject.toml`, …), so tools that rewrite different manifests at one directory never wait on each other, while tools that share one (uv and poetry, the npm family) do.

Every tool installs into the same `node_modules` or `.venv` in a directory, so three operations additionally hold a lock on the directory's build environment:

- a `--build` step
- an upgrade whose native command installs as it pins
- `outdated`'s preview of an adoptable update, which runs that command on a copy

The lock file is named for the directory and the family, so a `cooldown` from before the per-family locks does not see a newer `cooldown`'s locks, nor the reverse. Do not run the two side by side in one repository.

## Cache hardening

Publish times are cached, and the cache is treated as adversarial input:

- A cached publish time may **never move earlier** on refresh — it is a monotonic floor.
- A **backdated** upstream timestamp (a release claiming to be older than what was already recorded) is rejected, not trusted.

This closes the obvious bypass — an attacker backdating a release so it appears to have already cleared the window.

Two flags control how the cache is used at the boundary:

- **`--offline`:** turns every cache miss into `unknown-age` (never a false "ok").
- **`--fresh`:** ignores the cache entirely and re-fetches — the right choice for a CI gate that must not pass on stale data.

The [advisory feed](https://romnn.github.io/cooldown/docs/configuration/advisories/) inverts the rule, because it is a *loosening* input where publish times are a tightening one: stale cached advisory data may still annotate a row, but it never shortens a window — the shorten mode degrades to annotate-only, with a warning. An unreachable feed likewise fails open (the ordinary, stricter window stands) where a registry outage fails closed.

## Escape hatches are explicit and audited

Loosening the policy is always deliberate and always visible:

- Exemptions (`--latest`, `--allow`, config `allow`) are audited — every one shows up in [`cooldown explain`](https://romnn.github.io/cooldown/docs/commands/other/).
- A [`floor`](https://romnn.github.io/cooldown/docs/configuration/precedence/) bounds config-level loosening: it is max-clamped across layers, so a more specific block can't quietly weaken it, and an `allow` can only bypass it when co-declared with it, or through the audited `--allow` flag or `COOLDOWN_ALLOW` variable. `--latest` does not bypass a floor.
- The [advisory security window](https://romnn.github.io/cooldown/docs/configuration/advisories/) is bounded the same way: a `floor` clamps it unless `bypass-floor` is declared in the floor's own layer, so the worst a poisoned feed can do is drop a window to the floor.

There is no silent path to "adopt anything" — every one leaves a trail.

## Reporting a vulnerability

For a security issue in `cooldown` itself, please use GitHub's private vulnerability reporting on the [repository](https://github.com/romnn/cooldown) rather than a public issue.
