| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- package report
- import (
- "math"
- "strings"
- )
- // Finding contains information about strings that
- // have been captured by a tree-sitter query.
- type Finding struct {
- Description string
- StartLine int
- EndLine int
- StartColumn int
- EndColumn int
- Line string `json:"-"`
- Match string
- // Secret contains the full content of what is matched in
- // the tree-sitter query.
- Secret string
- // File is the name of the file containing the finding
- File string
- SymlinkFile string
- Commit string
- // Entropy is the shannon entropy of Value
- Entropy float32
- Author string
- Email string
- Date string
- Message string
- Tags []string
- // Rule is the name of the rule that was matched
- RuleID string
- // unique identifier
- Fingerprint string
- }
- // Redact removes sensitive information from a finding.
- func (f *Finding) Redact(percent uint) {
- secret := maskSecret(f.Secret, percent)
- if percent >= 100 {
- secret = "REDACTED"
- }
- f.Line = strings.Replace(f.Line, f.Secret, secret, -1)
- f.Match = strings.Replace(f.Match, f.Secret, secret, -1)
- f.Secret = secret
- }
- func maskSecret(secret string, percent uint) string {
- if percent > 100 {
- percent = 100
- }
- len := float64(len(secret))
- if len <= 0 {
- return secret
- }
- prc := float64(100 - percent)
- lth := int64(math.RoundToEven(len * prc / float64(100)))
- return secret[:lth] + "..."
- }
|