Documentation
¶
Overview ¶
Package rules contains the heuristics envaudit uses to decide whether a .env value is a real secret, a placeholder, or something in between.
Index ¶
Constants ¶
const ( ConfidenceNone = "none" ConfidenceLow = "low" ConfidenceMedium = "medium" ConfidenceHigh = "high" )
Confidence levels, ordered low to high.
Variables ¶
var BuiltinPatterns = []Pattern{ {"AWS Access Key ID", regexp.MustCompile(`^AKIA[0-9A-Z]{16}$`)}, {"AWS Secret Access Key", regexp.MustCompile(`^[A-Za-z0-9/+=]{40}$`)}, {"Ethereum/EVM Private Key", regexp.MustCompile(`^(0x)?[a-fA-F0-9]{64}$`)}, {"BIP39 Seed Phrase (12 words)", regexp.MustCompile(`^([a-z]+\s+){11}[a-z]+$`)}, {"BIP39 Seed Phrase (24 words)", regexp.MustCompile(`^([a-z]+\s+){23}[a-z]+$`)}, {"Stripe Secret Key", regexp.MustCompile(`^sk_(live|test)_[0-9a-zA-Z]{16,}$`)}, {"GitHub Token", regexp.MustCompile(`^gh[pousr]_[A-Za-z0-9]{36,}$`)}, {"Slack Token", regexp.MustCompile(`^xox[baprs]-[A-Za-z0-9-]{10,}$`)}, {"Slack Webhook URL", regexp.MustCompile(`^https://hooks\.slack\.com/services/[A-Z0-9]+/[A-Z0-9]+/[A-Za-z0-9]+$`)}, {"OpenAI API Key", regexp.MustCompile(`^sk-(proj-)?[A-Za-z0-9]{20,}$`)}, {"Anthropic API Key", regexp.MustCompile(`^sk-ant-[A-Za-z0-9_-]{20,}$`)}, {"Google API Key", regexp.MustCompile(`^AIza[0-9A-Za-z\-_]{35}$`)}, {"SendGrid API Key", regexp.MustCompile(`^SG\.[A-Za-z0-9_\-]{20,}\.[A-Za-z0-9_\-]{40,}$`)}, {"Twilio API Key", regexp.MustCompile(`^SK[0-9a-fA-F]{32}$`)}, {"npm Token", regexp.MustCompile(`^npm_[A-Za-z0-9]{36}$`)}, {"Telegram Bot Token", regexp.MustCompile(`^[0-9]{8,10}:AA[A-Za-z0-9_-]{33}$`)}, {"Discord Bot Token", regexp.MustCompile(`^[A-Za-z0-9_-]{24}\.[A-Za-z0-9_-]{6}\.[A-Za-z0-9_-]{27}$`)}, {"Hugging Face Token", regexp.MustCompile(`^hf_[A-Za-z0-9]{34}$`)}, {"GitLab Personal Access Token", regexp.MustCompile(`^glpat-[A-Za-z0-9_-]{20,}$`)}, {"Shopify Access Token", regexp.MustCompile(`^shpat_[A-Za-z0-9]{32}$`)}, {"DigitalOcean Personal Access Token", regexp.MustCompile(`^dop_v1_[a-z0-9]{64}$`)}, {"Klaviyo API Key", regexp.MustCompile(`^pk_[0-9a-fA-F]{32}$`)}, {"JWT", regexp.MustCompile(`^eyJ[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]*$`)}, {"Generic API Key (long hex/base64)", regexp.MustCompile(`^[A-Za-z0-9_\-]{32,}$`)}, {"Private Key Block", regexp.MustCompile(`BEGIN (RSA |EC |OPENSSH |PGP |DSA )?PRIVATE KEY`)}, {"Database Connection String", regexp.MustCompile(`^(postgres|postgresql|mysql|mongodb(\+srv)?):\/\/[^:]+:[^@]+@`)}, }
BuiltinPatterns are well-known secret formats. Kept intentionally small and high-precision; broad/fuzzy detection is entropy's job, not regex's.
Functions ¶
func IsPlaceholder ¶
IsPlaceholder reports whether value looks like a deliberate stand-in rather than a real credential.
func ShannonEntropy ¶
ShannonEntropy returns the Shannon entropy, in bits per character, of s. Higher entropy means "more random-looking"; real secrets (API keys, tokens, hex-encoded private keys) tend to sit well above ordinary English words or simple placeholders.
Types ¶
type Classification ¶
type Classification struct {
IsSecretLike bool
Confidence string // none|low|medium|high
MatchedPattern string // populated when a named Pattern matched
Reason string // short human-readable explanation
}
Classification is the result of evaluating a single KEY=VALUE pair.
func Classify ¶
func Classify(key, value string, entropyThreshold float64, custom []Pattern) Classification
Classify decides whether key=value looks like a real secret. custom is an optional extra set of patterns (from config) merged with the built-ins; entropyThreshold comes from config.Config.EntropyThreshold.