Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add algolia key support #866

Merged
merged 3 commits into from
May 25, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feat: add algolia key to generator
  • Loading branch information
SimonGurney committed May 6, 2022
commit f3df0c5ae3fd840710973cbb463abfcbe0b1f44d
1 change: 1 addition & 0 deletions cmd/generate/config/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ func main() {
configRules = append(configRules, rules.AdobeClientID())
configRules = append(configRules, rules.AdobeClientSecret())
configRules = append(configRules, rules.AgeSecretKey())
configRules = append(configRules, rules.AlgoliaApiKey())
configRules = append(configRules, rules.AlibabaAccessKey())
configRules = append(configRules, rules.AlibabaSecretKey())
configRules = append(configRules, rules.AsanaClientID())
Expand Down
23 changes: 23 additions & 0 deletions cmd/generate/config/rules/algolia.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package rules

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

func AlgoliaApiKey() *config.Rule {
// define rule
r := config.Rule{
Description: "Algolia API Key",
RuleID: "algolia-api-key",
Regex: generateUniqueTokenRegex(`[a-z0-9]{32}`),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SimonGurney this should use generateSemiGenericRegex since the algolia token does not have any unique prefix/suffix that is part of the rule. This will slightly change the generated regular expression.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmmm, I thought the opposite was true... It has no unique suffix/prefix so would use the unique token regex rather than generateSemiGenericRegex which wants unique identifiers?

I must have misread it.

I can't compile the go to test, I'll have to leave it you

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It has no unique suffix/prefix so would use the unique token regex

Using the generateUniqueTokenRegex means the regular expression can be less strict as there are uniquely identifiable patterns within the token. Using generateSemiGenericRegex means that the token follows a generic api token format like a 32 alphanumeric character sequence in this case.

I must have misread it.

No worries, this functionality isn't really documented anywhere and is a work in progress. The config generation cmd was really just a forcing function for me to finally get the default gitleaks rules in order.

I can't compile the go to test, I'll have to leave it you

I can merge this as is then update the code so you get contribution credit if you'd like

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds like a plan 👍

Keywords: []string{"algolia"},
}

// validate
tps := []string{
"algolia_key := " + secrets.NewSecret(hex("32")),
}
return validate(r, tps, nil)
}