freshgate
v0.1.0
Published
Block dependencies published too recently - a cooldown gate against hijacked npm releases.
Maintainers
Readme
freshgate
Block dependencies that were published too recently. A cooldown gate against hijacked npm releases.
$ npx freshgate
freshgate · package-lock.json · cooldown 3 days · 412 packages checked
✖ 1 package published less than 3 days ago:
@types/[email protected] direct published 1.2 days ago
→ older version: @types/[email protected]Why
Most npm supply-chain attacks (event-stream, ua-parser-js, the Shai-Hulud worm) follow the same pattern: an attacker publishes a malicious version, and it is detected and removed within hours or days. Projects that install it in that window get hit.
A cooldown closes that window: don't install any version until it has been public for a few days. pnpm has this built in (minimumReleaseAge). freshgate brings it to every project: npm, pnpm, yarn and bun, in CI or locally, with zero runtime dependencies.
Install
npx freshgate # run once
npm i -D freshgate # or add to your projectRequires Node.js 20+.
Usage
npx freshgate # check lockfile, 3-day cooldown
npx freshgate --days 7 # stricter cooldown
npx freshgate --allow "@myorg/*" # trust your own packages
npx freshgate --direct-only # only dependencies in package.json
npx freshgate --format github # GitHub Actions annotations
npx freshgate --warn # report only, never failOptions
| Flag | Config key | Default | Description |
|---|---|---|---|
| --days <n> | minAgeDays | 3 | Minimum age a version must have |
| --allow <pattern> | allow | [] | Exempt packages. Globs supported (@myorg/*). Repeatable or comma-separated |
| --direct-only | directOnly | false | Check only dependencies listed in package.json |
| --lockfile <path> | lockfile | auto-detect | Lockfile to check |
| --registry <url> | registry | from .npmrc | Registry URL |
| --format <type> | format | pretty | pretty, json or github |
| --warn | warnOnly | false | Report violations but exit 0 |
| --no-cache | — | cache on | Skip the on-disk publish-time cache |
| --cwd <dir> | — | . | Project directory |
Config file
Put options in freshgate.config.json:
{
"minAgeDays": 7,
"allow": ["@myorg/*", "typescript"]
}or in package.json:
{
"freshgate": { "minAgeDays": 7 }
}Command-line flags override the config.
Exit codes
| Code | Meaning |
|---|---|
| 0 | All packages pass (or --warn) |
| 1 | At least one package is newer than the cooldown |
| 2 | Error (no lockfile, bad option) |
CI
GitHub Actions
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 22
- run: npx freshgate --format githubViolations show up as annotations on the pull request.
Before installing
{
"scripts": {
"preinstall": "npx freshgate"
}
}Note: preinstall checks the existing lockfile. To catch new versions introduced by an update, run freshgate after npm install and before you commit the lockfile, or in CI.
Supported lockfiles
| Package manager | File | Versions |
|---|---|---|
| npm | package-lock.json, npm-shrinkwrap.json | lockfile v1, v2, v3 |
| pnpm | pnpm-lock.yaml | v5, v6, v9 |
| yarn | yarn.lock | classic (v1) and berry (v2+) |
| bun | bun.lock | text format |
Git, file, link and workspace dependencies are skipped. They have no registry publish date.
Private registries
freshgate reads ~/.npmrc and the project .npmrc, including scoped registries (@myorg:registry=...), _authToken entries and ${ENV_VAR} expansion. npm_config_registry is respected.
Programmatic API
import { checkFreshness, formatReport } from "freshgate";
const report = await checkFreshness({
cwd: process.cwd(),
minAgeDays: 7,
allow: ["@myorg/*"],
});
for (const v of report.violations) {
console.log(`${v.name}@${v.version} is ${v.ageDays.toFixed(1)} days old. Try ${v.suggestion}`);
}
console.log(formatReport(report, "pretty"));checkFreshness(options): Promise<Report>
| Option | Type | Default |
|---|---|---|
| cwd | string | process.cwd() |
| minAgeDays | number | 3 |
| allow | string[] | [] |
| directOnly | boolean | false |
| lockfile | string | auto-detect |
| registry | string | from .npmrc |
| cache | boolean | true |
| cacheFile | string | ~/.cache/freshgate/publish-times.json |
| concurrency | number | 8 |
Report contains checked, allowed, violations (name, version, direct, publishedAt, ageDays, suggestion) and skipped (packages that could not be verified, with a reason).
How it works
- Reads every package and version from your lockfile.
- Fetches each package's publish times from the registry (one request per package, 8 in parallel).
- Flags versions published within the cooldown window and suggests the newest version in the same major that passes.
- Caches publish times on disk. They never change, so repeat runs are fast.
Packages that can't be verified (not found, network error) are listed separately. They are never silently counted as passing.
License
MIT
