82 Commits
Author SHA1 Message Date
lukaszraczylo 916e2b0aa5 fix(proxy): keep package names that start with the registry name
The app mounts each handler behind http.StripPrefix. The npm and PyPI
handlers trimmed the registry prefix a second time. A request for
npm-run-all reached upstream as -run-all, and the npm package itself
became an empty path. PyPI trimmed /simple without a segment check.
2026-11-24 00:22:49 +00:00
lukaszraczylo 3a7ffab4d5 fix(prewarming): start the worker and cache through the proxy path
The pre-warm worker was never started, and its fetch discarded the
response body, so nothing reached the cache. startWorkers now calls
Start. The worker hands each package to a Fetcher. ProxyFetcher calls
the npm, Go and PyPI handlers in-process, resolves the latest version,
and downloads the artifact. The cache and the scan queue then treat it
like a client request.

Pre-warming stays off unless prewarming.enabled is set. Stop is safe on
a worker that never started, and a second Start does nothing.
2026-11-24 00:19:36 +00:00
lukaszraczylo 22f2a8dfb9 fix(trivy): unpack npm tarballs before scanning
Trivy does not read archives, so a bare npm tarball always scanned clean.
The scanner now extracts the tarball into node_modules/<name> in a temp
dir and runs trivy rootfs on it, so the node-pkg analyzer sees the
package.json. Extraction rejects absolute paths, parent segments and
links that leave the tree, and caps the unpacked size at 512 MiB. The
temp dir is removed after the scan.

PyPI wheels and Go module zips share the archive problem and need their
own extractors. This commit does not change them.
2026-11-24 00:16:07 +00:00
lukaszraczylo fac30f59e6 fix(osv): take the fixed version from the queried package range
An advisory can cover several packages. The fixed version came from the first range, so x/net findings showed the stdlib fix 1.26.9 instead of the x/net fix 0.60.0.
2026-11-23 19:54:33 +00:00
lukaszraczylo 775ed8a4aa fix(govulncheck): count findings in the scanned module only
A module was charged with advisories against its dependencies at the minimum versions in its go.mod. A consuming build resolves its own versions, so these findings do not describe the module. On production golang.org/x/net v0.56.0 carried x/crypto and x/text advisories this way. Stdlib findings describe the scanner toolchain and are also dropped.
2026-11-23 19:54:30 +00:00
lukaszraczylo e6d8ed0f2e fix(scanner): reuse a recent scanner health result
Each /health request ran the version command of every scanner. Under rescan load one round took about 1.4 seconds, which exceeds the client probes that use /health to choose the cache. The result is now reused for 30 seconds. A probe that ends with a cancelled context is not stored.
2026-11-23 19:47:16 +00:00
lukaszraczylo ecf750adbb feat(cache): rescan stale cache hits before serving
With security.rescan_on_access and rescan_interval set, a hit whose scan
result is missing or older than the interval is rescanned before it is
served. Concurrent hits share one scan, and the scan runs under the
manager context so a client disconnect does not abort it. The wait is
bounded by scan_wait_timeout. On a timeout the previous result decides,
or the first-download rule applies when none exists.
2026-11-23 19:27:49 +00:00
lukaszraczylo 41f8369c43 feat(rescan): limit rescans to active packages and run them in parallel
security.rescan_active_window skips packages not requested within the
window. security.rescan_concurrency runs a bounded pool of scans per
cycle. The cycle summary reports skips by reason. Both options default
to the previous behaviour.
2026-11-23 19:26:10 +00:00
lukaszraczylo d6044cdd2e fix(rescan): skip Go .mod and .info rows in the rescan worker
The worker kept its own list of metadata versions and scanned Go module
metadata rows that the serve path never scans. It now uses
metadata.IsMetadataEntry like the cache layer.
2026-11-23 19:25:28 +00:00
lukaszraczylo 3d6bda3a5f fix(pip-audit): audit the release from a pinned requirement
pip-audit takes a project directory as its positional argument and has
no --pyproject option, so every wheel and sdist scan failed. The scanner
now audits name==version from a requirements file with --no-deps and
--disable-pip.

It reads stdout only, lists each advisory once, and treats a skip_reason
as an error because pip-audit exits 0 for a package it could not audit.
2026-11-23 18:07:27 +00:00
lukaszraczylo e37c797602 fix(govulncheck): scan the module as a dependency and read the stream
govulncheck prints indented JSON objects. The line parser read none of
them, so every module read clean.

govulncheck also never reports advisories against the main module of the
tree it scans. A scan of the x/text 0.3.5 source found nothing. The
module is now a dependency of a wrapper module that imports its
packages, and the scan runs at module level.
2026-11-23 18:07:21 +00:00
lukaszraczylo 157814cf08 fix(npm-audit): audit the package through a wrapper project
npm 11 prints via as an array and metadata.dependencies as an object, so
the parser failed on every report. It now reads both shapes of via and
lists each advisory once.

The lockfile step resolved devDependencies, which took 28 seconds for
dayjs and reported 142 findings in its development tree. The tarball is
now the only dependency of a wrapper project, audited with --omit=dev.
This also audits the package itself, which npm audit skips for a root.
2026-11-23 18:07:00 +00:00
lukaszraczylo 65aa2e25dc fix(grype): parse file sources and scan packages by purl
grype 0.121 prints source.target as a string for file, directory and
purl sources. The parser expected an object and failed every scan.

A bare npm, PyPI or Go archive holds nothing grype can catalog, so a
scan of the archive read minimist 0.0.8 as clean. The scanner now passes
a purl for these registries and falls back to the file for others.
2026-11-23 18:06:57 +00:00
lukaszraczylo 3731ca05ce fix(scanner): leave failed scanner results out of the merge
A scanner that returns a result with status error now counts as a failed
scanner, like one that returns an error. Its result no longer joins the
merge, and the manager counts it as an infrastructure failure or another
failure by its cause.

The merged status is error only when every applicable scanner failed.
The fail_closed setting then decides that case as before. One scanner
failing while another returns clean now reads clean.
2026-11-23 18:06:54 +00:00
lukaszraczylo 16fb52ed3e feat(config): make the first-download scan wait configurable
The cache waited a fixed 30 seconds for a first download's scan, and the app never set the wait. Scanners run one after another, so a deployment with several scanners and fail_closed refused most first downloads. security.scan_wait_timeout now sets the wait; 0 keeps 30 seconds.
2026-11-23 17:37:45 +00:00
lukaszraczylo 378b8731fc fix(app): start the rescan worker
The app created the rescan worker when security.rescan_interval was set but never started it; only Shutdown called Stop. A scan lost to a restart therefore left its package unscanned for good, and old results were never refreshed with new CVEs. startWorkers now starts the worker. The ledger records it as GH-24.
2026-11-23 17:24:55 +00:00
lukaszraczylo 501bf1aec8 fix(pypi): serve pip's PEP 658 metadata requests
pip builds the PEP 658 URL by appending .metadata to the whole link, so the suffix lands on original_url, not the path. The filename binding from GH-01 then rejected the request with 400, and every pip install through the proxy failed. The handler now treats that form as the requested wheel's sidecar and streams it without storing it. A sidecar of another file is still refused. The Lean model and the ledger cover the new form (GH-23).
2026-11-23 17:08:20 +00:00
lukaszraczylo f4cf96e1e8 fix(api): resolve Go module paths to cache keys for vulnerability details
The dashboard links Go packages by module path, but Go rows are stored under cache keys (module/@v/version.zip, .mod, .info). The vulnerability details lookup used the module path, so every Go details page returned 404 "package not found". The handler now falls back to the .zip key, then .mod and .info.
2026-11-23 15:49:33 +00:00
lukaszraczylo b98e761c90 fix(stats): count a package under every severity it holds
The trend snapshot counted each vulnerable package once, under its
highest severity. The Vulnerable packages tiles and the severity
filter count a package under every severity its latest scan holds.
The two views disagreed, for example low 0 against 8 packages.

The snapshot and the backfill now use the filter definition, so a
package with high and low findings counts under both. A test compares
the snapshot with the filter result on one fixture.
2026-11-23 15:12:12 +00:00
lukaszraczylo a457e3d2e8 test(metadata): stop the aggregation worker before counting statements 2026-11-23 14:58:44 +00:00
lukaszraczylo ba8bc392ec feat(cache): purge soft-deleted package rows after a retention period
The cleanup worker now hard-deletes package rows whose deleted_at is
older than cache.deleted_retention. The default is 30 days. A value of
0 keeps the rows. The purge runs in bounded batches, with at most 100
batches per cleanup pass, and removes child rows with the package.

History tables have no foreign key to packages, and stats_snapshots
holds its own counts, so the purge leaves both untouched. The cleanup
log line now reports purged_deleted and deleted_retention.
2026-11-23 14:55:26 +00:00
lukaszraczylo 1512230ab3 feat(stats): record daily snapshots and serve a trend API
The aggregation worker now writes one row per UTC day to
stats_snapshots. The row holds package count, total size, vulnerable
package count, the four severity counts and the blocked count. The
write is an idempotent upsert per day.

