Compare commits

..
5 Commits
8 changed files with 29 additions and 5 deletions

No files matched your search

+6 -1
View File
@@ -34,11 +34,16 @@ brew install gitleaks
``` ```
### Docker ### Docker
Using the image from DockerHub: #### DockerHub
```bash ```bash
docker pull zricethezav/gitleaks:latest docker pull zricethezav/gitleaks:latest
docker run -v ${path_to_host_folder_to_scan}:/path zricethezav/gitleaks:latest [COMMAND] --source="/path" [OPTIONS] docker run -v ${path_to_host_folder_to_scan}:/path zricethezav/gitleaks:latest [COMMAND] --source="/path" [OPTIONS]
``` ```
#### ghrc.io
```bash
docker pull ghcr.io/zricethezav/gitleaks:latest
docker run -v ${path_to_host_folder_to_scan}:/path zricethezav/gitleaks:latest [COMMAND] --source="/path" [OPTIONS]
```
### From Source ### From Source
1. Download and install Go from https://golang.org/dl/ 1. Download and install Go from https://golang.org/dl/
+5
View File
@@ -2,6 +2,7 @@ package cmd
import ( import (
"os" "os"
"path/filepath"
"time" "time"
"github.com/rs/zerolog/log" "github.com/rs/zerolog/log"
@@ -40,12 +41,16 @@ func runDetect(cmd *cobra.Command, args []string) {
log.Fatal().Err(err).Msg("Failed to load config") log.Fatal().Err(err).Msg("Failed to load config")
} }
cfg.Path, _ = cmd.Flags().GetString("config")
source, _ := cmd.Flags().GetString("source") source, _ := cmd.Flags().GetString("source")
logOpts, _ := cmd.Flags().GetString("log-opts") logOpts, _ := cmd.Flags().GetString("log-opts")
verbose, _ := cmd.Flags().GetBool("verbose") verbose, _ := cmd.Flags().GetBool("verbose")
redact, _ := cmd.Flags().GetBool("redact") redact, _ := cmd.Flags().GetBool("redact")
noGit, _ := cmd.Flags().GetBool("no-git") noGit, _ := cmd.Flags().GetBool("no-git")
exitCode, _ := cmd.Flags().GetInt("exit-code") exitCode, _ := cmd.Flags().GetInt("exit-code")
if cfg.Path == "" {
cfg.Path = filepath.Join(source, ".gitleaks.toml")
}
start := time.Now() start := time.Now()
if noGit { if noGit {
+5
View File
@@ -2,6 +2,7 @@ package cmd
import ( import (
"os" "os"
"path/filepath"
"time" "time"
"github.com/rs/zerolog/log" "github.com/rs/zerolog/log"
@@ -35,11 +36,15 @@ func runProtect(cmd *cobra.Command, args []string) {
log.Fatal().Err(err).Msg("Failed to load config") log.Fatal().Err(err).Msg("Failed to load config")
} }
cfg.Path, _ = cmd.Flags().GetString("config")
source, _ := cmd.Flags().GetString("source") source, _ := cmd.Flags().GetString("source")
verbose, _ := cmd.Flags().GetBool("verbose") verbose, _ := cmd.Flags().GetBool("verbose")
redact, _ := cmd.Flags().GetBool("redact") redact, _ := cmd.Flags().GetBool("redact")
exitCode, _ := cmd.Flags().GetInt("exit-code") exitCode, _ := cmd.Flags().GetInt("exit-code")
staged, _ := cmd.Flags().GetBool("staged") staged, _ := cmd.Flags().GetBool("staged")
if cfg.Path == "" {
cfg.Path = filepath.Join(source, ".gitleaks.toml")
}
start := time.Now() start := time.Now()
files, err := git.GitDiff(source, staged) files, err := git.GitDiff(source, staged)
+1
View File
@@ -38,6 +38,7 @@ type ViperConfig struct {
// Config is a configuration struct that contains rules and an allowlist if present. // Config is a configuration struct that contains rules and an allowlist if present.
type Config struct { type Config struct {
Path string
Description string Description string
Rules []*Rule Rules []*Rule
Allowlist Allowlist Allowlist Allowlist
+1 -1
View File
@@ -445,4 +445,4 @@ regex = '''(?i)(typeform[a-z0-9_ .\-,]{0,25})(=|>|:=|\|\|:|<=|=>|:).{0,5}(tfp_[a
[allowlist] [allowlist]
description = "global allow lists" description = "global allow lists"
regexes = ['''219-09-9999''', '''078-05-1120''', '''(9[0-9]{2}|666)-\d{2}-\d{4}'''] regexes = ['''219-09-9999''', '''078-05-1120''', '''(9[0-9]{2}|666)-\d{2}-\d{4}''']
files = ['''(.*?)(jpg|gif|doc|pdf|bin|svg|socket)$'''] paths = ['''(.*?)(jpg|gif|doc|pdf|bin|svg|socket)$''']
+2 -2
View File
@@ -19,8 +19,8 @@ func DetectFindings(cfg config.Config, b []byte, filePath string, commit string)
var findings []report.Finding var findings []report.Finding
linePairs := regexp.MustCompile("\n").FindAllIndex(b, -1) linePairs := regexp.MustCompile("\n").FindAllIndex(b, -1)
// check if we should skip file based on the global allowlist // check if we should skip file based on the global allowlist or if the file is the same as the gitleaks config
if cfg.Allowlist.PathAllowed(filePath) { if cfg.Allowlist.PathAllowed(filePath) || filePath == cfg.Path {
return findings return findings
} }
+8
View File
@@ -2,6 +2,7 @@ package detect
import ( import (
"fmt" "fmt"
"path/filepath"
"testing" "testing"
"github.com/spf13/viper" "github.com/spf13/viper"
@@ -111,6 +112,12 @@ func TestDetectFindings(t *testing.T) {
expectedFindings: []report.Finding{}, expectedFindings: []report.Finding{},
wantError: fmt.Errorf("Discord API key invalid regex entropy group 5, max regex entropy group 3"), wantError: fmt.Errorf("Discord API key invalid regex entropy group 5, max regex entropy group 3"),
}, },
{
cfgName: "simple",
bytes: []byte(`awsToken := \"AKIALALEMEL33243OLIA\"`),
filePath: filepath.Join(configPath, "simple.toml"),
expectedFindings: []report.Finding{},
},
} }
for _, tt := range tests { for _, tt := range tests {
@@ -126,6 +133,7 @@ func TestDetectFindings(t *testing.T) {
var vc config.ViperConfig var vc config.ViperConfig
viper.Unmarshal(&vc) viper.Unmarshal(&vc)
cfg, err := vc.Translate() cfg, err := vc.Translate()
cfg.Path = filepath.Join(configPath, tt.cfgName+".toml")
if tt.wantError != nil { if tt.wantError != nil {
if err == nil { if err == nil {
t.Errorf("expected error") t.Errorf("expected error")
+1 -1
View File
@@ -21,7 +21,7 @@ func GitLog(source string, logOpts string) (<-chan *gitdiff.File, error) {
args = append(args, strings.Split(logOpts, " ")...) args = append(args, strings.Split(logOpts, " ")...)
cmd = exec.Command("git", args...) cmd = exec.Command("git", args...)
} else { } else {
cmd = exec.Command("git", "-C", sourceClean, "log", "-p", "-U0", "--full-history", "--simplify-merges", "--show-pulls", "--all") cmd = exec.Command("git", "-C", sourceClean, "log", "-p", "-U0", "--full-history", "--all")
} }
log.Debug().Msgf("executing: %s", cmd.String()) log.Debug().Msgf("executing: %s", cmd.String())