From 378b8731fcb0fea4a0373554fe56d2db6ec63fa2 Mon Sep 17 00:00:00 2001 From: Lukasz Raczylo Date: Mon, 23 Nov 2026 17:24:55 +0000 Subject: [PATCH] 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. --- lean4/FINDINGS.md | 1 + pkg/app/app.go | 5 ++++ pkg/app/rescan_worker_test.go | 56 +++++++++++++++++++++++++++++++++++ 3 files changed, 62 insertions(+) create mode 100644 pkg/app/rescan_worker_test.go diff --git a/lean4/FINDINGS.md b/lean4/FINDINGS.md index 5cc7b86..7459183 100644 --- a/lean4/FINDINGS.md +++ b/lean4/FINDINGS.md @@ -28,6 +28,7 @@ Currency: `sh lean4/scripts/check_currency.sh origin/main`. | GH-21 | scan retry | a scan retry on S3 or SMB storage reads the stored blob instead of a removed temp file | correctness | low (file-based scanners on remote storage) | `Security.old_remote_retry_unreadable`, `fixed_retry_always_readable` / `TestScanRetryOnRemoteStorageReadsBlobAgain` | 31db940 | | GH-22 | dashboard API | an OIDC-logged-in browser can call `/api` with a long URL; the proxy hop neither forwards session cookies nor exceeds the read buffer | availability | medium (every `/api` call returned 431 for OIDC users) | not modelled (header size, no decision logic) / `TestLargeRequestHeadersAreAccepted`, `TestReadBufferSizeIsConfigurable`, `scripts/check_frontend_cookie_strip.sh` | 536f35a | | GH-23 | PyPI sidecar | pip's PEP 658 request (`.metadata`, suffix on `original_url`) is served as its wheel's sidecar; another file's sidecar is still refused | correctness (pip install failed with 400) | medium (every pip install through the proxy) | `Access.pip_form_keeps_key_binding`, `pip_sidecar_of_other_file_rejected`, `pip_sidecar_of_same_file_accepted` / `TestPipSidecarFormIsStreamed`, `TestHandlePackageFile_OriginalURLFilenameBound` | 501bf1a | +| GH-24 | rescan | with `security.rescan_interval` set, artifacts whose scan never completed are scanned and old results refreshed | correctness (scans lost to a restart stayed unscanned; new CVEs never picked up) | medium | not modelled (worker wiring) / `TestWorkersStartTheRescanWorker` | this change | ### Exploit paths and reach diff --git a/pkg/app/app.go b/pkg/app/app.go index 17d553f..928e0c1 100644 --- a/pkg/app/app.go +++ b/pkg/app/app.go @@ -617,6 +617,11 @@ func (a *App) startWorkers(ctx context.Context) { // Start periodic stats broadcaster (every 30s) so connected WS clients // see live counter updates without polling. go a.startStatsBroadcaster(ctx) + + // Re-scans artifacts whose scan was lost to a restart and refreshes old results. + if a.rescanWorker != nil { + go a.rescanWorker.Start(ctx) + } } func (a *App) Run() error { diff --git a/pkg/app/rescan_worker_test.go b/pkg/app/rescan_worker_test.go new file mode 100644 index 0000000..744df40 --- /dev/null +++ b/pkg/app/rescan_worker_test.go @@ -0,0 +1,56 @@ +package app + +import ( + "context" + "net/http" + "net/http/httptest" + "strings" + "testing" + "time" + + "github.com/lukaszraczylo/gohoarder/pkg/config" + "github.com/lukaszraczylo/gohoarder/pkg/metadata" +) + +// A cached artifact whose scan never completed (lost to a restart) is scanned once the +// workers start, when security.rescan_interval is set. +func TestWorkersStartTheRescanWorker(t *testing.T) { + osv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { + w.Header().Set("Content-Type", "application/json") + _, _ = w.Write([]byte(`{"vulns":[]}`)) + })) + defer osv.Close() + + a := newTestApp(t, func(c *config.Config) { + c.Security.Enabled = true + c.Security.RescanInterval = time.Hour + c.Security.Scanners.OSV.Enabled = true + c.Security.Scanners.OSV.APIURL = osv.URL + }) + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() + + const key = "npm/left-pad/1.3.0" + if err := a.storage.Put(ctx, key, strings.NewReader("tarball"), nil); err != nil { + t.Fatalf("storage.Put: %v", err) + } + now := time.Now() + err := a.metadata.SavePackage(ctx, &metadata.Package{ + Registry: "npm", Name: "left-pad", Version: "1.3.0", StorageKey: key, + Size: 7, CachedAt: now, LastAccessed: now, + }) + if err != nil { + t.Fatalf("SavePackage: %v", err) + } + + a.startWorkers(ctx) + + deadline := time.Now().Add(20 * time.Second) + for time.Now().Before(deadline) { + if _, err := a.metadata.GetScanResult(ctx, "npm", "left-pad", "1.3.0"); err == nil { + return + } + time.Sleep(50 * time.Millisecond) + } + t.Fatal("no scan result after the workers started; the rescan worker never ran") +}