patterns

package
v0.17.2 Latest Latest
Warning

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

Go to latest
Published: Feb 3, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package patterns provides sensitive data detection patterns for various credential types.

Package patterns provides sensitive data detection patterns for various credential types.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Category

type Category string

Category of pattern

const (
	CategoryCloudCredentials Category = "cloud_credentials"
	CategoryPrivateKey       Category = "private_key"
	CategoryAPIToken         Category = "api_token"
	CategoryAuthToken        Category = "auth_token"
	CategorySensitiveFile    Category = "sensitive_file"
	CategoryDatabaseCred     Category = "database_credential"
	CategoryHighEntropy      Category = "high_entropy"
	CategoryCreditCard       Category = "credit_card"
	CategoryCustom           Category = "custom"
)

type CustomPatternError

type CustomPatternError struct {
	PatternName string
	Message     string
}

CustomPatternError represents an error when loading a custom pattern

func (*CustomPatternError) Error

func (e *CustomPatternError) Error() string

Error implements the error interface

type Pattern

type Pattern struct {
	Name        string
	Category    Category
	Severity    Severity
	Description string
	// contains filtered or unexported fields
}

Pattern represents a sensitive data detection pattern

func GetCloudPatterns

func GetCloudPatterns() []*Pattern

GetCloudPatterns returns all cloud credential detection patterns

func GetCreditCardPatterns

func GetCreditCardPatterns() []*Pattern

GetCreditCardPatterns returns credit card detection patterns

func GetDatabasePatterns

func GetDatabasePatterns() []*Pattern

GetDatabasePatterns returns all database credential detection patterns

func GetKeyPatterns

func GetKeyPatterns() []*Pattern

GetKeyPatterns returns all private key detection patterns

func GetTokenPatterns

func GetTokenPatterns() []*Pattern

GetTokenPatterns returns all API token detection patterns

func LoadCustomPatterns

func LoadCustomPatterns(patterns []config.CustomPattern) ([]*Pattern, []error)

LoadCustomPatterns converts config.CustomPattern definitions to Pattern objects. It validates regex patterns and returns errors for invalid ones. Returns a slice of valid patterns and a slice of errors for invalid patterns.

func (*Pattern) IsKnownExample

func (p *Pattern) IsKnownExample(match string) bool

IsKnownExample checks if a match is a known test/example value

func (*Pattern) IsValid

func (p *Pattern) IsValid(match string) bool

IsValid validates a match using the pattern's validator

func (*Pattern) Match

func (p *Pattern) Match(content string) []string

Match finds all matches in the given content If a validator is set, only matches that pass validation are returned

type PatternBuilder

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

PatternBuilder provides a fluent API for building patterns

func NewPattern

func NewPattern(name string) *PatternBuilder

NewPattern creates a new pattern builder

func (*PatternBuilder) Build

func (b *PatternBuilder) Build() *Pattern

Build creates the Pattern

func (*PatternBuilder) WithCategory

func (b *PatternBuilder) WithCategory(category Category) *PatternBuilder

WithCategory sets the pattern category

func (*PatternBuilder) WithDescription

func (b *PatternBuilder) WithDescription(description string) *PatternBuilder

WithDescription sets the pattern description

func (*PatternBuilder) WithKeywords

func (b *PatternBuilder) WithKeywords(keywords ...string) *PatternBuilder

WithKeywords sets the keywords for matching

func (*PatternBuilder) WithKnownExamples

func (b *PatternBuilder) WithKnownExamples(examples ...string) *PatternBuilder

WithKnownExamples sets known example values (like AWS example keys)

func (*PatternBuilder) WithNormalizer

func (b *PatternBuilder) WithNormalizer(normalizer func(string) string) *PatternBuilder

WithNormalizer sets a function to normalize matches before known example lookup

func (*PatternBuilder) WithRegex

func (b *PatternBuilder) WithRegex(pattern string) *PatternBuilder

WithRegex sets the regex pattern

func (*PatternBuilder) WithSeverity

func (b *PatternBuilder) WithSeverity(severity Severity) *PatternBuilder

WithSeverity sets the pattern severity

func (*PatternBuilder) WithValidator

func (b *PatternBuilder) WithValidator(validator func(string) bool) *PatternBuilder

WithValidator sets a custom validator function

type Severity

type Severity string

Severity levels for detected patterns

const (
	SeverityCritical Severity = "critical"
	SeverityHigh     Severity = "high"
	SeverityMedium   Severity = "medium"
	SeverityLow      Severity = "low"
)

Jump to

Keyboard shortcuts

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