Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gitleaks returns exit code 0 when a sequence of invalid flags is passed #1464

Open
fdz-tiago-taveira opened this issue Aug 12, 2024 · 4 comments · May be fixed by #1545
Open

Gitleaks returns exit code 0 when a sequence of invalid flags is passed #1464

fdz-tiago-taveira opened this issue Aug 12, 2024 · 4 comments · May be fixed by #1545
Labels
bug Something isn't working

Comments

@fdz-tiago-taveira
Copy link

Describe the bug
Gitleaks returns exit code 0 when the order of the flags should have caused it to fail (and return exit code 1).

To Reproduce
Steps to reproduce the behavior:

  1. touch config.toml
  2. gitleaks detect -s --no-banner . -c config.toml
  3. echo $? (0 is returned, despite the output showing the error)

Expected behavior
Return exit code 1 (leaks or error encountered).

Screenshots
n/a

Basic Info (please complete the following information):

  • OS: macOS 14.5 (23F79)
  • Gitleaks Version: 8.18.4

Additional context
Not passing the config file flag (i.e., gitleaks detect -s --no-banner .) returns the expected exit code (1).
I ran into this by chance due to having misplaced the arguments, other flag combinations possibly have the same behavior.

cc @zricethezav

@fdz-tiago-taveira fdz-tiago-taveira added the bug Something isn't working label Aug 12, 2024
@rgmz
Copy link
Contributor

rgmz commented Aug 14, 2024

I think this should be fixed by #1461.

$ ./gitleaks detect -s --no-banner . -c config.toml

    ○
    │╲
    │ ○
    ○ ░
    ░    gitleaks

11:14PM ERR [git] fatal: cannot change to '--no-banner': No such file or directory
11:14PM ERR failed to scan Git repository error="stderr is not empty"
11:14PM WRN partial scan completed in 3.72ms
11:14PM WRN no leaks found in partial scan

$ echo $?
1

@recreator66
Copy link
Contributor

This still exists @rgmz

./gitleaks detect -s --no-banner . -c config.toml

    ○
    │╲
    │ ○
    ○ ░
    ░    gitleaks

8:34PM ERR [git] fatal: cannot change to '--no-banner': No such file or directory
8:34PM ERR failed to scan Git repository error="stderr is not empty"
8:34PM INF scan completed in 1.07ms
8:34PM INF no leaks found

echo $?                                                                                                                                                       
0

I think this is because the error is only logged instead of terminating with exit code 1:

gitleaks/cmd/detect.go

Lines 117 to 120 in c5b15c9

if err != nil {
// don't exit on error, just log it
log.Error().Err(err).Msg("failed to scan Git repository")
}

With the replacement of log.Error().Err(err).Msg("failed to scan Git repository") by log.Fatal().Err(err).Msg("failed to scan Git repository") we could fix this issue.

./gitleaks detect -s --no-banner . -c config.toml

    ○
    │╲
    │ ○
    ○ ░
    ░    gitleaks

8:36PM ERR [git] fatal: cannot change to '--no-banner': No such file or directory
8:36PM FTL failed to scan Git repository error="stderr is not empty"

echo $?                                                                                                                                                   
1

What is the purpose to only log this error?

@rgmz
Copy link
Contributor

rgmz commented Oct 2, 2024

Hmm, must be a regression from #1504.

@recreator66
Copy link
Contributor

Just have seen the deprecation comments, wasn't aware of this change tbh.

However executing the same flags with directory does not throw an error at all..
How should we proceed here? Does it make sense to update the logic for the old command detect and should directory terminate the execution in case there a an empty config passed?

./gitleaks directory --no-banner -c config.toml 
9:29PM INF scan completed in 7.83ms
9:29PM INF no leaks found

echo $?
0

@recreator66 recreator66 linked a pull request Oct 2, 2024 that will close this issue
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants