scanner

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2026 License: MIT Imports: 18 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 sequentially in order. It implements gate.AVScanner. It short-circuits on the first detection or first error (fail-closed): any engine reporting malware or failing blocks the artifact.

func NewMultiScanner

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

NewMultiScanner wraps the given scanners. They run in the order supplied.

func (*MultiScanner) Scan

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

Scan runs each engine until one errors or reports an infection.

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) *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).

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