nuget.go 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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 NugetConfigPassword() *config.Rule {
  8. r := config.Rule{
  9. Description: "Identified a password within a Nuget config file, potentially compromising package management access.",
  10. RuleID: "nuget-config-password",
  11. Regex: regexp.MustCompile(`(?i)<add key=\"(?:(?:ClearText)?Password)\"\s*value=\"(.{8,})\"\s*/>`),
  12. Path: regexp.MustCompile(`(?i)nuget\.config$`),
  13. Keywords: []string{"<add key="},
  14. Entropy: 1,
  15. Allowlists: []*config.Allowlist{
  16. {
  17. Regexes: []*regexp.Regexp{
  18. // samples from https://learn.microsoft.com/en-us/nuget/reference/nuget-config-file
  19. regexp.MustCompile(`33f!!lloppa`),
  20. regexp.MustCompile(`hal\+9ooo_da!sY`),
  21. // exclude environment variables
  22. regexp.MustCompile(`^\%\S.*\%$`),
  23. },
  24. },
  25. },
  26. }
  27. tps := map[string]string{
  28. "nuget.config": `<add key="Password" value="CleartextPassword1" />`,
  29. "Nuget.config": `<add key="ClearTextPassword" value="CleartextPassword1" />`,
  30. "Nuget.Config": `<add key="ClearTextPassword" value="TestSourcePassword" />`,
  31. "Nuget.COnfig": `<add key="ClearTextPassword" value="TestSource-Password" />`,
  32. "Nuget.CONfig": `<add key="ClearTextPassword" value="TestSource%Password" />`,
  33. "Nuget.CONFig": `<add key="ClearTextPassword" value="TestSource%Password%" />`,
  34. }
  35. fps := map[string]string{
  36. "some.xml": `<add key="Password" value="CleartextPassword1" />`, // wrong filename
  37. "nuget.config": `<add key="ClearTextPassword" value="XXXXXXXXXXX" />`, // low entropy
  38. "Nuget.config": `<add key="ClearTextPassword" value="abc" />`, // too short
  39. "Nuget.Config": `<add key="ClearTextPassword" value="%TestSourcePassword%" />`, // environment variable
  40. "NUget.Config": `<add key="ClearTextPassword" value="33f!!lloppa" />`, // known sample
  41. "NUGet.Config": `<add key="ClearTextPassword" value="hal+9ooo_da!sY" />`, // known sample
  42. }
  43. return utils.ValidateWithPaths(r, tps, fps)
  44. }