scanner

package
v1.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 14, 2026 License: Apache-2.0 Imports: 11 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
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

func New(reg *analyzer.Registry, prep Preparer, log *slog.Logger) *Scanner

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL