detector

package
v0.0.0-...-cacfa07 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2025 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package detector implements pattern detection logic for identifying dangerous regex patterns.

Package detector implements NFA-based analysis for detecting EDA and IDA.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Detector

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

Detector performs pattern detection based on configured options.

func NewDetector

func NewDetector(opts *Options) *Detector

NewDetector creates a new detector with the given options.

func (*Detector) Detect

func (d *Detector) Detect(re *syntax.Regexp, pattern string) ([]Issue, error)

Detect analyzes a parsed regex and returns detected issues.

type Issue

type Issue struct {
	Type       string
	Severity   string
	Position   Position
	Pattern    string
	Message    string
	Example    string
	Suggestion string
	Complexity int
}

Issue represents a detected problem.

type NFAAnalyzer

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

NFAAnalyzer performs NFA-based analysis for EDA/IDA detection.

func NewNFAAnalyzer

func NewNFAAnalyzer() *NFAAnalyzer

NewNFAAnalyzer creates a new NFA analyzer.

func (*NFAAnalyzer) AnalyzePattern

func (a *NFAAnalyzer) AnalyzePattern(re *syntax.Regexp, pattern string) ([]Issue, error)

AnalyzePattern analyzes a regex pattern using NFA-based methods.

func (*NFAAnalyzer) ComputeAmbiguityDegree

func (a *NFAAnalyzer) ComputeAmbiguityDegree(re *syntax.Regexp) (int, bool)

ComputeAmbiguityDegree estimates the degree of ambiguity for a pattern. Returns (degree, isExponential).

type Options

type Options struct {
	Mode   ValidationMode
	Checks uint32
}

Options contains configuration for detection.

type Position

type Position struct {
	Start  int
	End    int
	Line   int
	Column int
}

Position represents a location in the pattern.

type ValidationMode

type ValidationMode int

ValidationMode represents the depth of analysis.

const (
	Fast ValidationMode = iota
	Balanced
	Thorough
)

Jump to

Keyboard shortcuts

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