A migration backfills package counts from cached_at and deleted_at as
the number of packages alive at the end of each day. Vulnerability
fields backfill from scan_results timestamps and stay empty before the
first scan. GET /api/stats/trend returns daily points for 30day, 90day
or 1year with a constant number of queries.

The Stats page shows a chart of cached and vulnerable packages with a
period selector and severity toggles. The Dashboard shows a compact
version. The Lean model gains theorems for the backfill and upsert.
2026-11-23 14:55:19 +00:00
lukaszraczylo bd9d686383 feat(vulnerable): filter vulnerable packages by severity
The four severity tiles on the vulnerable packages page are now toggle
buttons with aria-pressed. Each tile shows "Filter on" while active.
A tile selects packages with at least one vulnerability of that
severity. Several tiles combine with OR. A second click clears the
tile, and a Clear filters control clears all of them.

The selection lives in the URL (?severity=critical,high), so it
survives a reload and works as a link. An empty result shows the
library empty state with a clear action.

GET /api/packages accepts a severity list. The page uses it to load
only vulnerable packages instead of the whole cache. The filter is a
subquery on the latest scan result, so the statement count does not
grow with the number of rows. An unknown severity returns 400.
2026-11-23 14:54:44 +00:00
lukaszraczylo 4d31e535ff test(app): pace broadcast bursts to remove a race flake 2026-11-23 14:31:49 +00:00
lukaszraczylo fe2d9f8b3a fix(metadata): wait for the aggregation worker before closing the store 2026-11-23 14:26:35 +00:00
lukaszraczylo a84f080b79 fix(scanner): rescan packages on remote storage via ScanFile 2026-11-23 14:26:35 +00:00
lukaszraczylo 9b4659218c feat(cache): wire cache.ttl_overrides to metadata freshness 2026-11-23 14:26:29 +00:00
lukaszraczylo 1256756057 fix(api): drop dead per-handler CORS headers 2026-11-23 14:26:17 +00:00
lukaszraczylo 262771d224 fix(api): return 404 when deleting a package that does not exist 2026-11-23 14:26:09 +00:00
lukaszraczylo 536f35ab55 fix(server): stop 431 on /api for browsers with large session cookies 2026-11-23 14:14:28 +00:00
lukaszraczylo f2049383cb fix(api): restrict CORS to allowed origins, refuse cross-origin writes 2026-11-23 13:38:38 +00:00
lukaszraczylo 549d56e0a1 fix(cache): default metadata freshness to 24h, under the age gate 2026-11-23 13:38:37 +00:00
lukaszraczylo 31db940014 fix(scanner): re-read the blob when a scan retry finds its file gone 2026-11-23 13:38:37 +00:00
lukaszraczylo f46e079cee fix(stats): upsert hourly and daily stats on SQLite as PostgreSQL does 2026-11-23 13:38:37 +00:00
lukaszraczylo ae5167ffa9 fix(auth): look up API keys by id, one bcrypt compare per request 2026-11-23 13:38:37 +00:00
lukaszraczylo 787c757827 fix(network): vet every redirect hop against the upstream allowlist 2026-11-23 13:38:36 +00:00
lukaszraczylo db5ca2539f perf(api): serve package lists and stats in constant queries
The dashboard waited seconds for /api/packages and /api/stats. Both
handlers ran queries per package, so the cost grew with the cache.

Baseline, measured live through a port-forward (median of 5):
- /api/packages: 3033 ms, 594 items, limit ignored
- /api/packages?limit=50&offset=0: 2813 ms
- /api/stats: 3813 ms
- /api/stats/timeseries?period=1day: 12 ms

Baseline queries per request, counted on SQLite with 20 and 120 rows:
- /api/packages: 141 and 841 queries (7 per package)
- /api/stats: 103 and 603 queries (5 per package)

Both handlers now run a constant number of queries: 4 for the full list,
6 for a page, 6 for stats. The query-count tests fail on the old code.

- /api/packages pages (registry, name) groups with page, page_size,
  registry, q, sort and order, and returns total_groups. Without page
  and page_size it returns every package, so old clients keep working.
- A batched scan lookup replaces the per-package GetScanResult and
  CheckVulnerabilities calls. ScanDecisions returns the same verdicts as
  CheckVulnerabilities, proven by a policy and bypass matrix test.
- The silent 1000-row cap is gone from the list and the Go delete.
- /api/stats sums per registry with GROUP BY and judges blocked
  packages in one batch.
- Migration 202611240001 adds scan_results (package_id, scanned_at) on
  SQLite, PostgreSQL and MySQL. The existing (registry_id, name, version)
  index already serves the group lookups.
