Documentation
¶
Overview ¶
Package scan provides content scanning middleware for Trove. It scans uploaded content for threats using a pluggable Provider interface. When a threat is detected, the upload is blocked with trove.ErrContentBlocked.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ClamAVOption ¶
type ClamAVOption func(*ClamAVProvider)
ClamAVOption configures the ClamAV provider.
func WithTimeout ¶
func WithTimeout(d time.Duration) ClamAVOption
WithTimeout sets the scan timeout for ClamAV connections.
type ClamAVProvider ¶
type ClamAVProvider struct {
// contains filtered or unexported fields
}
ClamAVProvider implements Provider using the ClamAV INSTREAM protocol. It connects to a ClamAV daemon over TCP and streams content for scanning.
func NewClamAVProvider ¶
func NewClamAVProvider(addr string, opts ...ClamAVOption) *ClamAVProvider
NewClamAVProvider creates a ClamAV scan provider. The addr is the ClamAV daemon address (e.g., "localhost:3310").
func (*ClamAVProvider) Scan ¶
Scan sends content to ClamAV using the INSTREAM protocol and returns the scan result.
INSTREAM protocol:
- Send "zINSTREAM\x00"
- For each chunk: send 4-byte big-endian length + data
- Send 4-byte zero to signal end of stream
- Read response: "stream: OK\x00" or "stream: <THREAT> FOUND\x00"
type OnDetectFunc ¶
OnDetectFunc is a callback invoked when a threat is detected.
type Option ¶
type Option func(*Scan)
Option configures the Scan middleware.
func WithMaxSize ¶
WithMaxSize sets the maximum size of content to scan. Content larger than this is passed through without scanning. Default: 25MB.
func WithOnDetect ¶
func WithOnDetect(fn OnDetectFunc) Option
WithOnDetect sets a callback for when threats are detected.
func WithSkipExtensions ¶
WithSkipExtensions sets file extensions to skip scanning.
type Provider ¶
type Provider interface {
// Scan inspects the content and returns a result indicating whether
// the content is clean or contains a threat.
Scan(ctx context.Context, r io.Reader) (*Result, error)
}
Provider defines the interface for content scanning backends.
type Result ¶
type Result struct {
// Clean is true if no threats were found.
Clean bool
// Threat is the name/identifier of the detected threat (empty if clean).
Threat string
// Details provides additional information about the scan.
Details string
}
Result holds the outcome of a content scan.
type Scan ¶
type Scan struct {
// contains filtered or unexported fields
}
Scan provides content scanning middleware for uploads.
func (*Scan) Direction ¶
func (s *Scan) Direction() middleware.Direction
Direction returns Write since scanning only applies to uploads.
func (*Scan) WrapWriter ¶
func (s *Scan) WrapWriter(ctx context.Context, w io.WriteCloser, key string) (io.WriteCloser, error)
WrapWriter wraps a writer to scan content before it reaches the driver. Data is buffered, scanned on Close(), and blocked with ErrContentBlocked if a threat is detected.
Each scan records a "scan object" client span (a scanner such as ClamAV is a separate service) with the result and the size scanned, and counts trove_scans_total on the Recorder of the Trove that runs the middleware. The span carries neither the key nor the threat name.