Skip to content

Commit

Permalink
feat: add --ignore-gitleaks-allow cmd flag (#1260)
Browse files Browse the repository at this point in the history
* feat: add --ignore-gitleaks-allow cmd flag

* typo: fix
  • Loading branch information
savely-krasovsky committed Aug 30, 2023
1 parent a82ac29 commit 0d5e46f
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 1 deletion.
4 changes: 4 additions & 0 deletions cmd/detect.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ func runDetect(cmd *cobra.Command, args []string) {
if detector.MaxTargetMegaBytes, err = cmd.Flags().GetInt("max-target-megabytes"); err != nil {
log.Fatal().Err(err).Msg("")
}
// set ignore gitleaks:allow flag
if detector.IgnoreGitleaksAllow, err = cmd.Flags().GetBool("ignore-gitleaks-allow"); err != nil {
log.Fatal().Err(err).Msg("")
}

gitleaksIgnorePath, err := cmd.Flags().GetString("gitleaks-ignore-path")
if err != nil {
Expand Down
4 changes: 4 additions & 0 deletions cmd/protect.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ func runProtect(cmd *cobra.Command, args []string) {
if detector.MaxTargetMegaBytes, err = cmd.Flags().GetInt("max-target-megabytes"); err != nil {
log.Fatal().Err(err).Msg("")
}
// set ignore gitleaks:allow flag
if detector.IgnoreGitleaksAllow, err = cmd.Flags().GetBool("ignore-gitleaks-allow"); err != nil {
log.Fatal().Err(err).Msg("")
}

gitleaksIgnorePath, err := cmd.Flags().GetString("gitleaks-ignore-path")
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ func init() {
rootCmd.PersistentFlags().BoolP("verbose", "v", false, "show verbose output from scan")
rootCmd.PersistentFlags().BoolP("no-color", "", false, "turn off color for verbose output")
rootCmd.PersistentFlags().Int("max-target-megabytes", 0, "files larger than this will be skipped")
rootCmd.PersistentFlags().BoolP("ignore-gitleaks-allow", "", false, "ignore gitleaks:allow comments")
rootCmd.PersistentFlags().Uint("redact", 0, "redact secrets from logs and stdout. To redact only parts of the secret just apply a percent value from 0..100. For example --redact=20 (default 100%)")
rootCmd.Flag("redact").NoOptDefVal = "100"
rootCmd.PersistentFlags().Bool("no-banner", false, "suppress banner")
Expand Down
5 changes: 4 additions & 1 deletion detect/detect.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ type Detector struct {
// NoColor is a flag to disable color output
NoColor bool

// IgnoreGitleaksAllow is a flag to ignore gitleaks:allow comments.
IgnoreGitleaksAllow bool

// commitMap is used to keep track of commits that have been scanned.
// This is only used for logging purposes and git scans.
commitMap map[string]bool
Expand Down Expand Up @@ -282,7 +285,7 @@ func (d *Detector) detectRule(fragment Fragment, rule config.Rule) []report.Find
}

if strings.Contains(fragment.Raw[loc.startLineIndex:loc.endLineIndex],
gitleaksAllowSignature) {
gitleaksAllowSignature) && !d.IgnoreGitleaksAllow {
continue
}

Expand Down

0 comments on commit 0d5e46f

Please sign in to comment.