Skip to content

Commit

Permalink
Add detection for OpenAI API keys (gitleaks#1148)
Browse files Browse the repository at this point in the history
* Add detection for OpenAI API keys

* Remove `sk-` keyword
  • Loading branch information
becojo authored Jun 14, 2023
1 parent c101fa8 commit 7dc9ba4
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
1 change: 1 addition & 0 deletions cmd/generate/config/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ func main() {
configRules = append(configRules, rules.NPM())
configRules = append(configRules, rules.NytimesAccessToken())
configRules = append(configRules, rules.OktaAccessToken())
configRules = append(configRules, rules.OpenAI())
configRules = append(configRules, rules.PlaidAccessID())
configRules = append(configRules, rules.PlaidSecretKey())
configRules = append(configRules, rules.PlaidAccessToken())
Expand Down
25 changes: 25 additions & 0 deletions cmd/generate/config/rules/openai.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package rules

import (
"github.com/zricethezav/gitleaks/v8/cmd/generate/secrets"
"github.com/zricethezav/gitleaks/v8/config"
)

func OpenAI() *config.Rule {
// define rule
r := config.Rule{
RuleID: "openai-api-key",
Description: "OpenAI API Key",
Regex: generateUniqueTokenRegex(`sk-[a-zA-Z0-9]{20}T3BlbkFJ[a-zA-Z0-9]{20}`),
SecretGroup: 1,
Keywords: []string{
"T3BlbkFJ",
},
}

// validate
tps := []string{
generateSampleSecret("openaiApiKey", "sk-"+secrets.NewSecret(alphaNumeric("20"))+"T3BlbkFJ"+secrets.NewSecret(alphaNumeric("20"))),
}
return validate(r, tps, nil)
}
9 changes: 9 additions & 0 deletions config/gitleaks.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2371,6 +2371,15 @@ keywords = [
"okta",
]

[[rules]]
description = "OpenAI API Key"
id = "openai-api-key"
regex = '''(?i)\b(sk-[a-zA-Z0-9]{20}T3BlbkFJ[a-zA-Z0-9]{20})(?:['|\"|\n|\r|\s|\x60|;]|$)'''
secretGroup = 1
keywords = [
"sk-","t3blbkfj",
]

[[rules]]
description = "Plaid API Token"
id = "plaid-api-token"
Expand Down

0 comments on commit 7dc9ba4

Please sign in to comment.