4
0

freemius.go 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. package rules
  2. import (
  3. "github.com/zricethezav/gitleaks/v8/cmd/generate/config/utils"
  4. "github.com/zricethezav/gitleaks/v8/config"
  5. "github.com/zricethezav/gitleaks/v8/regexp"
  6. )
  7. func Freemius() *config.Rule {
  8. // define rule
  9. r := config.Rule{
  10. RuleID: "freemius-secret-key",
  11. Description: "Detected a Freemius secret key, potentially exposing sensitive information.",
  12. Regex: regexp.MustCompile(`(?i)["']secret_key["']\s*=>\s*["'](sk_[\S]{29})["']`),
  13. Keywords: []string{"secret_key"},
  14. Path: regexp.MustCompile(`(?i)\.php$`),
  15. }
  16. // validate
  17. tps := map[string]string{
  18. "file.php": `$config = array(
  19. "secret_key" => "sk_ubb4yN3mzqGR2x8#P7r5&@*xC$utE",
  20. );`,
  21. }
  22. // It's only used in PHP SDK snippet.
  23. // see https://freemius.com/help/documentation/wordpress-sdk/integrating-freemius-sdk/
  24. fps := map[string]string{
  25. // Invalid format: missing quotes around `secret_key`.
  26. "foo.php": `$config = array(
  27. secret_key => "sk_abcdefghijklmnopqrstuvwxyz123",
  28. );`,
  29. // Invalid format: missing quotes around the key value.
  30. "bar.php": `$config = array(
  31. "secret_key" => sk_abcdefghijklmnopqrstuvwxyz123,
  32. );`,
  33. // Invalid: different key name.
  34. "baz.php": `$config = array(
  35. "other_key" => "sk_abcdefghijklmnopqrstuvwxyz123",
  36. );`,
  37. // Invalid: file extension, should validate only .php files.
  38. "foo.html": `$config = array(
  39. "secret_key" => "sk_ubb4yN3mzqGR2x8#P7r5&@*xC$utE",
  40. );`,
  41. }
  42. return utils.ValidateWithPaths(r, tps, fps)
  43. }