scanner

package
v1.0.7 Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ShouldBlock

func ShouldBlock(severity Severity) bool

ShouldBlock returns true if the severity level should trigger a block

Types

type Category

type Category string

Category represents the type of sensitive data detected

const (
	CategoryPII           Category = "PII"
	CategoryCredential    Category = "Credential"
	CategoryFinancial     Category = "Financial"
	CategoryCryptographic Category = "Cryptographic"
	CategoryNetwork       Category = "Network"
)
const (
	CategoryHealthcare Category = "Healthcare"
	CategoryCloud      Category = "Cloud"
	CategoryDocument   Category = "Document"
)

AdditionalCategories adds new category constants

type Config

type Config struct {
	Patterns       []*Pattern
	BlockThreshold Severity
	LogFindings    bool
	IncludeContext bool
	ContextSize    int // Characters before and after match to include
	MaxFindings    int // Maximum number of findings to return per scan
}

Config holds scanner configuration

func DefaultConfig

func DefaultConfig() *Config

DefaultConfig returns a default scanner configuration

type Finding

type Finding struct {
	Pattern  *Pattern
	Match    string
	Position int
	Context  string // Additional context around the match (optional)
}

Finding represents a single detection of sensitive data

type Pattern

type Pattern struct {
	Name        string
	Regex       *regexp.Regexp
	Severity    Severity
	Category    Category
	Description string
}

Pattern represents a detection pattern for sensitive data

func AdditionalPatterns

func AdditionalPatterns() []*Pattern

AdditionalPatterns returns extended detection patterns These can be merged with DefaultPatterns() for enhanced coverage

func AllPatterns

func AllPatterns() []*Pattern

AllPatterns returns combined default and additional patterns

func DefaultPatterns

func DefaultPatterns() []*Pattern

DefaultPatterns returns the complete set of detection patterns Note: Go's regexp package uses RE2 syntax which doesn't support negative lookahead

type Scanner

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

Scanner represents the content scanning engine

func New

func New(config *Config) *Scanner

New creates a new Scanner with the given configuration

func (*Scanner) AddPattern

func (s *Scanner) AddPattern(pattern *Pattern)

AddPattern adds a custom pattern to the scanner

func (*Scanner) CompilePattern

func (s *Scanner) CompilePattern(name, pattern string, severity Severity, category Category, description string) error

CompilePattern compiles a regex pattern and adds it to the scanner

func (*Scanner) GetCriticalFindings

func (s *Scanner) GetCriticalFindings(findings []Finding) []Finding

GetCriticalFindings returns only Critical severity findings

func (*Scanner) GetFindingsByCategory

func (s *Scanner) GetFindingsByCategory(findings []Finding, category Category) []Finding

GetFindingsByCategory returns findings filtered by category

func (*Scanner) GetFindingsBySeverity

func (s *Scanner) GetFindingsBySeverity(findings []Finding, minSeverity Severity) []Finding

GetFindingsBySeverity returns findings filtered by minimum severity

func (*Scanner) GetPattern

func (s *Scanner) GetPattern(name string) *Pattern

GetPattern returns a pattern by name

func (*Scanner) GetViolationNames

func (s *Scanner) GetViolationNames(findings []Finding) []string

GetViolationNames returns the names of patterns that triggered violations

func (*Scanner) GetViolationSummary

func (s *Scanner) GetViolationSummary(findings []Finding) map[Severity]int

GetViolationSummary returns a summary of all findings by severity

func (*Scanner) HasViolation

func (s *Scanner) HasViolation(findings []Finding) bool

HasViolation checks if any finding meets or exceeds the configured block threshold

func (*Scanner) RemovePattern

func (s *Scanner) RemovePattern(name string) bool

RemovePattern removes a pattern by name

func (*Scanner) Scan

func (s *Scanner) Scan(content string) []Finding

Scan analyzes content against all configured patterns and returns findings

func (*Scanner) ScanBytes

func (s *Scanner) ScanBytes(content []byte) []Finding

ScanBytes converts bytes to string and scans

func (*Scanner) ScanWithContext

func (s *Scanner) ScanWithContext(content string) []Finding

ScanWithContext analyzes content and returns findings with their surrounding context

func (*Scanner) SetConfig

func (s *Scanner) SetConfig(config *Config)

SetConfig updates the scanner configuration

func (*Scanner) ShouldBlock

func (s *Scanner) ShouldBlock(findings []Finding) bool

ShouldBlock checks if any finding should trigger a block action

type Severity

type Severity int

Severity represents the risk level of a finding

const (
	Info Severity = iota
	Low
	Medium
	High
	Critical
)

func (Severity) String

func (s Severity) String() string

String returns the string representation of Severity

Jump to

Keyboard shortcuts

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