scanner

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2026 License: MIT Imports: 19 Imported by: 0

Documentation

Overview

Package scanner implements CVE and malware scanners.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

New builds an AV scanner from its config. Unknown types are an error. The scanner reports cfg.DisplayName() as the engine of its verdicts.

func NewLimitedScanner

func NewLimitedScanner(inner gate.AVScanner, limit int, opts ...LimitedOption) gate.AVScanner

NewLimitedScanner wraps inner so that at most limit scans run concurrently. A limit <= 0 disables limiting and returns inner unchanged.

Types

type ClamAVScanner

type ClamAVScanner struct {
	// contains filtered or unexported fields
}

ClamAVScanner is a clamd client that scans files via the INSTREAM command. It implements gate.AVScanner.

func NewClamAVScanner

func NewClamAVScanner(address string, timeout time.Duration) (*ClamAVScanner, error)

NewClamAVScanner creates a scanner for the given clamd address. address is "unix:///var/run/clamav/clamd.sock" or "tcp:host:3310".

func (*ClamAVScanner) Probe

func (s *ClamAVScanner) Probe(ctx context.Context) error

Probe checks clamd liveness with the PING command (expects PONG).

func (*ClamAVScanner) Scan

func (s *ClamAVScanner) Scan(ctx context.Context, filePath string) (*gate.AVResult, error)

Scan implements gate.AVScanner using the clamd INSTREAM protocol.

type ICAPScanner

type ICAPScanner struct {
	// contains filtered or unexported fields
}

ICAPScanner scans files via the ICAP RESPMOD method. It works with any ICAP AV server (Kaspersky, Dr.Web, ClamAV behind c-icap). Implements gate.AVScanner.

func NewICAPScanner

func NewICAPScanner(address, service string, timeout time.Duration) (*ICAPScanner, error)

NewICAPScanner creates a scanner for an ICAP server at address with the given service name. address is "unix:///path" or "tcp:host:port".

func (*ICAPScanner) Probe

func (s *ICAPScanner) Probe(ctx context.Context) error

Probe checks ICAP liveness with the OPTIONS method (expects a 2xx status).

func (*ICAPScanner) Scan

func (s *ICAPScanner) Scan(ctx context.Context, filePath string) (*gate.AVResult, error)

Scan implements gate.AVScanner using ICAP RESPMOD.

type LimitedOption added in v0.6.0

type LimitedOption func(*LimitedScanner)

LimitedOption customises a LimitedScanner.

func WithWaitObserver added in v0.6.0

func WithWaitObserver(f func(time.Duration)) LimitedOption

WithWaitObserver reports, once per Scan that acquires a slot, how long it waited in the queue. A nil f is a no-op and skips timing entirely.

type LimitedScanner

type LimitedScanner struct {
	// contains filtered or unexported fields
}

LimitedScanner caps the number of concurrent scans run against the wrapped engine. It exists to apply backpressure: clamd (and ICAP servers) have a bounded worker pool, so firing more concurrent INSTREAM/RESPMOD requests than the engine can serve makes responses queue past the per-scan deadline and surface as "i/o timeout". Bounding in-flight scans keeps each one fast enough to beat its deadline. It implements gate.AVScanner.

func (*LimitedScanner) Scan

func (l *LimitedScanner) Scan(ctx context.Context, filePath string) (*gate.AVResult, error)

Scan acquires a concurrency slot (honouring context cancellation while it waits) then delegates to the wrapped scanner.

type MultiScanner

type MultiScanner struct {
	// contains filtered or unexported fields
}

MultiScanner runs several AV engines concurrently on the same file, so a scan takes as long as the slowest engine rather than the sum of all of them. It implements gate.AVScanner and fails closed: any engine reporting malware or failing blocks the artifact.

func NewMultiScanner

func NewMultiScanner(scanners ...gate.AVScanner) *MultiScanner

NewMultiScanner wraps the given scanners. Their order decides which result is reported when several engines detect or fail on the same file.

func (*MultiScanner) Scan

func (m *MultiScanner) Scan(ctx context.Context, filePath string) (*gate.AVResult, error)

Scan runs every engine at once and waits for all of them, so no engine is still reading the file (or holding a concurrency slot) once Scan returns. A detection cancels the others' context. The verdict is the first detection in engine order; failing that, the first error; failing that, the first incomplete scan; else clean. A detection outranks an error because both block and the detection says why; an engine giving up on the file must never hide another engine's detection, so it ranks last.

type OSVOption added in v1.0.0

type OSVOption func(*OSVScanner)

OSVOption configures an OSVScanner.

func WithOSVHTTPClient added in v1.0.0

func WithOSVHTTPClient(c *http.Client) OSVOption

WithOSVHTTPClient sets the client OSV lookups use. The proxy passes one on its shared upstream transport, so lookups honour tls.ca_files (a TLS-inspecting corporate proxy would otherwise fail every lookup, and the CVE gate with it) and count against the per-host rate limits.

type OSVScanner

type OSVScanner struct {
	// contains filtered or unexported fields
}

OSVScanner queries api.osv.dev for known vulnerabilities. It implements gate.CVEScanner and caches results in memory.

func NewOSVScanner

func NewOSVScanner(baseURL string, ttl time.Duration, opts ...OSVOption) *OSVScanner

NewOSVScanner creates an OSVScanner with the given base URL and cache TTL. baseURL should be "https://api.osv.dev" (or a mock server URL in tests). Without WithOSVHTTPClient it uses a private client with a 15 s timeout.

func (*OSVScanner) Close

func (s *OSVScanner) Close() error

Close stops the janitor goroutine and waits for it to exit. Safe to call more than once.

func (*OSVScanner) Health

func (s *OSVScanner) Health() health.Sample

Health reports the result of the last live query as a passive health sample. Before any live query runs, HasData is false (status unknown). Cache hits do not update it.

func (*OSVScanner) Scan

func (s *OSVScanner) Scan(ctx context.Context, ref *gate.PackageRef) (*gate.ScanResult, error)

Scan implements gate.CVEScanner.

type Prober

type Prober interface {
	Probe(ctx context.Context) error
}

Prober is an optional scanner capability: a cheap liveness check that does not scan a file. ClamAVScanner and ICAPScanner implement it; the health Monitor calls Probe on a background timer.

Jump to

Keyboard shortcuts

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