mirror of
https://github.com/gitleaks/gitleaks.git
synced 2026-11-29 20:54:22 +01:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
107a41827b | ||
|
|
7fac002325 | ||
|
|
4b541044e8 | ||
|
|
af7d5bcb83 | ||
|
|
3e8cd2d1ab | ||
|
|
ddcc75371f | ||
|
|
9708e65c25 | ||
|
|
198e41051e | ||
|
|
e273a970a4 | ||
|
|
a503b583ba | ||
|
|
d5c275d6b2 |
No files matched your search
+3
-1
@@ -15,8 +15,10 @@ builds:
|
|||||||
goarm:
|
goarm:
|
||||||
- "6"
|
- "6"
|
||||||
- "7"
|
- "7"
|
||||||
|
tags:
|
||||||
|
- gore2regex
|
||||||
ldflags:
|
ldflags:
|
||||||
- -tags=gore2regex -s -w -X=github.com/zricethezav/gitleaks/v8/cmd.Version={{.Version}}
|
- -s -w -X=github.com/zricethezav/gitleaks/v8/cmd.Version={{.Version}}
|
||||||
archives:
|
archives:
|
||||||
- builds: [gitleaks]
|
- builds: [gitleaks]
|
||||||
format_overrides:
|
format_overrides:
|
||||||
|
|||||||
@@ -113,7 +113,7 @@ jobs:
|
|||||||
```
|
```
|
||||||
repos:
|
repos:
|
||||||
- repo: https://github.com/gitleaks/gitleaks
|
- repo: https://github.com/gitleaks/gitleaks
|
||||||
rev: v8.23.1
|
rev: v8.24.2
|
||||||
hooks:
|
hooks:
|
||||||
- id: gitleaks
|
- id: gitleaks
|
||||||
```
|
```
|
||||||
@@ -157,8 +157,9 @@ Flags:
|
|||||||
order of precedence:
|
order of precedence:
|
||||||
1. --config/-c
|
1. --config/-c
|
||||||
2. env var GITLEAKS_CONFIG
|
2. env var GITLEAKS_CONFIG
|
||||||
3. (target path)/.gitleaks.toml
|
3. env var GITLEAKS_CONFIG_TOML with the file content
|
||||||
If none of the three options are used, then gitleaks will use the default config
|
4. (target path)/.gitleaks.toml
|
||||||
|
If none of the four options are used, then gitleaks will use the default config
|
||||||
--enable-rule strings only enable specific rules by id
|
--enable-rule strings only enable specific rules by id
|
||||||
--exit-code int exit code when leaks have been encountered (default 1)
|
--exit-code int exit code when leaks have been encountered (default 1)
|
||||||
-i, --gitleaks-ignore-path string path to .gitleaksignore file or folder containing one (default ".")
|
-i, --gitleaks-ignore-path string path to .gitleaksignore file or folder containing one (default ".")
|
||||||
@@ -223,6 +224,31 @@ After running the detect command with the --baseline-path parameter, report outp
|
|||||||
You can run Gitleaks as a pre-commit hook by copying the example `pre-commit.py` script into
|
You can run Gitleaks as a pre-commit hook by copying the example `pre-commit.py` script into
|
||||||
your `.git/hooks/` directory.
|
your `.git/hooks/` directory.
|
||||||
|
|
||||||
|
## Load Configuration
|
||||||
|
|
||||||
|
The order of precedence is:
|
||||||
|
|
||||||
|
1. `--config/-c` option:
|
||||||
|
```bash
|
||||||
|
gitleaks git --config /home/dev/customgitleaks.toml .
|
||||||
|
```
|
||||||
|
2. Environment variable `GITLEAKS_CONFIG` with the file path:
|
||||||
|
```bash
|
||||||
|
export GITLEAKS_CONFIG="/home/dev/customgitleaks.toml"
|
||||||
|
gitleaks git .
|
||||||
|
```
|
||||||
|
3. Environment variable `GITLEAKS_CONFIG_TOML` with the file content:
|
||||||
|
```bash
|
||||||
|
export GITLEAKS_CONFIG_TOML=`cat customgitleaks.toml`
|
||||||
|
gitleaks git .
|
||||||
|
```
|
||||||
|
4. A `.gitleaks.toml` file within the target path:
|
||||||
|
```bash
|
||||||
|
gitleaks git .
|
||||||
|
```
|
||||||
|
|
||||||
|
If none of the four options are used, then gitleaks will use the default config.
|
||||||
|
|
||||||
## Configuration
|
## Configuration
|
||||||
|
|
||||||
Gitleaks offers a configuration format you can follow to write your own secret detection rules:
|
Gitleaks offers a configuration format you can follow to write your own secret detection rules:
|
||||||
|
|||||||
@@ -111,6 +111,7 @@ func main() {
|
|||||||
rules.GitlabPipelineTriggerToken(),
|
rules.GitlabPipelineTriggerToken(),
|
||||||
rules.GitlabRunnerRegistrationToken(),
|
rules.GitlabRunnerRegistrationToken(),
|
||||||
rules.GitlabRunnerAuthenticationToken(),
|
rules.GitlabRunnerAuthenticationToken(),
|
||||||
|
rules.GitlabRunnerAuthenticationTokenRoutable(),
|
||||||
rules.GitlabScimToken(),
|
rules.GitlabScimToken(),
|
||||||
rules.GitlabSessionCookie(),
|
rules.GitlabSessionCookie(),
|
||||||
rules.GitterAccessToken(),
|
rules.GitterAccessToken(),
|
||||||
@@ -147,6 +148,7 @@ func main() {
|
|||||||
rules.MailGunSigningKey(),
|
rules.MailGunSigningKey(),
|
||||||
rules.MapBox(),
|
rules.MapBox(),
|
||||||
rules.MattermostAccessToken(),
|
rules.MattermostAccessToken(),
|
||||||
|
rules.MaxMindLicenseKey(),
|
||||||
rules.Meraki(),
|
rules.Meraki(),
|
||||||
rules.MessageBirdAPIToken(),
|
rules.MessageBirdAPIToken(),
|
||||||
rules.MessageBirdClientID(),
|
rules.MessageBirdClientID(),
|
||||||
|
|||||||
@@ -66,6 +66,7 @@ func GenericCredential() *config.Rule {
|
|||||||
`|(?:credentials?[_.-]?id|withCredentials)` + // Jenkins plugins
|
`|(?:credentials?[_.-]?id|withCredentials)` + // Jenkins plugins
|
||||||
// Key
|
// Key
|
||||||
`|(?:bucket|foreign|hot|idx|natural|primary|pub(?:lic)?|schema|sequence)[_.-]?key` +
|
`|(?:bucket|foreign|hot|idx|natural|primary|pub(?:lic)?|schema|sequence)[_.-]?key` +
|
||||||
|
`|(?:turkey)` +
|
||||||
`|key[_.-]?(?:alias|board|code|frame|id|length|mesh|name|pair|press(?:ed)?|ring|selector|signature|size|stone|storetype|word|up|down|left|right)` +
|
`|key[_.-]?(?:alias|board|code|frame|id|length|mesh|name|pair|press(?:ed)?|ring|selector|signature|size|stone|storetype|word|up|down|left|right)` +
|
||||||
// Azure KeyVault
|
// Azure KeyVault
|
||||||
`|key[_.-]?vault[_.-]?(?:id|name)|keyVaultToStoreSecrets` +
|
`|key[_.-]?vault[_.-]?(?:id|name)|keyVaultToStoreSecrets` +
|
||||||
@@ -98,6 +99,8 @@ func GenericCredential() *config.Rule {
|
|||||||
Regexes: []*regexp.Regexp{
|
Regexes: []*regexp.Regexp{
|
||||||
// Docker build secrets (https://docs.docker.com/build/building/secrets/#using-build-secrets).
|
// Docker build secrets (https://docs.docker.com/build/building/secrets/#using-build-secrets).
|
||||||
regexp.MustCompile(`--mount=type=secret,`),
|
regexp.MustCompile(`--mount=type=secret,`),
|
||||||
|
// https://github.com/gitleaks/gitleaks/issues/1800
|
||||||
|
regexp.MustCompile(`import[ \t]+{[ \t\w,]+}[ \t]+from[ \t]+['"][^'"]+['"]`),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -224,6 +227,9 @@ _LIBCPP_CONSTEXPR_AFTER_CXX11 `,
|
|||||||
`BlindKeySignatures = Ed25519.BlindKeySignatures`,
|
`BlindKeySignatures = Ed25519.BlindKeySignatures`,
|
||||||
`AVEncVideoMaxKeyframeDistance, "2987123a-ba93-4704-b489-ec1e5f25292c"`,
|
`AVEncVideoMaxKeyframeDistance, "2987123a-ba93-4704-b489-ec1e5f25292c"`,
|
||||||
` keyPressed = kVK_Return.u16`,
|
` keyPressed = kVK_Return.u16`,
|
||||||
|
`timezone_mapping = {
|
||||||
|
"Turkey Standard Time": "Europe/Istanbul",
|
||||||
|
}`, // https://github.com/gitleaks/gitleaks/issues/1799
|
||||||
// `<add key="SchemaTable" value="G:\SchemaTable.xml" />`,
|
// `<add key="SchemaTable" value="G:\SchemaTable.xml" />`,
|
||||||
//` { key: '9df21e95-3848-409d-8f94-c675cdfee839', value: 'Americas' },`,
|
//` { key: '9df21e95-3848-409d-8f94-c675cdfee839', value: 'Americas' },`,
|
||||||
// `<TAR key="REF_ID_923.properties" value="/opts/config/alias/"/>`,
|
// `<TAR key="REF_ID_923.properties" value="/opts/config/alias/"/>`,
|
||||||
@@ -265,6 +271,7 @@ R5: Regulatory--21`,
|
|||||||
DYNATRACE_API_KEY=`,
|
DYNATRACE_API_KEY=`,
|
||||||
`snowflake.password=
|
`snowflake.password=
|
||||||
jdbc.snowflake.url=`,
|
jdbc.snowflake.url=`,
|
||||||
|
`import { chain_Anvil1_Key, chain_Anvil2_Key } from '../blockchain-tests/pallets/supported-chains/consts';`,
|
||||||
|
|
||||||
// Yocto/BitBake
|
// Yocto/BitBake
|
||||||
`SRCREV_moby = "43fc912ef59a83054ea7f6706df4d53a7dea4d80"`,
|
`SRCREV_moby = "43fc912ef59a83054ea7f6706df4d53a7dea4d80"`,
|
||||||
|
|||||||
@@ -177,6 +177,23 @@ func GitlabRunnerAuthenticationToken() *config.Rule {
|
|||||||
return utils.Validate(r, tps, nil)
|
return utils.Validate(r, tps, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GitlabRunnerAuthenticationTokenRoutable() *config.Rule {
|
||||||
|
r := config.Rule{
|
||||||
|
RuleID: "gitlab-runner-authentication-token-routable",
|
||||||
|
Description: "Discovered a GitLab Runner Authentication Token (Routable), posing a risk to CI/CD pipeline integrity and unauthorized access.",
|
||||||
|
Regex: regexp.MustCompile(`\bglrt-t\d_[0-9a-zA-Z_\-]{27,300}\.[0-9a-z]{2}[0-9a-z]{7}\b`),
|
||||||
|
Entropy: 4,
|
||||||
|
Keywords: []string{"glrt-"},
|
||||||
|
}
|
||||||
|
|
||||||
|
tps := utils.GenerateSampleSecrets("gitlab", "glrt-t"+secrets.NewSecret(utils.Numeric("1"))+"_"+secrets.NewSecret(utils.AlphaNumeric("27"))+"."+secrets.NewSecret(utils.AlphaNumeric("2"))+secrets.NewSecret(utils.AlphaNumeric("7")))
|
||||||
|
fps := []string{
|
||||||
|
"glrt-tx_xxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxx",
|
||||||
|
}
|
||||||
|
|
||||||
|
return utils.Validate(r, tps, fps)
|
||||||
|
}
|
||||||
|
|
||||||
func GitlabScimToken() *config.Rule {
|
func GitlabScimToken() *config.Rule {
|
||||||
r := config.Rule{
|
r := config.Rule{
|
||||||
RuleID: "gitlab-scim-token",
|
RuleID: "gitlab-scim-token",
|
||||||
|
|||||||
@@ -0,0 +1,21 @@
|
|||||||
|
package rules
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/zricethezav/gitleaks/v8/cmd/generate/config/utils"
|
||||||
|
"github.com/zricethezav/gitleaks/v8/config"
|
||||||
|
)
|
||||||
|
|
||||||
|
func MaxMindLicenseKey() *config.Rule {
|
||||||
|
// define rule
|
||||||
|
r := config.Rule{
|
||||||
|
RuleID: "maxmind-license-key",
|
||||||
|
Description: "Discovered a potential MaxMind license key.",
|
||||||
|
Regex: utils.GenerateUniqueTokenRegex(`[A-Za-z0-9]{6}_[A-Za-z0-9]{29}_mmk`, false),
|
||||||
|
Entropy: 4,
|
||||||
|
Keywords: []string{"_mmk"},
|
||||||
|
}
|
||||||
|
|
||||||
|
// validate
|
||||||
|
tps := utils.GenerateSampleSecrets("maxmind", `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`) // gitleaks:allow
|
||||||
|
return utils.Validate(r, tps, nil)
|
||||||
|
}
|
||||||
@@ -11,7 +11,7 @@ func OpenAI() *config.Rule {
|
|||||||
r := config.Rule{
|
r := config.Rule{
|
||||||
RuleID: "openai-api-key",
|
RuleID: "openai-api-key",
|
||||||
Description: "Found an OpenAI API Key, posing a risk of unauthorized access to AI services and data manipulation.",
|
Description: "Found an OpenAI API Key, posing a risk of unauthorized access to AI services and data manipulation.",
|
||||||
Regex: utils.GenerateUniqueTokenRegex(`sk-[a-zA-Z0-9]{20}T3BlbkFJ[a-zA-Z0-9]{20}`, false),
|
Regex: utils.GenerateUniqueTokenRegex(`sk-(?:proj|svcacct|admin)-(?:[A-Za-z0-9_-]{74}|[A-Za-z0-9_-]{58})T3BlbkFJ(?:[A-Za-z0-9_-]{74}|[A-Za-z0-9_-]{58})\b|sk-[a-zA-Z0-9]{20}T3BlbkFJ[a-zA-Z0-9]{20}`, false),
|
||||||
Entropy: 3,
|
Entropy: 3,
|
||||||
Keywords: []string{
|
Keywords: []string{
|
||||||
"T3BlbkFJ",
|
"T3BlbkFJ",
|
||||||
@@ -19,6 +19,19 @@ func OpenAI() *config.Rule {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// validate
|
// validate
|
||||||
tps := utils.GenerateSampleSecrets("openaiApiKey", "sk-"+secrets.NewSecret(utils.AlphaNumeric("20"))+"T3BlbkFJ"+secrets.NewSecret(utils.AlphaNumeric("20")))
|
tps := append(utils.GenerateSampleSecrets("openaiApiKey", "sk-"+secrets.NewSecret(utils.AlphaNumeric("20"))+"T3BlbkFJ"+secrets.NewSecret(utils.AlphaNumeric("20"))),
|
||||||
|
[]string{
|
||||||
|
"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",
|
||||||
|
"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",
|
||||||
|
"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",
|
||||||
|
|
||||||
|
"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",
|
||||||
|
"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",
|
||||||
|
"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",
|
||||||
|
|
||||||
|
"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",
|
||||||
|
"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",
|
||||||
|
"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",
|
||||||
|
}...)
|
||||||
return utils.Validate(r, tps, nil)
|
return utils.Validate(r, tps, nil)
|
||||||
}
|
}
|
||||||
@@ -272,7 +272,7 @@ func SlackWebHookUrl() *config.Rule {
|
|||||||
Description: "Discovered a Slack Webhook, which could lead to unauthorized message posting and data leakage in Slack channels.",
|
Description: "Discovered a Slack Webhook, which could lead to unauthorized message posting and data leakage in Slack channels.",
|
||||||
// If this generates too many false-positives we should define an allowlist (e.g., "xxxx", "00000").
|
// If this generates too many false-positives we should define an allowlist (e.g., "xxxx", "00000").
|
||||||
Regex: regexp.MustCompile(
|
Regex: regexp.MustCompile(
|
||||||
`(?:https?://)?hooks.slack.com/(?:services|workflows)/[A-Za-z0-9+/]{43,46}`),
|
`(?:https?://)?hooks.slack.com/(?:services|workflows|triggers)/[A-Za-z0-9+/]{43,56}`),
|
||||||
Keywords: []string{
|
Keywords: []string{
|
||||||
"hooks.slack.com",
|
"hooks.slack.com",
|
||||||
},
|
},
|
||||||
@@ -290,6 +290,7 @@ func SlackWebHookUrl() *config.Rule {
|
|||||||
"https://hooks.slack.com/workflows/" + secrets.NewSecret(utils.AlphaNumeric("46")),
|
"https://hooks.slack.com/workflows/" + secrets.NewSecret(utils.AlphaNumeric("46")),
|
||||||
"https://hooks.slack.com/workflows/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", // gitleaks:allow
|
"https://hooks.slack.com/workflows/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", // gitleaks:allow
|
||||||
"http://hooks.slack.com/workflows/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", // gitleaks:allow
|
"http://hooks.slack.com/workflows/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", // gitleaks:allow
|
||||||
|
"https://hooks.slack.com/triggers/" + secrets.NewSecret(utils.AlphaNumeric("56")),
|
||||||
}
|
}
|
||||||
return utils.Validate(r, tps, nil)
|
return utils.Validate(r, tps, nil)
|
||||||
}
|
}
|
||||||
+14
-5
@@ -1,6 +1,7 @@
|
|||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
@@ -33,8 +34,9 @@ const configDescription = `config file path
|
|||||||
order of precedence:
|
order of precedence:
|
||||||
1. --config/-c
|
1. --config/-c
|
||||||
2. env var GITLEAKS_CONFIG
|
2. env var GITLEAKS_CONFIG
|
||||||
3. (target path)/.gitleaks.toml
|
3. env var GITLEAKS_CONFIG_TOML with the file content
|
||||||
If none of the three options are used, then gitleaks will use the default config`
|
4. (target path)/.gitleaks.toml
|
||||||
|
If none of the four options are used, then gitleaks will use the default config`
|
||||||
|
|
||||||
var rootCmd = &cobra.Command{
|
var rootCmd = &cobra.Command{
|
||||||
Use: "gitleaks",
|
Use: "gitleaks",
|
||||||
@@ -104,6 +106,8 @@ func initLog() {
|
|||||||
|
|
||||||
func initConfig(source string) {
|
func initConfig(source string) {
|
||||||
hideBanner, err := rootCmd.Flags().GetBool("no-banner")
|
hideBanner, err := rootCmd.Flags().GetBool("no-banner")
|
||||||
|
viper.SetConfigType("toml")
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logging.Fatal().Msg(err.Error())
|
logging.Fatal().Msg(err.Error())
|
||||||
}
|
}
|
||||||
@@ -124,6 +128,13 @@ func initConfig(source string) {
|
|||||||
envPath := os.Getenv("GITLEAKS_CONFIG")
|
envPath := os.Getenv("GITLEAKS_CONFIG")
|
||||||
viper.SetConfigFile(envPath)
|
viper.SetConfigFile(envPath)
|
||||||
logging.Debug().Msgf("using gitleaks config from GITLEAKS_CONFIG env var: %s", envPath)
|
logging.Debug().Msgf("using gitleaks config from GITLEAKS_CONFIG env var: %s", envPath)
|
||||||
|
} else if os.Getenv("GITLEAKS_CONFIG_TOML") != "" {
|
||||||
|
configContent := []byte(os.Getenv("GITLEAKS_CONFIG_TOML"))
|
||||||
|
if err := viper.ReadConfig(bytes.NewBuffer(configContent)); err != nil {
|
||||||
|
logging.Fatal().Err(err).Str("content", os.Getenv("GITLEAKS_CONFIG_TOML")).Msg("unable to load gitleaks config from GITLEAKS_CONFIG_TOML env var")
|
||||||
|
}
|
||||||
|
logging.Debug().Str("content", os.Getenv("GITLEAKS_CONFIG_TOML")).Msg("using gitleaks config from GITLEAKS_CONFIG_TOML env var content")
|
||||||
|
return
|
||||||
} else {
|
} else {
|
||||||
fileInfo, err := os.Stat(source)
|
fileInfo, err := os.Stat(source)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -133,7 +144,6 @@ func initConfig(source string) {
|
|||||||
if !fileInfo.IsDir() {
|
if !fileInfo.IsDir() {
|
||||||
logging.Debug().Msgf("unable to load gitleaks config from %s since --source=%s is a file, using default config",
|
logging.Debug().Msgf("unable to load gitleaks config from %s since --source=%s is a file, using default config",
|
||||||
filepath.Join(source, ".gitleaks.toml"), source)
|
filepath.Join(source, ".gitleaks.toml"), source)
|
||||||
viper.SetConfigType("toml")
|
|
||||||
if err = viper.ReadConfig(strings.NewReader(config.DefaultConfig)); err != nil {
|
if err = viper.ReadConfig(strings.NewReader(config.DefaultConfig)); err != nil {
|
||||||
logging.Fatal().Msgf("err reading toml %s", err.Error())
|
logging.Fatal().Msgf("err reading toml %s", err.Error())
|
||||||
}
|
}
|
||||||
@@ -142,7 +152,7 @@ func initConfig(source string) {
|
|||||||
|
|
||||||
if _, err := os.Stat(filepath.Join(source, ".gitleaks.toml")); os.IsNotExist(err) {
|
if _, err := os.Stat(filepath.Join(source, ".gitleaks.toml")); os.IsNotExist(err) {
|
||||||
logging.Debug().Msgf("no gitleaks config found in path %s, using default gitleaks config", filepath.Join(source, ".gitleaks.toml"))
|
logging.Debug().Msgf("no gitleaks config found in path %s, using default gitleaks config", filepath.Join(source, ".gitleaks.toml"))
|
||||||
viper.SetConfigType("toml")
|
|
||||||
if err = viper.ReadConfig(strings.NewReader(config.DefaultConfig)); err != nil {
|
if err = viper.ReadConfig(strings.NewReader(config.DefaultConfig)); err != nil {
|
||||||
logging.Fatal().Msgf("err reading default config toml %s", err.Error())
|
logging.Fatal().Msgf("err reading default config toml %s", err.Error())
|
||||||
}
|
}
|
||||||
@@ -153,7 +163,6 @@ func initConfig(source string) {
|
|||||||
|
|
||||||
viper.AddConfigPath(source)
|
viper.AddConfigPath(source)
|
||||||
viper.SetConfigName(".gitleaks")
|
viper.SetConfigName(".gitleaks")
|
||||||
viper.SetConfigType("toml")
|
|
||||||
}
|
}
|
||||||
if err := viper.ReadInConfig(); err != nil {
|
if err := viper.ReadInConfig(); err != nil {
|
||||||
logging.Fatal().Msgf("unable to load gitleaks config, err: %s", err)
|
logging.Fatal().Msgf("unable to load gitleaks config, err: %s", err)
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ const (
|
|||||||
NoPlatform // Explicitly disable the feature
|
NoPlatform // Explicitly disable the feature
|
||||||
GitHubPlatform
|
GitHubPlatform
|
||||||
GitLabPlatform
|
GitLabPlatform
|
||||||
|
AzureDevOpsPlatform
|
||||||
// TODO: Add others.
|
// TODO: Add others.
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -21,6 +22,7 @@ func (p Platform) String() string {
|
|||||||
"none",
|
"none",
|
||||||
"github",
|
"github",
|
||||||
"gitlab",
|
"gitlab",
|
||||||
|
"azuredevops",
|
||||||
}[p]
|
}[p]
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -34,6 +36,8 @@ func PlatformFromString(s string) (Platform, error) {
|
|||||||
return GitHubPlatform, nil
|
return GitHubPlatform, nil
|
||||||
case "gitlab":
|
case "gitlab":
|
||||||
return GitLabPlatform, nil
|
return GitLabPlatform, nil
|
||||||
|
case "azuredevops":
|
||||||
|
return AzureDevOpsPlatform, nil
|
||||||
default:
|
default:
|
||||||
return UnknownPlatform, fmt.Errorf("invalid scm platform value: %s", s)
|
return UnknownPlatform, fmt.Errorf("invalid scm platform value: %s", s)
|
||||||
}
|
}
|
||||||
|
|||||||
+18
-3
@@ -591,7 +591,7 @@ regexes = [
|
|||||||
[[rules.allowlists]]
|
[[rules.allowlists]]
|
||||||
regexTarget = "match"
|
regexTarget = "match"
|
||||||
regexes = [
|
regexes = [
|
||||||
'''(?i)(?:access(?:ibility|or)|access[_.-]?id|random[_.-]?access|api[_.-]?(?:id|name|version)|rapid|capital|[a-z0-9-]*?api[a-z0-9-]*?:jar:|author|X-MS-Exchange-Organization-Auth|Authentication-Results|(?:credentials?[_.-]?id|withCredentials)|(?:bucket|foreign|hot|idx|natural|primary|pub(?:lic)?|schema|sequence)[_.-]?key|key[_.-]?(?:alias|board|code|frame|id|length|mesh|name|pair|press(?:ed)?|ring|selector|signature|size|stone|storetype|word|up|down|left|right)|key[_.-]?vault[_.-]?(?:id|name)|keyVaultToStoreSecrets|key(?:store|tab)[_.-]?(?:file|path)|issuerkeyhash|(?-i:[DdMm]onkey|[DM]ONKEY)|keying|(?:secret)[_.-]?(?:length|name|size)|UserSecretsId|(?:csrf)[_.-]?token|(?:io\.jsonwebtoken[ \t]?:[ \t]?[\w-]+)|(?:api|credentials|token)[_.-]?(?:endpoint|ur[il])|public[_.-]?token|(?:key|token)[_.-]?file|(?-i:(?:[A-Z_]+=\n[A-Z_]+=|[a-z_]+=\n[a-z_]+=)(?:\n|\z))|(?-i:(?:[A-Z.]+=\n[A-Z.]+=|[a-z.]+=\n[a-z.]+=)(?:\n|\z)))''',
|
'''(?i)(?:access(?:ibility|or)|access[_.-]?id|random[_.-]?access|api[_.-]?(?:id|name|version)|rapid|capital|[a-z0-9-]*?api[a-z0-9-]*?:jar:|author|X-MS-Exchange-Organization-Auth|Authentication-Results|(?:credentials?[_.-]?id|withCredentials)|(?:bucket|foreign|hot|idx|natural|primary|pub(?:lic)?|schema|sequence)[_.-]?key|(?:turkey)|key[_.-]?(?:alias|board|code|frame|id|length|mesh|name|pair|press(?:ed)?|ring|selector|signature|size|stone|storetype|word|up|down|left|right)|key[_.-]?vault[_.-]?(?:id|name)|keyVaultToStoreSecrets|key(?:store|tab)[_.-]?(?:file|path)|issuerkeyhash|(?-i:[DdMm]onkey|[DM]ONKEY)|keying|(?:secret)[_.-]?(?:length|name|size)|UserSecretsId|(?:csrf)[_.-]?token|(?:io\.jsonwebtoken[ \t]?:[ \t]?[\w-]+)|(?:api|credentials|token)[_.-]?(?:endpoint|ur[il])|public[_.-]?token|(?:key|token)[_.-]?file|(?-i:(?:[A-Z_]+=\n[A-Z_]+=|[a-z_]+=\n[a-z_]+=)(?:\n|\z))|(?-i:(?:[A-Z.]+=\n[A-Z.]+=|[a-z.]+=\n[a-z.]+=)(?:\n|\z)))''',
|
||||||
]
|
]
|
||||||
stopwords = [
|
stopwords = [
|
||||||
"000000",
|
"000000",
|
||||||
@@ -2076,6 +2076,7 @@ stopwords = [
|
|||||||
regexTarget = "line"
|
regexTarget = "line"
|
||||||
regexes = [
|
regexes = [
|
||||||
'''--mount=type=secret,''',
|
'''--mount=type=secret,''',
|
||||||
|
'''import[ \t]+{[ \t\w,]+}[ \t]+from[ \t]+['"][^'"]+['"]''',
|
||||||
]
|
]
|
||||||
[[rules.allowlists]]
|
[[rules.allowlists]]
|
||||||
condition = "AND"
|
condition = "AND"
|
||||||
@@ -2219,6 +2220,13 @@ regex = '''glrt-[0-9a-zA-Z_\-]{20}'''
|
|||||||
entropy = 3
|
entropy = 3
|
||||||
keywords = ["glrt-"]
|
keywords = ["glrt-"]
|
||||||
|
|
||||||
|
[[rules]]
|
||||||
|
id = "gitlab-runner-authentication-token-routable"
|
||||||
|
description = "Discovered a GitLab Runner Authentication Token (Routable), posing a risk to CI/CD pipeline integrity and unauthorized access."
|
||||||
|
regex = '''\bglrt-t\d_[0-9a-zA-Z_\-]{27,300}\.[0-9a-z]{2}[0-9a-z]{7}\b'''
|
||||||
|
entropy = 4
|
||||||
|
keywords = ["glrt-"]
|
||||||
|
|
||||||
[[rules]]
|
[[rules]]
|
||||||
id = "gitlab-scim-token"
|
id = "gitlab-scim-token"
|
||||||
description = "Discovered a GitLab SCIM Token, posing a risk to unauthorized access for a organization or instance."
|
description = "Discovered a GitLab SCIM Token, posing a risk to unauthorized access for a organization or instance."
|
||||||
@@ -2513,6 +2521,13 @@ description = "Identified a Mattermost Access Token, which may compromise team c
|
|||||||
regex = '''(?i)[\w.-]{0,50}?(?:mattermost)(?:[ \t\w.-]{0,20})[\s'"]{0,3}(?:=|>|:{1,3}=|\|\||:|=>|\?=|,)[\x60'"\s=]{0,5}([a-z0-9]{26})(?:[\x60'"\s;]|\\[nr]|$)'''
|
regex = '''(?i)[\w.-]{0,50}?(?:mattermost)(?:[ \t\w.-]{0,20})[\s'"]{0,3}(?:=|>|:{1,3}=|\|\||:|=>|\?=|,)[\x60'"\s=]{0,5}([a-z0-9]{26})(?:[\x60'"\s;]|\\[nr]|$)'''
|
||||||
keywords = ["mattermost"]
|
keywords = ["mattermost"]
|
||||||
|
|
||||||
|
[[rules]]
|
||||||
|
id = "maxmind-license-key"
|
||||||
|
description = "Discovered a potential MaxMind license key."
|
||||||
|
regex = '''\b([A-Za-z0-9]{6}_[A-Za-z0-9]{29}_mmk)(?:[\x60'"\s;]|\\[nr]|$)'''
|
||||||
|
entropy = 4
|
||||||
|
keywords = ["_mmk"]
|
||||||
|
|
||||||
[[rules]]
|
[[rules]]
|
||||||
id = "messagebird-api-token"
|
id = "messagebird-api-token"
|
||||||
description = "Found a MessageBird API token, risking unauthorized access to communication platforms and message data."
|
description = "Found a MessageBird API token, risking unauthorized access to communication platforms and message data."
|
||||||
@@ -2625,7 +2640,7 @@ keywords = ["okta"]
|
|||||||
[[rules]]
|
[[rules]]
|
||||||
id = "openai-api-key"
|
id = "openai-api-key"
|
||||||
description = "Found an OpenAI API Key, posing a risk of unauthorized access to AI services and data manipulation."
|
description = "Found an OpenAI API Key, posing a risk of unauthorized access to AI services and data manipulation."
|
||||||
regex = '''\b(sk-[a-zA-Z0-9]{20}T3BlbkFJ[a-zA-Z0-9]{20})(?:[\x60'"\s;]|\\[nr]|$)'''
|
regex = '''\b(sk-(?:proj|svcacct|admin)-(?:[A-Za-z0-9_-]{74}|[A-Za-z0-9_-]{58})T3BlbkFJ(?:[A-Za-z0-9_-]{74}|[A-Za-z0-9_-]{58})\b|sk-[a-zA-Z0-9]{20}T3BlbkFJ[a-zA-Z0-9]{20})(?:[\x60'"\s;]|\\[nr]|$)'''
|
||||||
entropy = 3
|
entropy = 3
|
||||||
keywords = ["t3blbkfj"]
|
keywords = ["t3blbkfj"]
|
||||||
|
|
||||||
@@ -2946,7 +2961,7 @@ keywords = [
|
|||||||
[[rules]]
|
[[rules]]
|
||||||
id = "slack-webhook-url"
|
id = "slack-webhook-url"
|
||||||
description = "Discovered a Slack Webhook, which could lead to unauthorized message posting and data leakage in Slack channels."
|
description = "Discovered a Slack Webhook, which could lead to unauthorized message posting and data leakage in Slack channels."
|
||||||
regex = '''(?:https?://)?hooks.slack.com/(?:services|workflows)/[A-Za-z0-9+/]{43,46}'''
|
regex = '''(?:https?://)?hooks.slack.com/(?:services|workflows|triggers)/[A-Za-z0-9+/]{43,56}'''
|
||||||
keywords = ["hooks.slack.com"]
|
keywords = ["hooks.slack.com"]
|
||||||
|
|
||||||
[[rules]]
|
[[rules]]
|
||||||
|
|||||||
+12
-9
@@ -280,24 +280,27 @@ func segmentWithDecodedOverlap(encodedSegments []EncodedSegment, start, end int)
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s EncodedSegment) lineStartIndex(currentRaw string) int {
|
func (s EncodedSegment) currentLine(currentRaw string) string {
|
||||||
|
start := 0
|
||||||
|
end := len(currentRaw)
|
||||||
|
|
||||||
|
// Find the start of the range
|
||||||
for i := s.decodedStart; i > -1; i-- {
|
for i := s.decodedStart; i > -1; i-- {
|
||||||
c := currentRaw[i]
|
c := currentRaw[i]
|
||||||
if c == '\n' {
|
if c == '\n' {
|
||||||
return i
|
start = i
|
||||||
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0
|
// Find the end of the range
|
||||||
}
|
for i := s.decodedEnd; i < end; i++ {
|
||||||
|
|
||||||
func (s EncodedSegment) lineEndIndex(currentRaw string, matchLen int) int {
|
|
||||||
for i := s.decodedStart; i < s.decodedStart+matchLen; i++ {
|
|
||||||
c := currentRaw[i]
|
c := currentRaw[i]
|
||||||
if c == '\n' {
|
if c == '\n' {
|
||||||
return i
|
end = i
|
||||||
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return len(currentRaw) - 1
|
return currentRaw[start:end]
|
||||||
}
|
}
|
||||||
+1
-1
@@ -392,7 +392,7 @@ MatchLoop:
|
|||||||
if segment := segmentWithDecodedOverlap(encodedSegments, matchIndex[0], matchIndex[1]); segment != nil {
|
if segment := segmentWithDecodedOverlap(encodedSegments, matchIndex[0], matchIndex[1]); segment != nil {
|
||||||
matchIndex = segment.adjustMatchIndex(matchIndex)
|
matchIndex = segment.adjustMatchIndex(matchIndex)
|
||||||
metaTags = append(metaTags, segment.tags()...)
|
metaTags = append(metaTags, segment.tags()...)
|
||||||
currentLine = currentRaw[segment.lineStartIndex(currentRaw):segment.lineEndIndex(currentRaw, matchIndex[1]-matchIndex[0])]
|
currentLine = segment.currentLine(currentRaw)
|
||||||
} else {
|
} else {
|
||||||
// This item has already been added to a finding
|
// This item has already been added to a finding
|
||||||
continue
|
continue
|
||||||
|
|||||||
@@ -171,6 +171,8 @@ func platformFromHost(u *url.URL) scm.Platform {
|
|||||||
return scm.GitHubPlatform
|
return scm.GitHubPlatform
|
||||||
case "gitlab.com":
|
case "gitlab.com":
|
||||||
return scm.GitLabPlatform
|
return scm.GitLabPlatform
|
||||||
|
case "dev.azure.com", "visualstudio.com":
|
||||||
|
return scm.AzureDevOpsPlatform
|
||||||
default:
|
default:
|
||||||
return scm.UnknownPlatform
|
return scm.UnknownPlatform
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -78,6 +78,18 @@ func createScmLink(scmPlatform scm.Platform, remoteUrl string, finding report.Fi
|
|||||||
link += fmt.Sprintf("-%d", finding.EndLine)
|
link += fmt.Sprintf("-%d", finding.EndLine)
|
||||||
}
|
}
|
||||||
return link
|
return link
|
||||||
|
case scm.AzureDevOpsPlatform:
|
||||||
|
link := fmt.Sprintf("%s/commit/%s?path=/%s", remoteUrl, finding.Commit, filePath)
|
||||||
|
// Add line information if applicable
|
||||||
|
if finding.StartLine != 0 {
|
||||||
|
link += fmt.Sprintf("&line=%d", finding.StartLine)
|
||||||
|
}
|
||||||
|
if finding.EndLine != finding.StartLine {
|
||||||
|
link += fmt.Sprintf("&lineEnd=%d", finding.EndLine)
|
||||||
|
}
|
||||||
|
// This is a bit dirty, but Azure DevOps does not highlight the line when the lineStartColumn and lineEndColumn are not provided
|
||||||
|
link += "&lineStartColumn=1&lineEndColumn=10000000&type=2&lineStyle=plain&_a=files"
|
||||||
|
return link
|
||||||
default:
|
default:
|
||||||
// This should never happen.
|
// This should never happen.
|
||||||
return ""
|
return ""
|
||||||
|
|||||||
@@ -91,6 +91,32 @@ func Test_createScmLink(t *testing.T) {
|
|||||||
},
|
},
|
||||||
want: "https://gitlab.com/example-org/example-group/gitleaks/blob/63410f74e23a4e51e1f60b9feb073b5d325af878/.vscode/launchSettings.json#L6-8",
|
want: "https://gitlab.com/example-org/example-group/gitleaks/blob/63410f74e23a4e51e1f60b9feb073b5d325af878/.vscode/launchSettings.json#L6-8",
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// Azure DevOps
|
||||||
|
"azuredevops - single line": {
|
||||||
|
platform: scm.AzureDevOpsPlatform,
|
||||||
|
url: "https://dev.azure.com/exampleorganisation/exampleproject/_git/exampleRepository",
|
||||||
|
finding: report.Finding{
|
||||||
|
Commit: "20553ad96a4a080c94a54d677db97eed8ce2560d",
|
||||||
|
File: "examplefile.json",
|
||||||
|
StartLine: 25,
|
||||||
|
EndLine: 25,
|
||||||
|
},
|
||||||
|
want: "https://dev.azure.com/exampleorganisation/exampleproject/_git/exampleRepository/commit/20553ad96a4a080c94a54d677db97eed8ce2560d?path=/examplefile.json&line=25&lineStartColumn=1&lineEndColumn=10000000&type=2&lineStyle=plain&_a=files",
|
||||||
|
},
|
||||||
|
|
||||||
|
// Azure DevOps
|
||||||
|
"azuredevops - multi line": {
|
||||||
|
platform: scm.AzureDevOpsPlatform,
|
||||||
|
url: "https://dev.azure.com/exampleorganisation/exampleproject/_git/exampleRepository",
|
||||||
|
finding: report.Finding{
|
||||||
|
Commit: "20553ad96a4a080c94a54d677db97eed8ce2560d",
|
||||||
|
File: "examplefile.json",
|
||||||
|
StartLine: 25,
|
||||||
|
EndLine: 30,
|
||||||
|
},
|
||||||
|
want: "https://dev.azure.com/exampleorganisation/exampleproject/_git/exampleRepository/commit/20553ad96a4a080c94a54d677db97eed8ce2560d?path=/examplefile.json&line=25&lineEnd=30&lineStartColumn=1&lineEndColumn=10000000&type=2&lineStyle=plain&_a=files",
|
||||||
|
},
|
||||||
}
|
}
|
||||||
for name, tt := range tests {
|
for name, tt := range tests {
|
||||||
t.Run(name, func(t *testing.T) {
|
t.Run(name, func(t *testing.T) {
|
||||||
|
|||||||
Reference in new issue
Block a user