Skip to content

Commit

Permalink
feat: add PrivateAI rule (#1548)
Browse files Browse the repository at this point in the history
  • Loading branch information
rgmz authored Oct 6, 2024
1 parent 445abe3 commit 00bb821
Show file tree
Hide file tree
Showing 3 changed files with 43 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 @@ -153,6 +153,7 @@ func main() {
rules.PlanetScaleOAuthToken(),
rules.PostManAPI(),
rules.Prefect(),
rules.PrivateAIToken(),
rules.PrivateKey(),
rules.PulumiAPIToken(),
rules.PyPiUploadToken(),
Expand Down
31 changes: 31 additions & 0 deletions cmd/generate/config/rules/privateai.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package rules

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

func PrivateAIToken() *config.Rule {
// https://docs.private-ai.com/reference/latest/operation/metrics_metrics_get/
r := config.Rule{
RuleID: "privateai-api-token",
Description: "Identified a PrivateAI Token, posing a risk of unauthorized access to AI services and data manipulation.",
Regex: utils.GenerateSemiGenericRegex([]string{"private[_-]?ai"}, `[a-z0-9]{32}`, false),
Entropy: 3,
Keywords: []string{
"privateai",
"private_ai",
"private-ai",
},
}

// validate
tps := []string{
utils.GenerateSampleSecret("privateai", secrets.NewSecret(utils.AlphaNumeric("32"))),
}
fps := []string{
`const privateaiToken = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";`,
}
return utils.Validate(r, tps, fps)
}
11 changes: 11 additions & 0 deletions config/gitleaks.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2426,6 +2426,17 @@ description = "Identified a Private Key, which may compromise cryptographic secu
regex = '''(?i)-----BEGIN[ A-Z0-9_-]{0,100}PRIVATE KEY(?: BLOCK)?-----[\s\S-]*?KEY(?: BLOCK)?-----'''
keywords = ["-----begin"]

[[rules]]
id = "privateai-api-token"
description = "Identified a PrivateAI Token, posing a risk of unauthorized access to AI services and data manipulation."
regex = '''(?i:(?:private[_-]?ai)(?:[0-9a-z\-_\t .]{0,20})(?:[\s|']|[\s|"]){0,3})(?:=|>|:{1,3}=|\|\|:|<=|=>|:|\?=)(?:'|\"|\s|=|\x60){0,5}([a-z0-9]{32})(?:['|\"|\n|\r|\s|\x60|;]|$)'''
entropy = 3
keywords = [
"privateai",
"private_ai",
"private-ai",
]

[[rules]]
id = "pulumi-api-token"
description = "Found a Pulumi API token, posing a risk to infrastructure as code services and cloud resource management."
Expand Down

0 comments on commit 00bb821

Please sign in to comment.