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
+46
View File
@@ -0,0 +1,46 @@
// Package scanerr classifies scanner failures so callers can tell an
// unavailable scanner from a scan that found the package unsafe.
package scanerr
import (
"context"
"errors"
"fmt"
"net"
"net/http"
)
// ErrInfrastructure marks a failure of the scanning machinery (timeout,
// unreachable service) as opposed to a verdict on the package.
var ErrInfrastructure = errors.New("scanner infrastructure failure")
// StatusError is an HTTP status returned by a scanner's backing service.
type StatusError struct {
Service string
Body string
Code int
}
func (e *StatusError) Error() string {
return fmt.Sprintf("%s returned status %d: %s", e.Service, e.Code, e.Body)
}
// IsInfrastructure reports whether err means the scanner could not run
// (timeout, network failure, upstream 5xx or rate limit).
func IsInfrastructure(err error) bool {
if err == nil {
return false
}
if errors.Is(err, ErrInfrastructure) || errors.Is(err, context.DeadlineExceeded) || errors.Is(err, context.Canceled) {
return true
}
var netErr net.Error
if errors.As(err, &netErr) {
return true
}
var statusErr *StatusError
if errors.As(err, &statusErr) {
return statusErr.Code >= http.StatusInternalServerError || statusErr.Code == http.StatusTooManyRequests
}
return false
}