scan

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Jan 24, 2026 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var GlobalEngine = &Engine{
	KeywordIndexMap: make(map[int][]int),
}

Functions

func BuildEngine

func BuildEngine(patterns []CompiledPattern)

BuildEngine compiles the Aho-Corasick matcher from the provided patterns

func ExtractKeyword

func ExtractKeyword(regexStr string) string

ExtractKeyword analyzes a regex pattern and returns the longest literal string that MUST be present for the regex to match. Returns empty string if none found.

func GetPatternCount

func GetPatternCount() int

GetPatternCount returns the number of loaded patterns

func IsValidKeyword

func IsValidKeyword(kw string) bool

IsValidKeyword checks if the keyword is good enough to be an index

func PatternCount

func PatternCount() int

func SaveEndpoints

func SaveEndpoints(endpoints []core.Endpoint, cfg *config.Config)

func SaveScanLog

func SaveScanLog(logName string, content string, cfg *config.Config)

SaveScanLog saves detailed scan logs to logs folder

func SaveSecrets

func SaveSecrets(secrets []core.Secret, cfg *config.Config)

func SetTemplatePatterns

func SetTemplatePatterns(patterns []CompiledPattern)

SetTemplatePatterns sets the loaded patterns for use by the scanner

Types

type CompiledPattern

type CompiledPattern struct {
	ID           string
	Name         string
	Regex        *coregex.Regexp
	RegexString  string // Store original regex for optimization
	Confidence   int
	Severity     string
	EntropyCheck bool
	MinEntropy   float64
	Tags         []string
	Mutex        *sync.Mutex // Protects Regex from concurrent access (lazy DFA)
}

func GetPatterns

func GetPatterns() []CompiledPattern

func GetPatternsBySeverity

func GetPatternsBySeverity(severity string) []CompiledPattern

func GetPatternsByTag

func GetPatternsByTag(tag string) []CompiledPattern

func LoadPatterns

func LoadPatterns() ([]CompiledPattern, error)

type EndpointScanner

type EndpointScanner struct {
	Config *config.Config
}

func NewEndpointScanner

func NewEndpointScanner(cfg *config.Config) *EndpointScanner

func (*EndpointScanner) Run

func (e *EndpointScanner) Run(files []string) []core.Endpoint

type Engine

type Engine struct {
	Matcher          *ahocorasick.Matcher
	KeywordIndexMap  map[int][]int // Maps keyword_index (from AC) -> list of pattern indices (in AllPatterns)
	FallbackPatterns []int         // Indices of patterns with no keywords (must always run)
	AllPatterns      []CompiledPattern
	IsReady          bool
	// contains filtered or unexported fields
}

Engine is the high-performance scanning engine

func (*Engine) ScanContent

func (e *Engine) ScanContent(content []byte, filePath string, seen map[string]bool, linePositions []int, skipGeneric bool) []core.Secret

ScanContent runs the high-performance scan on a file

type GitleaksResult

type GitleaksResult struct {
	Description string `json:"Description"`
	Secret      string `json:"Secret"`
	File        string `json:"File"`
	Match       string `json:"Match"`
	StartLine   int    `json:"StartLine"`
}

type PatternFile

type PatternFile struct {
	Name     string            `yaml:"name"`
	Version  string            `yaml:"version"`
	Author   string            `yaml:"author"`
	Category string            `yaml:"category"`
	Provider string            `yaml:"provider"`
	Patterns []PatternTemplate `yaml:"patterns"`
}

type PatternLoader

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

type PatternTemplate

type PatternTemplate struct {
	ID              string   `yaml:"id"`
	Name            string   `yaml:"name"`
	Description     string   `yaml:"description"`
	Regex           string   `yaml:"regex"`
	Confidence      int      `yaml:"confidence"`
	Severity        string   `yaml:"severity"`
	EntropyCheck    bool     `yaml:"entropy_check"`
	MinEntropy      float64  `yaml:"min_entropy"`
	MinLength       int      `yaml:"min_length"`
	MaxLength       int      `yaml:"max_length"`
	Tags            []string `yaml:"tags"`
	ContextKeywords []string `yaml:"context_keywords"`
	References      []string `yaml:"references"`
}

type SecretScanner

type SecretScanner struct {
	Config *config.Config
}

func NewSecretScanner

func NewSecretScanner(cfg *config.Config) *SecretScanner

func (*SecretScanner) Run

func (s *SecretScanner) Run(files []string) []core.Secret

func (*SecretScanner) SetSkipGeneric

func (s *SecretScanner) SetSkipGeneric(skip bool)

Jump to

Keyboard shortcuts

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