anthropic.go 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. package rules
  2. import (
  3. "github.com/zricethezav/gitleaks/v8/cmd/generate/config/utils"
  4. "github.com/zricethezav/gitleaks/v8/cmd/generate/secrets"
  5. "github.com/zricethezav/gitleaks/v8/config"
  6. )
  7. func AnthropicApiKey() *config.Rule {
  8. // define rule
  9. r := config.Rule{
  10. RuleID: "anthropic-api-key",
  11. Description: "Identified an Anthropic API Key, which may compromise AI assistant integrations and expose sensitive data to unauthorized access.",
  12. Regex: utils.GenerateUniqueTokenRegex(`sk-ant-api03-[a-zA-Z0-9_\-]{93}AA`, false),
  13. Keywords: []string{
  14. "sk-ant-api03",
  15. },
  16. }
  17. // validate
  18. tps := []string{
  19. // Valid API key example
  20. "sk-ant-api03-abc123xyz-456def789ghij-klmnopqrstuvwx-3456yza789bcde-1234fghijklmnopby56aaaogaopaaaabc123xyzAA",
  21. // Generate additional random test keys
  22. utils.GenerateSampleSecret("anthropic", "sk-ant-api03-"+secrets.NewSecret(utils.AlphaNumericExtendedShort("93"))+"AA"),
  23. }
  24. fps := []string{
  25. // Too short key (missing characters)
  26. "sk-ant-api03-abc123xyz-456de-klMnopqrstuvwx-3456yza789bcde-1234fghijklmnopAA",
  27. // Wrong suffix
  28. "sk-ant-api03-abc123xyz-456def789ghij-klmnopqrstuvwx-3456yza789bcde-1234fghijklmnopby56aaaogaopaaaabc123xyzBB",
  29. // Wrong prefix (admin key, not API key)
  30. "sk-ant-admin01-abc123xyz-456def789ghij-klmnopqrstuvwx-3456yza789bcde-1234fghijklmnopby56aaaogaopaaaabc123xyzAA",
  31. }
  32. return utils.Validate(r, tps, fps)
  33. }
  34. func AnthropicAdminApiKey() *config.Rule {
  35. // define rule
  36. r := config.Rule{
  37. RuleID: "anthropic-admin-api-key",
  38. Description: "Detected an Anthropic Admin API Key, risking unauthorized access to administrative functions and sensitive AI model configurations.",
  39. Regex: utils.GenerateUniqueTokenRegex(`sk-ant-admin01-[a-zA-Z0-9_\-]{93}AA`, false),
  40. Keywords: []string{
  41. "sk-ant-admin01",
  42. },
  43. }
  44. // validate
  45. tps := []string{
  46. // Valid admin key example
  47. "sk-ant-admin01-abc12fake-456def789ghij-klmnopqrstuvwx-3456yza789bcde-12fakehijklmnopby56aaaogaopaaaabc123xyzAA",
  48. // Generate additional random test keys
  49. utils.GenerateSampleSecret("anthropic", "sk-ant-admin01-"+secrets.NewSecret(utils.AlphaNumericExtendedShort("93"))+"AA"),
  50. }
  51. fps := []string{
  52. // Too short key (missing characters)
  53. "sk-ant-admin01-abc123xyz-456de-klMnopqrstuvwx-3456yza789bcde-1234fghijklmnopAA",
  54. // Wrong suffix
  55. "sk-ant-admin01-abc123xyz-456def789ghij-klmnopqrstuvwx-3456yza789bcde-1234fghijklmnopby56aaaogaopaaaabc123xyzBB",
  56. // Wrong prefix (API key, not admin key)
  57. "sk-ant-api03-abc123xyz-456def789ghij-klmnopqrstuvwx-3456yza789bcde-1234fghijklmnopby56aaaogaopaaaabc123xyzAA",
  58. }
  59. return utils.Validate(r, tps, fps)
  60. }