fix(proxy): serve escaped npm scopes and unscanned packages

npm and pnpm request scoped packages as @scope%2fname. Fiber's adaptor
answers 404 to an escaped slash, so a route middleware now rewrites the
scope separator before the adaptor runs.

With scanning off, the cache still waited 30 s for a scan result and then
refused the package. A scanner that is off is now treated as absent.

A scan that fails on infrastructure (timeout, network error, upstream 5xx)
no longer blocks the package until its entry expires. The package is
served and the scan is retried every scan_retry_interval. Set
security.fail_closed to refuse such packages.

The OSV api_url default and the docs named the host, which answers 404 to a
query. They now name https://api.osv.dev/v1/query, and a bare host is
completed with the query path.
This commit is contained in:
2026-11-23 00:31:47 +00:00
parent 65b2f23486
commit a313ac1096
17 changed files with 862 additions and 18 deletions
+12
View File
@@ -234,6 +234,7 @@ func (a *App) initializeComponents() error {
DefaultTTL: a.config.Cache.DefaultTTL,
CleanupInterval: cleanupInterval,
MaxPackageSize: a.config.Security.Scanners.Static.MaxPackageSize,
FailClosed: a.config.Security.FailClosed,
})
if err != nil {
return fmt.Errorf("failed to initialize cache: %w", err)
@@ -528,6 +529,12 @@ func (a *App) setupServer() error {
Upstream: npmUpstream,
})
npmProxyWithCDN := a.cdnMiddleware.Handler(http.StripPrefix("/npm", npmProxyHandler))
a.app.Use("/npm", func(c fiber.Ctx) error {
if canonical := npm.CanonicalPath(c.Path()); canonical != c.Path() {
c.Path(canonical)
}
return c.Next()
})
if authEnabled {
a.app.All("/npm/*", mwAuth, adaptor.HTTPHandler(npmProxyWithCDN))
} else {
@@ -673,6 +680,11 @@ func (a *App) Shutdown() error {
a.rescanWorker.Stop()
}
// Cancel pending scan retries before the backends close.
if a.scanManager != nil {
a.scanManager.Stop()
}
// Close analytics engine
a.analyticsEngine.Close() // #nosec G104 -- Cleanup, error not critical