Compare commits

..
4 Commits
Author SHA1 Message Date
Richard Gomez 128cd22f7c fix(rule): comment out errant validation case (#1509)
This should be re-enabled once a more suitable fix is implemented.
2024-09-16 06:17:26 -05:00
Zachary Rice 1a6d2b0a7a remove validate config test temporarily 2024-09-14 05:49:13 -05:00
Zachary Rice 0874ebcc3f Update README.md 2024-09-14 05:46:28 -05:00
Zachary Rice 9463ffaa5e fix flag access (#1506) 2024-09-14 04:01:27 -05:00
10 changed files with 45 additions and 92 deletions

No files matched your search

-3
View File
@@ -24,6 +24,3 @@ jobs:
- name: Test
run: make test
- name: Validate Config
run: go generate ./... && git diff --exit-code
-48
View File
@@ -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.
### 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
You can run Gitleaks as a pre-commit hook by copying the example `pre-commit.py` script into
+7 -10
View File
@@ -46,11 +46,13 @@ var detectCmd = &cobra.Command{
}
func runDetect(cmd *cobra.Command, args []string) {
initConfig()
var (
findings []report.Finding
err error
)
source, err := cmd.Flags().GetString("source")
if err != nil {
log.Fatal().Err(err).Msg("could not get source")
}
initConfig(source)
var findings []report.Finding
// setup config (aka, the thing that defines rules)
cfg := Config(cmd)
@@ -58,11 +60,6 @@ func runDetect(cmd *cobra.Command, args []string) {
// start timer
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)
// set exit code
+10 -6
View File
@@ -23,7 +23,15 @@ var directoryCmd = &cobra.Command{
}
func runDirectory(cmd *cobra.Command, args []string) {
initConfig()
// grab source
source := "."
if len(args) == 1 {
source = args[0]
if source == "" {
source = "."
}
}
initConfig(source)
var (
findings []report.Finding
err error
@@ -35,11 +43,7 @@ func runDirectory(cmd *cobra.Command, args []string) {
// start timer
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)
// set exit code
+11 -5
View File
@@ -25,12 +25,22 @@ var gitCmd = &cobra.Command{
}
func runGit(cmd *cobra.Command, args []string) {
initConfig()
var (
findings []report.Finding
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)
cfg := Config(cmd)
@@ -38,10 +48,6 @@ func runGit(cmd *cobra.Command, args []string) {
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)
// set exit code
+5 -6
View File
@@ -25,18 +25,17 @@ var protectCmd = &cobra.Command{
}
func runProtect(cmd *cobra.Command, args []string) {
initConfig()
var err error
source, err := cmd.Flags().GetString("source")
if err != nil {
log.Fatal().Err(err).Msg("could not get source")
}
initConfig(source)
// setup config (aka, the thing that defines rules)
cfg := Config(cmd)
exitCode, _ := cmd.Flags().GetInt("exit-code")
staged, _ := cmd.Flags().GetBool("staged")
source, err := cmd.Flags().GetString("source")
if err != nil {
log.Fatal().Err(err).Msg("")
}
start := time.Now()
detector := Detector(cmd, cfg, source)
+1 -5
View File
@@ -86,7 +86,7 @@ func initLog() {
}
}
func initConfig() {
func initConfig(source string) {
hideBanner, err := rootCmd.Flags().GetBool("no-banner")
if err != nil {
log.Fatal().Msg(err.Error())
@@ -106,10 +106,6 @@ func initConfig() {
viper.SetConfigFile(envPath)
log.Debug().Msgf("using gitleaks config from GITLEAKS_CONFIG env var: %s", envPath)
} else {
source, err := rootCmd.Flags().GetString("source")
if err != nil {
log.Fatal().Msg(err.Error())
}
fileInfo, err := os.Stat(source)
if err != nil {
log.Fatal().Msg(err.Error())
+1 -1
View File
@@ -21,7 +21,7 @@ var stdInCmd = &cobra.Command{
}
func runStdIn(cmd *cobra.Command, args []string) {
initConfig()
initConfig(".")
var (
findings []report.Finding
err error
+5 -5
View File
@@ -91,11 +91,11 @@ func TestTranslate(t *testing.T) {
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})['\\\"]"),
},
{
cfgName: "no_regex_or_path",
cfg: Config{},
wantError: fmt.Errorf("discord-api-key: both |regex| and |path| are empty, this rule will have no effect"),
},
//{
// cfgName: "no_regex_or_path",
// cfg: Config{},
// wantError: fmt.Errorf("discord-api-key: both |regex| and |path| are empty, this rule will have no effect"),
//},
{
cfgName: "bad_entropy_group",
cfg: Config{},
+5 -3
View File
@@ -60,10 +60,12 @@ func (r Rule) Validate() error {
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.
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)
}
//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)
//}
// Ensure |secretGroup| works.
if r.Regex != nil && r.SecretGroup > r.Regex.NumSubexp() {