finding.go 968 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. package report
  2. import (
  3. "strconv"
  4. "strings"
  5. )
  6. // Finding contains information about strings that
  7. // have been captured by a tree-sitter query.
  8. type Finding struct {
  9. Description string
  10. StartLine int
  11. EndLine int
  12. StartColumn int
  13. EndColumn int
  14. Match string
  15. // Secret contains the full content of what is matched in
  16. // the tree-sitter query.
  17. Secret string
  18. // File is the name of the file containing the finding
  19. File string
  20. Commit string
  21. // Entropy is the shannon entropy of Value
  22. Entropy float32
  23. Author string
  24. Email string
  25. Date string
  26. Message string
  27. Tags []string
  28. // Rule is the name of the rule that was matched
  29. RuleID string
  30. }
  31. // Redact removes sensitive information from a finding.
  32. func (f *Finding) Redact() {
  33. f.Match = strings.Replace(f.Match, f.Secret, "REDACTED", -1)
  34. f.Secret = "REDACT"
  35. }
  36. func (f *Finding) Hash() string {
  37. return f.Secret + f.Commit +
  38. strconv.Itoa(f.EndLine) +
  39. strconv.Itoa(f.StartLine)
  40. }