regexsafe

package
v3.8.8 Latest Latest
Warning

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

Go to latest
Published: Jun 29, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package regexsafe centralises the RE2 ReDoS / unsupported-feature validation shared by every SQL dialect's regex conversion.

Each dialect previously reimplemented this validation in its own regex.go, and the copies had drifted (some compiled the pattern first, the nested-quantifier and nesting-depth loops were written differently, error wording diverged). A single implementation guarantees that a check tightened for one dialect protects all of them. Only the dialect-specific parts — case-insensitivity handling and the final character-class / non-capturing group transform — remain in each dialect's regex.go.

Index

Constants

View Source
const (
	// MaxPatternLength caps the raw pattern length.
	MaxPatternLength = 500
	// MaxGroups caps the number of capture groups.
	MaxGroups = 20
	// MaxNestingDepth caps how deeply groups may nest.
	MaxNestingDepth = 10
)

Pattern complexity limits to prevent ReDoS attacks (CWE-1333).

Variables

This section is empty.

Functions

func Validate

func Validate(pattern string) error

Validate runs the dialect-agnostic security checks on an RE2 pattern.

Callers should strip any leading (?i) case-insensitivity flag before calling Validate (the flag's handling is dialect-specific); Validate still rejects inline flags other than (?i). It returns a non-nil error describing the first problem found, or nil if the pattern is safe to convert.

Types

This section is empty.

Jump to

Keyboard shortcuts

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