Documentation
¶
Overview ¶
Package triage provides lightweight security analysis of byte strings: Shannon entropy scoring, content classification (URL, email, IPv4/IPv6, domain, file path, hex, base64, UUID), and secret/credential detection (AWS keys, PEM private keys, GitHub/Slack/Stripe tokens, Google API keys, JWTs, and generic key=value assignments).
It depends only on the standard library, making it easy to embed in scanners, CI secret gates, log scrubbers, and forensics tooling. The entry point is Classify; Entropy is exposed separately for reuse.
Index ¶
Constants ¶
const DefaultRedactMask = "[REDACTED]"
DefaultRedactMask is the replacement written over each detected secret by Redact. A fixed token (rather than length-preserving asterisks) avoids leaking the original secret's length.
Variables ¶
This section is empty.
Functions ¶
func Entropy ¶
Entropy returns the Shannon entropy of data in bits per byte, a value in the range [0, 8]. Higher values indicate more randomness: natural-language text typically scores ~4.0-4.5, base64-encoded data ~6, and cryptographic key material approaches 8.
func Redact ¶ added in v0.3.0
Redact returns a copy of str with every detected secret replaced by DefaultRedactMask. It is intended for scrubbing logs, crash dumps, and other text before it is stored or forwarded. The input is never modified.
Detection uses the same rules as Classify; bytes that are not part of a secret are preserved verbatim. Overlapping matches are merged so each region is masked exactly once.
func RedactWith ¶ added in v0.3.0
RedactWith behaves like Redact but replaces each detected secret with the supplied mask instead of DefaultRedactMask.
Types ¶
type Category ¶
type Category string
Category is a human-readable classification of a string's content.
const ( CategoryURL Category = "URL" CategoryEmail Category = "Email" CategoryIPv4 Category = "IPv4" CategoryIPv6 Category = "IPv6" CategoryUUID Category = "UUID" CategoryPathWindows Category = "WinPath" CategoryPathUnix Category = "UnixPath" CategoryDomain Category = "Domain" CategoryHex Category = "Hex" CategoryBase64 Category = "Base64" )
Classification categories.
type Result ¶
type Result struct {
// Entropy is the Shannon entropy (bits/byte) of the trimmed string.
Entropy float64
// HighEntropy is true when Entropy meets the configured threshold and the
// string looks like an opaque token rather than natural-language text.
HighEntropy bool
// Categories holds the content classification (at most one, first match
// wins by priority); empty when nothing matched.
Categories []Category
// Secrets holds any detected secrets/credentials.
Secrets []SecretFinding
}
Result holds the triage analysis of a single string.
func Classify ¶
Classify analyzes a string and returns its entropy, content category, and any detected secrets. minEntropy is the threshold (bits/byte) above which an opaque token is flagged as high-entropy; pass 0 to disable that flag.
func (Result) Interesting ¶
Interesting reports whether the result is worth surfacing in --secrets mode: it contains a detected secret or qualifies as a high-entropy blob.
type SecretFinding ¶
type SecretFinding struct {
Rule string `json:"rule"`
Severity Severity `json:"severity"`
Match string `json:"match"`
// Start and End are the byte offsets of the match within the scanned
// string: str[Start:End] == Match. End is exclusive. They make it possible
// to highlight or redact the exact span (see [Redact]).
Start int `json:"start"`
End int `json:"end"`
}
SecretFinding describes a single secret detected inside a string.