2026-11-23 13:26:50 +00:00
lukaszraczylo 3143de3a3f fix(scanner): scan PyPI artifacts by release version, not file name
PyPI artifacts are cached under their file name, and the scanners received that name as the version. OSV parsed it as a version below every range, so it missed vulnerabilities that affect the real release (for requests 2.19.0, PYSEC-2023-74 and GHSA-j8r2-6x86-q33q) and reported others that do not. Scanners now receive the release version stored on the package row. The saved result stays keyed by the cache version.
2026-11-23 13:15:34 +00:00
lukaszraczylo f0b37ea719 fix(cache): scan npm and PyPI packages named like Go metadata
IsMetadataEntry treated any name ending in .mod or .info as metadata. An npm or PyPI package with such a name skipped the vulnerability scan and was never blocked. The suffix rule now applies to the go registry only.
2026-11-23 13:15:34 +00:00
lukaszraczylo 7192e4ff3e fix(stats): keep downloads that a daily rollup has not counted yet
The time series let a day's rollup replace the hourly rows and events for that day. A download aggregated after the rollup ran vanished from the chart until the next pass. The chart now takes the larger of the two figures.
2026-11-23 13:15:34 +00:00
lukaszraczylo ad4e848e2b fix(stats): roll up every completed day still held hourly
The daily pass rolled up only yesterday, once a day at hour 0. A pass that ran before its last hour was aggregated, or that a restart skipped, left that day short or empty, and the hourly rows were deleted after seven days. Each pass now recomputes the six completed days before today.
2026-11-23 13:15:33 +00:00
lukaszraczylo 990a1d3409 fix(cache): retry once when a purge removes the blob during a hit
Get probed the blob in getOrFetch and opened it again after the singleflight. A purge between the two returned a storage error to the client. Get now resolves the entry a second time, which sees the miss and fetches again.
2026-11-23 13:15:33 +00:00
lukaszraczylo 440279aa50 fix(cache): stop LRU eviction spinning and failing overlapping stores
evict re-listed the same 100 rows forever when every delete failed, and an
overlapping store received a quota error because a flag rejected the second
eviction. Eviction now returns when a pass deletes nothing, and a second
caller waits for the running eviction.
2026-11-23 13:15:33 +00:00
lukaszraczylo 1f31256769 fix(storage): release replaced bytes when a key is overwritten
Put added the new size to the usage counter without subtracting the file it
replaced. Each overwrite inflated usage until restart and could trip the
quota on a cache that was not full.
2026-11-23 13:15:33 +00:00
lukaszraczylo 4713524778 fix(scanner): honour CVE bypasses under block_on_severity LOW
The LOW policy counted every vulnerability, including bypassed ones, so an
active bypass never unblocked a package. It now counts only the remaining
vulnerabilities.
2026-11-23 13:15:33 +00:00
lukaszraczylo 5c9f7e6af3 fix(pypi): bind original_url to the requested file name
The cache key is built from the request path, but the upstream fetch used
the original_url query value. Any file on an allowed host could be stored
under another package's key. The handler now rejects an original_url whose
file name differs from the requested file.
2026-11-23 13:15:32 +00:00
lukaszraczylo 6f604367da fix(websocket): start the event loop and throttle drop warnings
The app built the websocket server but never called Start, so nothing read the 256-slot broadcast channel. After the first 256 events every event was dropped with a warning, and dashboard clients blocked forever on the unbuffered register channel, leaking a goroutine per connection and never receiving events. Run now starts the loop with the other workers. Dropped events are counted in gohoarder_websocket_events_dropped_total and warned about at most once a minute.
2026-11-23 12:56:32 +00:00
lukaszraczylo d6edd40d79 feat(cache): evict items idle past cache.idle_ttl
Every cached item got a 7-day expiry at store time. A popular tarball
left the cache seven days after it was cached, however often clients
requested it.

Artifacts now get no age-based expiry. Cleanup removes any item whose
last_accessed is older than cache.idle_ttl (default 168h, 0 disables).
It reads the items in bounded batches of 500 through the indexed
last_accessed column and deletes them through deletePackage. Metadata
entries keep the freshness expiry from default_ttl.

Startup and each cleanup run clear the expiry that earlier versions set
on artifact rows. Cleanup records the idle and ttl eviction reasons and
logs the count and bytes freed. The stats API reports idle_ttl in
seconds. Package deletes are soft deletes and no history table has a
foreign key to packages, so download history stays intact.
2026-11-23 12:49:47 +00:00
lukaszraczylo 5420480ef8 fix(metadata): keep created_at on CVE bypass edit; repair MySQL suite 2026-11-23 03:18:42 +00:00
lukaszraczylo bde9eebf3d fix(ui): show the PyPI release version in every version display 2026-11-23 03:18:42 +00:00