mirror of
https://github.com/gitleaks/gitleaks.git
synced 2026-11-29 12:44:22 +01:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
128cd22f7c | ||
|
|
1a6d2b0a7a | ||
|
|
0874ebcc3f | ||
|
|
9463ffaa5e |
No files matched your search
@@ -24,6 +24,3 @@ jobs:
|
|||||||
|
|
||||||
- name: Test
|
- name: Test
|
||||||
run: make test
|
run: make test
|
||||||
|
|
||||||
- name: Validate Config
|
|
||||||
run: go generate ./... && git diff --exit-code
|
|
||||||
@@ -208,54 +208,6 @@ gitleaks git --baseline-path gitleaks-report.json --report-path findings.json
|
|||||||
|
|
||||||
After running the detect command with the --baseline-path parameter, report output (findings.json) will only contain new issues.
|
After running the detect command with the --baseline-path parameter, report output (findings.json) will only contain new issues.
|
||||||
|
|
||||||
### Verify Findings
|
|
||||||
|
|
||||||
You can verify a finding found by gitleaks using a `git log` command.
|
|
||||||
Example output:
|
|
||||||
|
|
||||||
```
|
|
||||||
Finding: aws_secret="AKIAIMNOJVGFDXXXE4OA"
|
|
||||||
RuleID: aws-access-token
|
|
||||||
Secret AKIAIMNOJVGFDXXXE4OA
|
|
||||||
Entropy: 3.65
|
|
||||||
File: checks_test.go
|
|
||||||
Line: 37
|
|
||||||
Commit: ec2fc9d6cb0954fb3b57201cf6133c48d8ca0d29
|
|
||||||
Author: Zachary Rice
|
|
||||||
Email: z@email.com
|
|
||||||
Date: 2018-01-28T17:39:00Z
|
|
||||||
Fingerprint: ec2fc9d6cb0954fb3b57201cf6133c48d8ca0d29:checks_test.go:aws-access-token:37
|
|
||||||
```
|
|
||||||
|
|
||||||
We can use the following format to verify the leak:
|
|
||||||
|
|
||||||
```
|
|
||||||
git log -L {StartLine,EndLine}:{File} {Commit}
|
|
||||||
```
|
|
||||||
|
|
||||||
So in this example it would look like:
|
|
||||||
|
|
||||||
```
|
|
||||||
git log -L 37,37:checks_test.go ec2fc9d6cb0954fb3b57201cf6133c48d8ca0d29
|
|
||||||
```
|
|
||||||
|
|
||||||
Which gives us:
|
|
||||||
|
|
||||||
```
|
|
||||||
commit ec2fc9d6cb0954fb3b57201cf6133c48d8ca0d29
|
|
||||||
Author: zricethezav <thisispublicanyways@gmail.com>
|
|
||||||
Date: Sun Jan 28 17:39:00 2018 -0500
|
|
||||||
|
|
||||||
[update] entropy check
|
|
||||||
|
|
||||||
diff --git a/checks_test.go b/checks_test.go
|
|
||||||
--- a/checks_test.go
|
|
||||||
+++ b/checks_test.go
|
|
||||||
@@ -28,0 +37,1 @@
|
|
||||||
+ "aws_secret= \"AKIAIMNOJVGFDXXXE4OA\"": true,
|
|
||||||
|
|
||||||
```
|
|
||||||
|
|
||||||
## Pre-Commit hook
|
## Pre-Commit hook
|
||||||
|
|
||||||
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
|
||||||
|
|||||||
+7
-10
@@ -46,11 +46,13 @@ var detectCmd = &cobra.Command{
|
|||||||
}
|
}
|
||||||
|
|
||||||
func runDetect(cmd *cobra.Command, args []string) {
|
func runDetect(cmd *cobra.Command, args []string) {
|
||||||
initConfig()
|
source, err := cmd.Flags().GetString("source")
|
||||||
var (
|
if err != nil {
|
||||||
findings []report.Finding
|
log.Fatal().Err(err).Msg("could not get source")
|
||||||
err error
|
}
|
||||||
)
|
initConfig(source)
|
||||||
|
|
||||||
|
var findings []report.Finding
|
||||||
|
|
||||||
// setup config (aka, the thing that defines rules)
|
// setup config (aka, the thing that defines rules)
|
||||||
cfg := Config(cmd)
|
cfg := Config(cmd)
|
||||||
@@ -58,11 +60,6 @@ func runDetect(cmd *cobra.Command, args []string) {
|
|||||||
// start timer
|
// start timer
|
||||||
start := time.Now()
|
start := time.Now()
|
||||||
|
|
||||||
// grab source
|
|
||||||
source, err := cmd.Flags().GetString("source")
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal().Err(err).Msg("could not get source")
|
|
||||||
}
|
|
||||||
detector := Detector(cmd, cfg, source)
|
detector := Detector(cmd, cfg, source)
|
||||||
|
|
||||||
// set exit code
|
// set exit code
|
||||||
|
|||||||
+10
-6
@@ -23,7 +23,15 @@ var directoryCmd = &cobra.Command{
|
|||||||
}
|
}
|
||||||
|
|
||||||
func runDirectory(cmd *cobra.Command, args []string) {
|
func runDirectory(cmd *cobra.Command, args []string) {
|
||||||
initConfig()
|
// grab source
|
||||||
|
source := "."
|
||||||
|
if len(args) == 1 {
|
||||||
|
source = args[0]
|
||||||
|
if source == "" {
|
||||||
|
source = "."
|
||||||
|
}
|
||||||
|
}
|
||||||
|
initConfig(source)
|
||||||
var (
|
var (
|
||||||
findings []report.Finding
|
findings []report.Finding
|
||||||
err error
|
err error
|
||||||
@@ -35,11 +43,7 @@ func runDirectory(cmd *cobra.Command, args []string) {
|
|||||||
// start timer
|
// start timer
|
||||||
start := time.Now()
|
start := time.Now()
|
||||||
|
|
||||||
// grab source
|
|
||||||
source, err := cmd.Flags().GetString("source")
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal().Err(err).Msg("could not get source")
|
|
||||||
}
|
|
||||||
detector := Detector(cmd, cfg, source)
|
detector := Detector(cmd, cfg, source)
|
||||||
|
|
||||||
// set exit code
|
// set exit code
|
||||||
|
|||||||
+11
-5
@@ -25,12 +25,22 @@ var gitCmd = &cobra.Command{
|
|||||||
}
|
}
|
||||||
|
|
||||||
func runGit(cmd *cobra.Command, args []string) {
|
func runGit(cmd *cobra.Command, args []string) {
|
||||||
initConfig()
|
|
||||||
var (
|
var (
|
||||||
findings []report.Finding
|
findings []report.Finding
|
||||||
err error
|
err error
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// grab source
|
||||||
|
source := "."
|
||||||
|
if len(args) == 1 {
|
||||||
|
source = args[0]
|
||||||
|
if source == "" {
|
||||||
|
source = "."
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
initConfig(source)
|
||||||
|
|
||||||
// setup config (aka, the thing that defines rules)
|
// setup config (aka, the thing that defines rules)
|
||||||
cfg := Config(cmd)
|
cfg := Config(cmd)
|
||||||
|
|
||||||
@@ -38,10 +48,6 @@ func runGit(cmd *cobra.Command, args []string) {
|
|||||||
start := time.Now()
|
start := time.Now()
|
||||||
|
|
||||||
// grab source
|
// grab source
|
||||||
source, err := cmd.Flags().GetString("source")
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal().Err(err).Msg("could not get source")
|
|
||||||
}
|
|
||||||
detector := Detector(cmd, cfg, source)
|
detector := Detector(cmd, cfg, source)
|
||||||
|
|
||||||
// set exit code
|
// set exit code
|
||||||
|
|||||||
+5
-6
@@ -25,18 +25,17 @@ var protectCmd = &cobra.Command{
|
|||||||
}
|
}
|
||||||
|
|
||||||
func runProtect(cmd *cobra.Command, args []string) {
|
func runProtect(cmd *cobra.Command, args []string) {
|
||||||
initConfig()
|
source, err := cmd.Flags().GetString("source")
|
||||||
var err error
|
if err != nil {
|
||||||
|
log.Fatal().Err(err).Msg("could not get source")
|
||||||
|
}
|
||||||
|
initConfig(source)
|
||||||
|
|
||||||
// setup config (aka, the thing that defines rules)
|
// setup config (aka, the thing that defines rules)
|
||||||
cfg := Config(cmd)
|
cfg := Config(cmd)
|
||||||
|
|
||||||
exitCode, _ := cmd.Flags().GetInt("exit-code")
|
exitCode, _ := cmd.Flags().GetInt("exit-code")
|
||||||
staged, _ := cmd.Flags().GetBool("staged")
|
staged, _ := cmd.Flags().GetBool("staged")
|
||||||
source, err := cmd.Flags().GetString("source")
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal().Err(err).Msg("")
|
|
||||||
}
|
|
||||||
start := time.Now()
|
start := time.Now()
|
||||||
detector := Detector(cmd, cfg, source)
|
detector := Detector(cmd, cfg, source)
|
||||||
|
|
||||||
|
|||||||
+1
-5
@@ -86,7 +86,7 @@ func initLog() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func initConfig() {
|
func initConfig(source string) {
|
||||||
hideBanner, err := rootCmd.Flags().GetBool("no-banner")
|
hideBanner, err := rootCmd.Flags().GetBool("no-banner")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal().Msg(err.Error())
|
log.Fatal().Msg(err.Error())
|
||||||
@@ -106,10 +106,6 @@ func initConfig() {
|
|||||||
viper.SetConfigFile(envPath)
|
viper.SetConfigFile(envPath)
|
||||||
log.Debug().Msgf("using gitleaks config from GITLEAKS_CONFIG env var: %s", envPath)
|
log.Debug().Msgf("using gitleaks config from GITLEAKS_CONFIG env var: %s", envPath)
|
||||||
} else {
|
} else {
|
||||||
source, err := rootCmd.Flags().GetString("source")
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal().Msg(err.Error())
|
|
||||||
}
|
|
||||||
fileInfo, err := os.Stat(source)
|
fileInfo, err := os.Stat(source)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal().Msg(err.Error())
|
log.Fatal().Msg(err.Error())
|
||||||
|
|||||||
+1
-1
@@ -21,7 +21,7 @@ var stdInCmd = &cobra.Command{
|
|||||||
}
|
}
|
||||||
|
|
||||||
func runStdIn(cmd *cobra.Command, args []string) {
|
func runStdIn(cmd *cobra.Command, args []string) {
|
||||||
initConfig()
|
initConfig(".")
|
||||||
var (
|
var (
|
||||||
findings []report.Finding
|
findings []report.Finding
|
||||||
err error
|
err error
|
||||||
|
|||||||
@@ -91,11 +91,11 @@ func TestTranslate(t *testing.T) {
|
|||||||
cfg: Config{},
|
cfg: Config{},
|
||||||
wantError: fmt.Errorf("rule |id| is missing or empty, regex: (?i)(discord[a-z0-9_ .\\-,]{0,25})(=|>|:=|\\|\\|:|<=|=>|:).{0,5}['\\\"]([a-h0-9]{64})['\\\"]"),
|
wantError: fmt.Errorf("rule |id| is missing or empty, regex: (?i)(discord[a-z0-9_ .\\-,]{0,25})(=|>|:=|\\|\\|:|<=|=>|:).{0,5}['\\\"]([a-h0-9]{64})['\\\"]"),
|
||||||
},
|
},
|
||||||
{
|
//{
|
||||||
cfgName: "no_regex_or_path",
|
// cfgName: "no_regex_or_path",
|
||||||
cfg: Config{},
|
// cfg: Config{},
|
||||||
wantError: fmt.Errorf("discord-api-key: both |regex| and |path| are empty, this rule will have no effect"),
|
// wantError: fmt.Errorf("discord-api-key: both |regex| and |path| are empty, this rule will have no effect"),
|
||||||
},
|
//},
|
||||||
{
|
{
|
||||||
cfgName: "bad_entropy_group",
|
cfgName: "bad_entropy_group",
|
||||||
cfg: Config{},
|
cfg: Config{},
|
||||||
|
|||||||
+5
-3
@@ -60,10 +60,12 @@ func (r Rule) Validate() error {
|
|||||||
return fmt.Errorf("rule |id| is missing or empty" + context)
|
return fmt.Errorf("rule |id| is missing or empty" + context)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: uncomment this once it works with |extend|.
|
||||||
|
// See: https://github.com/gitleaks/gitleaks/issues/1507#issuecomment-2352559213
|
||||||
// Ensure the rule actually matches something.
|
// Ensure the rule actually matches something.
|
||||||
if r.Regex == nil && r.Path == nil {
|
//if r.Regex == nil && r.Path == nil {
|
||||||
return fmt.Errorf("%s: both |regex| and |path| are empty, this rule will have no effect", r.RuleID)
|
// return fmt.Errorf("%s: both |regex| and |path| are empty, this rule will have no effect", r.RuleID)
|
||||||
}
|
//}
|
||||||
|
|
||||||
// Ensure |secretGroup| works.
|
// Ensure |secretGroup| works.
|
||||||
if r.Regex != nil && r.SecretGroup > r.Regex.NumSubexp() {
|
if r.Regex != nil && r.SecretGroup > r.Regex.NumSubexp() {
|
||||||
|
|||||||
Reference in new issue
Block a user