Documentation
¶
Overview ¶
Package scanner runs analyzers against a target and turns their results into a single verdict. It is the shared service layer behind both the CLI and the HTTP API, so the two can never disagree about what a scan means.
Index ¶
Constants ¶
const DefaultAnalyzerTimeout = 5 * time.Minute
DefaultAnalyzerTimeout bounds one analyzer when nothing else is configured. It is set well above what the largest trees take on an idle machine (about a minute), so that a loaded host - where the same work takes longer on the clock - does not cut an analyzer short and change what the scan reports. An analyzer that still reaches it is reported PARTIAL with a warning.
const DiscoveryFailedPrefix = "target discovery failed:"
DiscoveryFailedPrefix starts per-analyzer Scan errors when target preparation fails. API frontends use it to recognize messages that may contain host or caller-supplied paths.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Options ¶
type Options struct {
// Analyzers to run. Empty means every registered analyzer that applies to
// the target kind.
Analyzers []string
// BestEffort lists analyzers whose failure must not block the verdict.
// Everything else is required: enabling an analyzer means you want its
// answer, and not getting it is a reason to say UNKNOWN.
BestEffort []string
// Required names analyzers that are required whatever they return, without narrowing the
// selection to them. BestEffort takes precedence when an analyzer appears in both lists.
Required []string
// BlockingSeverity is the lowest severity that turns a completed scan
// UNSAFE
BlockingSeverity model.Severity
Probes analyzer.ProbeLevel
AllowedToolCalls []string
// Timeout bounds the whole scan; AnalyzerTimeout bounds each analyzer
Timeout time.Duration
AnalyzerTimeout time.Duration
// Concurrency caps analyzers running at once. Zero and one both mean
// serial. The command line defaults it to 4; a scan against a live
// server that cannot take the parallelism should lower it.
Concurrency int
// Root is the filesystem boundary analyzers must stay inside
Root string
Options map[string]map[string]any
// Baseline maps accepted finding IDs to the reason they were accepted.
// Applied before the verdict is computed, so the verdict, the exit code
// and every serialized copy of a finding agree about what was suppressed.
Baseline map[string]string
ScannerVersion string
}
Options configures one scan
type Preparer ¶
type Preparer interface {
Prepare(ctx context.Context, target model.Target) (*analyzer.AnalysisContext, func(), error)
}
Preparer builds the live connection and discovery snapshot for a target. The scanner does not know how to speak MCP; it is handed an implementation.
type Scanner ¶
type Scanner struct {
// contains filtered or unexported fields
}
Scanner runs scans
func New ¶
New builds a scanner. A nil registry uses the default one, a nil preparer means offline scans only, and a nil logger discards output.
func (*Scanner) Scan ¶
func (s *Scanner) Scan(ctx context.Context, target model.Target, opts Options) (*model.ScanResult, error)
Scan runs the configured analyzers against one target.
Every failure path here produces a result, never a bare error: a scan that could not run is a security answer of its own (UNKNOWN) and callers must see it in the report rather than as a message on stderr.