Documentation
¶
Overview ¶
Package api implements the scanner's HTTP API: POST /v1/scans submits a target, GET /v1/scans/{id} polls its result, and /healthz, /readyz serve standard liveness/readiness checks. It is net/http only - no router dependency, using the method+wildcard patterns net/http.ServeMux has supported since Go 1.22.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Options ¶
type Options struct {
Policy policy.Policy
MaxBodyBytes int64
MaxConcurrentScans int
MaxInFlight int
ScanTimeout time.Duration
// ScanOptions is the base scanner.Options built from the server's configuration file
// (app.ScanOptions(cfg)) - analyzers, timeouts, and per-analyzer settings. handleSubmit copies it,
// applies request analyzers and blocking severity, then sets the policy baseline and resolved
// source root.
ScanOptions scanner.Options
// AllowedTargetKinds restricts what POST /v1/scans will accept.
// Defaults to remote only - anything that starts a process or reads a
// local path is opt-in per deployment.
AllowedTargetKinds []model.TargetKind
// TokenEnv names the environment variable holding the bearer token required on every request
// except /healthz and /readyz. Empty means no token; NewServer accepts that only when no
// sensitive target kind is enabled. The secret is read once during construction.
TokenEnv string
// BaseDir bounds a submitted source/static-target path: it is resolved
// against BaseDir with filepath.EvalSymlinks and a containment check.
// For TargetSource, Options.Root for the scan is set from the result;
// for TargetStatic, Target.Path is. Required whenever TargetSource or
// TargetStatic is in AllowedTargetKinds.
BaseDir string
// AllowedHosts are the host names (without a port) the Host header of a /v1 request may
// carry. A web page can reach a listener on loopback through DNS rebinding, and the request
// then carries the page's own host name; only the names listed here are served. Empty means
// no Host check: mcp-scanner-api fills it for a listener on a named or loopback address.
AllowedHosts []string
// AllowedOrigins are the browser origins (scheme://host[:port]) allowed to call /v1. A
// request with any other Origin header comes from a web page and is refused. Empty allows
// none: API clients such as curl and SDKs send no Origin header.
AllowedOrigins []string
// RecordRetention bounds how long a stored record survives before the
// next put evicts it. Defaults to defaultRecordRetention.
RecordRetention time.Duration
// MaxStoredRecords caps the store regardless of age. Defaults to
// defaultMaxStoredRecords.
MaxStoredRecords int
// MaxStoredBytes caps the store by the summed size of every stored
// result, oldest evicted first, regardless of MaxStoredRecords: a
// remote target the caller controls decides how large its own
// discovery snapshot is, so a count cap alone does not bound memory.
// Defaults to defaultMaxStoredBytes.
MaxStoredBytes int64
// Logger receives detail that must not go back to an API caller - for
// example the underlying filesystem error behind a redacted "target
// could not be read" response. Defaults to a discard logger.
Logger *slog.Logger
}
Options configures a Server. Zero values fall back to the defaults above.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server is the HTTP API. Build one with NewServer and mount Handler()
func NewServer ¶
NewServer builds a Server around an already-configured *scanner.Scanner; its Preparer and registry decide what scans can do. Startup fails when sensitive target kinds lack authentication or the filesystem boundary needed to prevent unauthenticated process execution or arbitrary file reads.