Documentation
¶
Overview ¶
Package bouncer provides token validation, secret pattern matching, and streaming redaction for MCP proxy request/response filtering and security enforcement.
Index ¶
- Constants
- Variables
- func CompileCustomPatterns(configs []PatternConfig) ([]*regexp.Regexp, error)
- func CompileCustomPatternsWithTimeout(configs []PatternConfig, timeout time.Duration) ([]*regexp.Regexp, error)
- func CompilePatterns(configs []PatternConfig) ([]*regexp.Regexp, error)
- func DetectLanguage(filename string) string
- func FindDangerousPatterns(patterns []string) (unsafe []string, err error)
- func FormatPatternList() string
- func GetBuffer() []byte
- func GetPatternNames() []string
- func IsPatternSafe(pattern string) bool
- func LoadPatternsWithLogging(customConfigs []PatternConfig) ([]*regexp.Regexp, []string)
- func MatchSecret(input string) []string
- func PatternsToRegexps(patterns []SecretPattern) []*regexp.Regexp
- func RedactSecrets(input string) string
- func RedactWithPatterns(input string, patterns []*regexp.Regexp) string
- func ReturnBuffer(buf []byte)
- func SafeCompile(pattern string) (*regexp.Regexp, error)
- func SafeCompileMust(pattern string) *regexp.Regexp
- func StripComments(pattern string) string
- func ValidatePattern(pattern string) error
- func ValidatePatterns() error
- func ValidateReDoS(pattern string, timeout time.Duration) error
- type AlertManager
- type BoilerplateProcessor
- type BoilerplatePruner
- type BoilerplateReport
- type Bouncer
- type Claims
- type Config
- type LoadedPatterns
- type PatternConfig
- type PatternDef
- type RedactionEvent
- type RedactionMeta
- type Redactor
- type SecretPattern
- type StreamingRedactor
- type TokenValidator
Constants ¶
const SecretRedacted = "[SECRET_REDACTED]"
Variables ¶
var ( // ErrInvalidToken indicates the provided token is invalid. ErrInvalidToken = errors.New("invalid token") // ErrExpiredToken indicates the provided token has expired. ErrExpiredToken = errors.New("expired token") // ErrMissingToken indicates no token was provided. ErrMissingToken = errors.New("missing token") )
var BuiltInPatterns = []SecretPattern{ { Name: "aws-access-key", Pattern: regexp.MustCompile(`AKIA[0-9A-Z]{16}`), Example: "AKIAIOSFODNN7EXAMPLE", Description: "AWS Access Key ID (20 characters, starts with AKIA)", }, { Name: "github-classic-pat", Pattern: regexp.MustCompile(`ghp_[A-Za-z0-9]{36}`), Example: "ghp_abcdefghijklmnopqrstuvwxyz1234567890abcd", Description: "GitHub Classic Personal Access Token (starts with ghp_)", }, { Name: "github-fine-grained-pat", Pattern: regexp.MustCompile(`github_pat_[A-Za-z0-9_]{22,}`), Example: "github_pat_11abcdefghIJ9xsQ_xxxxxxxxxxxxxxxxx", Description: "GitHub Fine-grained PAT (starts with github_pat_)", }, { Name: "stripe-secret-key", Pattern: regexp.MustCompile(`sk_live_[A-Za-z0-9]{24}`), Example: "[Stripe Live Secret Key - 24 chars after sk_live_]", Description: "Stripe Live Secret Key (starts with sk_live_)", }, { Name: "stripe-publishable-key", Pattern: regexp.MustCompile(`pk_live_[A-Za-z0-9]{24}`), Example: "[Stripe Publishable Key - 24 chars after pk_live_]", Description: "Stripe Live Publishable Key (starts with pk_live_)", }, { Name: "generic-api-key", Pattern: regexp.MustCompile(`(?i)(api[_-]?key)[_-]?[=]?[A-Za-z0-9]{16,}`), Example: "api_key=abcdefghijklmnopqrstuvwx", Description: "Generic API key pattern (case-insensitive)", }, { Name: "bearer-token", Pattern: regexp.MustCompile(`(?i)bearer\s+[A-Za-z0-9\-_]+\.[A-Za-z0-9\-_]+\.[A-Za-z0-9\-_]+`), Example: "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c", Description: "JWT Bearer token (three base64url segments)", }, { Name: "env-var-value", Pattern: regexp.MustCompile(`\$[A-Z_][A-Z0-9_]{0,30}=([^\s,}]+)`), Example: "$API_KEY=secret123", Description: "Environment variable assignment", }, }
var (
ErrDangerousPattern = errors.New("dangerous regex pattern detected")
)
Functions ¶
func CompileCustomPatterns ¶ added in v0.2.0
func CompileCustomPatterns(configs []PatternConfig) ([]*regexp.Regexp, error)
func CompileCustomPatternsWithTimeout ¶ added in v0.2.0
func CompilePatterns ¶ added in v0.2.0
func CompilePatterns(configs []PatternConfig) ([]*regexp.Regexp, error)
func DetectLanguage ¶ added in v0.2.0
func FindDangerousPatterns ¶ added in v0.6.0
func FormatPatternList ¶ added in v0.2.0
func FormatPatternList() string
func GetPatternNames ¶ added in v0.2.0
func GetPatternNames() []string
func IsPatternSafe ¶ added in v0.6.0
func LoadPatternsWithLogging ¶ added in v0.2.0
func LoadPatternsWithLogging(customConfigs []PatternConfig) ([]*regexp.Regexp, []string)
func MatchSecret ¶ added in v0.2.0
func PatternsToRegexps ¶ added in v0.2.0
func PatternsToRegexps(patterns []SecretPattern) []*regexp.Regexp
func RedactSecrets ¶ added in v0.2.0
func RedactWithPatterns ¶ added in v0.2.0
func ReturnBuffer ¶ added in v0.2.0
func ReturnBuffer(buf []byte)
func SafeCompileMust ¶ added in v0.6.0
func StripComments ¶ added in v0.6.0
func ValidatePattern ¶ added in v0.6.0
func ValidatePatterns ¶ added in v0.2.0
func ValidatePatterns() error
Types ¶
type AlertManager ¶ added in v0.2.0
type AlertManager struct {
// contains filtered or unexported fields
}
func NewAlertManager ¶ added in v0.2.0
func NewAlertManager(verbose bool) *AlertManager
func (*AlertManager) EmitSummary ¶ added in v0.2.0
func (am *AlertManager) EmitSummary(messageID string, method string)
func (*AlertManager) GetCounts ¶ added in v0.2.0
func (am *AlertManager) GetCounts() map[string]int
func (*AlertManager) RecordRedaction ¶ added in v0.2.0
func (am *AlertManager) RecordRedaction(event RedactionEvent)
func (*AlertManager) SetEnabled ¶ added in v0.2.0
func (am *AlertManager) SetEnabled(enabled bool)
func (*AlertManager) SetVerbose ¶ added in v0.2.0
func (am *AlertManager) SetVerbose(verbose bool)
type BoilerplateProcessor ¶ added in v0.2.0
type BoilerplateProcessor interface {
Process(content []byte, language string) ([]byte, BoilerplateReport, error)
}
type BoilerplatePruner ¶ added in v0.2.0
type BoilerplatePruner struct {
// contains filtered or unexported fields
}
func NewBoilerplatePruner ¶ added in v0.2.0
func NewBoilerplatePruner(enabled, redactImports, redactLicenses bool, customPatterns []PatternDef) *BoilerplatePruner
func (*BoilerplatePruner) Process ¶ added in v0.2.0
func (p *BoilerplatePruner) Process(content []byte, language string) ([]byte, BoilerplateReport, error)
func (*BoilerplatePruner) ProcessStream ¶ added in v0.2.0
func (p *BoilerplatePruner) ProcessStream(reader io.Reader, writer io.Writer, language string) (BoilerplateReport, error)
type BoilerplateReport ¶ added in v0.2.0
type Bouncer ¶
type Bouncer struct{}
Bouncer is a token validation and secret detection service.
func (*Bouncer) ExtractClaims ¶
ExtractClaims extracts claims from a validated token.
type Claims ¶
type Claims map[string]interface{}
Claims represents the claims extracted from a validated token.
type Config ¶ added in v0.2.0
type Config struct {
Enabled bool `yaml:"enabled"`
CustomPatterns []PatternDef `yaml:"custom_patterns"`
}
Config defines the bouncer configuration, including whether the bouncer is enabled and any custom regex patterns for secret detection.
func LoadConfig ¶ added in v0.2.0
LoadConfig reads and parses a bouncer YAML configuration from the provided reader.
func LoadConfigFile ¶ added in v0.2.0
LoadConfigFile reads and parses a bouncer YAML configuration from the given file path.
func (*Config) CompilePatterns ¶ added in v0.2.0
func (c *Config) CompilePatterns() (*LoadedPatterns, error)
CompilePatterns compiles built-in and custom patterns into a LoadedPatterns struct.
type LoadedPatterns ¶ added in v0.2.0
type LoadedPatterns struct {
BuiltIn []SecretPattern
Custom []SecretPattern
All []*regexp.Regexp
}
LoadedPatterns holds the compiled built-in and custom regex patterns.
type PatternConfig ¶ added in v0.2.0
func (PatternConfig) Validate ¶ added in v0.2.0
func (pc PatternConfig) Validate() error
type PatternDef ¶ added in v0.2.0
PatternDef defines a custom regex pattern for secret detection.
type RedactionEvent ¶ added in v0.2.0
type RedactionMeta ¶ added in v0.2.0
type Redactor ¶ added in v0.1.2
type Redactor struct {
// contains filtered or unexported fields
}
func NewRedactor ¶ added in v0.1.2
func NewRedactorFromLoaded ¶ added in v0.2.0
func NewRedactorFromLoaded(loaded *LoadedPatterns) *Redactor
func NewRedactorWithAlerts ¶ added in v0.2.0
func NewRedactorWithAlerts(patterns []*regexp.Regexp, alertManager *AlertManager) *Redactor
func (*Redactor) RedactJSON ¶ added in v0.1.2
func (*Redactor) RedactStream ¶ added in v0.1.2
type SecretPattern ¶ added in v0.2.0
func GetBuiltInPatterns ¶ added in v0.2.0
func GetBuiltInPatterns() []SecretPattern
func GetPatternByName ¶ added in v0.2.0
func GetPatternByName(name string) *SecretPattern
type StreamingRedactor ¶ added in v0.2.0
type StreamingRedactor struct {
// contains filtered or unexported fields
}
func NewStreamingRedactor ¶ added in v0.2.0
func NewStreamingRedactor(patterns []*regexp.Regexp) *StreamingRedactor
func NewStreamingRedactorWithAlerts ¶ added in v0.2.0
func NewStreamingRedactorWithAlerts(patterns []*regexp.Regexp, am *AlertManager) *StreamingRedactor
func (*StreamingRedactor) RedactStream ¶ added in v0.2.0
func (sr *StreamingRedactor) RedactStream(r io.Reader, w io.Writer, meta ...*RedactionMeta) error