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

Exclude .git directory from scan #485

Merged
merged 1 commit into from Jun 9, 2020

Conversation

hiroakis
Copy link
Contributor

@hiroakis hiroakis commented Jun 9, 2020

When your repository has a branch which has .go suffix as a branch name (for examplefix/main.go), gosec will cause errors. Because git command creates .git/refs/heads/fix/main.go file in your .git directory. Then, gosec scans it as a Go file.
This pull request will fix it ignore .git directory.

Steps to reproduce

  1. Create a branch which has .go suffix

git checkout -b feature/ignore-dot-git-dir.go

  1. Run gosec

gosec ./...

  1. It will cause following errors
gosec =                                                                           (git)-[feature/ignore-dot-git-dir.go] -? (m1)
gosec = cd cmd/gosec/ && go build && cd - && ./cmd/gosec/gosec ./...
~/work/src/github.com/hiroakis/gosec
[gosec] 2020/06/09 21:48:30 Including rules: default
[gosec] 2020/06/09 21:48:30 Excluding rules: default
[gosec] 2020/06/09 21:48:30 Import directory: /Users/sano/work/src/github.com/hiroakis/gosec/testutils
[gosec] 2020/06/09 21:48:30 Checking package: testutils
[gosec] 2020/06/09 21:48:30 Checking file: /Users/sano/work/src/github.com/hiroakis/gosec/testutils/log.go
[gosec] 2020/06/09 21:48:30 Checking file: /Users/sano/work/src/github.com/hiroakis/gosec/testutils/pkg.go
[gosec] 2020/06/09 21:48:30 Checking file: /Users/sano/work/src/github.com/hiroakis/gosec/testutils/source.go
[gosec] 2020/06/09 21:48:30 Checking file: /Users/sano/work/src/github.com/hiroakis/gosec/testutils/visitor.go
[gosec] 2020/06/09 21:48:30 Import directory: /Users/sano/work/src/github.com/hiroakis/gosec/.git/logs/refs/heads/feature
[gosec] 2020/06/09 21:48:30 Import directory: /Users/sano/work/src/github.com/hiroakis/gosec/.git/logs/refs/remotes/origin/feature
[gosec] 2020/06/09 21:48:30 Import directory: /Users/sano/work/src/github.com/hiroakis/gosec/.git/refs/remotes/origin/feature
[gosec] 2020/06/09 21:48:30 Import directory: /Users/sano/work/src/github.com/hiroakis/gosec
[gosec] 2020/06/09 21:48:30 Checking package: gosec
[gosec] 2020/06/09 21:48:30 Checking file: /Users/sano/work/src/github.com/hiroakis/gosec/analyzer.go
[gosec] 2020/06/09 21:48:30 Checking file: /Users/sano/work/src/github.com/hiroakis/gosec/call_list.go
[gosec] 2020/06/09 21:48:30 Checking file: /Users/sano/work/src/github.com/hiroakis/gosec/config.go
[gosec] 2020/06/09 21:48:30 Checking file: /Users/sano/work/src/github.com/hiroakis/gosec/errors.go
[gosec] 2020/06/09 21:48:30 Checking file: /Users/sano/work/src/github.com/hiroakis/gosec/helpers.go
[gosec] 2020/06/09 21:48:30 Checking file: /Users/sano/work/src/github.com/hiroakis/gosec/import_tracker.go
[gosec] 2020/06/09 21:48:30 Checking file: /Users/sano/work/src/github.com/hiroakis/gosec/issue.go
[gosec] 2020/06/09 21:48:30 Checking file: /Users/sano/work/src/github.com/hiroakis/gosec/resolve.go
[gosec] 2020/06/09 21:48:30 Checking file: /Users/sano/work/src/github.com/hiroakis/gosec/rule.go
[gosec] 2020/06/09 21:48:30 Import directory: /Users/sano/work/src/github.com/hiroakis/gosec/rules
[gosec] 2020/06/09 21:48:31 Checking package: rules
[gosec] 2020/06/09 21:48:31 Checking file: /Users/sano/work/src/github.com/hiroakis/gosec/rules/archive.go
[gosec] 2020/06/09 21:48:31 Checking file: /Users/sano/work/src/github.com/hiroakis/gosec/rules/bad_defer.go
[gosec] 2020/06/09 21:48:31 Checking file: /Users/sano/work/src/github.com/hiroakis/gosec/rules/bind.go
[gosec] 2020/06/09 21:48:31 Checking file: /Users/sano/work/src/github.com/hiroakis/gosec/rules/blacklist.go
[gosec] 2020/06/09 21:48:31 Checking file: /Users/sano/work/src/github.com/hiroakis/gosec/rules/decompression-bomb.go
[gosec] 2020/06/09 21:48:31 Checking file: /Users/sano/work/src/github.com/hiroakis/gosec/rules/errors.go
[gosec] 2020/06/09 21:48:31 Checking file: /Users/sano/work/src/github.com/hiroakis/gosec/rules/fileperms.go
[gosec] 2020/06/09 21:48:31 Checking file: /Users/sano/work/src/github.com/hiroakis/gosec/rules/hardcoded_credentials.go
[gosec] 2020/06/09 21:48:31 Checking file: /Users/sano/work/src/github.com/hiroakis/gosec/rules/implicit_aliasing.go
[gosec] 2020/06/09 21:48:31 Checking file: /Users/sano/work/src/github.com/hiroakis/gosec/rules/integer_overflow.go
[gosec] 2020/06/09 21:48:31 Checking file: /Users/sano/work/src/github.com/hiroakis/gosec/rules/pprof.go
[gosec] 2020/06/09 21:48:31 Checking file: /Users/sano/work/src/github.com/hiroakis/gosec/rules/rand.go
[gosec] 2020/06/09 21:48:31 Checking file: /Users/sano/work/src/github.com/hiroakis/gosec/rules/readfile.go
[gosec] 2020/06/09 21:48:31 Checking file: /Users/sano/work/src/github.com/hiroakis/gosec/rules/rsa.go
[gosec] 2020/06/09 21:48:31 Checking file: /Users/sano/work/src/github.com/hiroakis/gosec/rules/rulelist.go
[gosec] 2020/06/09 21:48:31 Checking file: /Users/sano/work/src/github.com/hiroakis/gosec/rules/sql.go
[gosec] 2020/06/09 21:48:31 Checking file: /Users/sano/work/src/github.com/hiroakis/gosec/rules/ssh.go
[gosec] 2020/06/09 21:48:31 Checking file: /Users/sano/work/src/github.com/hiroakis/gosec/rules/ssrf.go
[gosec] 2020/06/09 21:48:31 Checking file: /Users/sano/work/src/github.com/hiroakis/gosec/rules/subproc.go
[gosec] 2020/06/09 21:48:31 Checking file: /Users/sano/work/src/github.com/hiroakis/gosec/rules/tempfiles.go
[gosec] 2020/06/09 21:48:31 Checking file: /Users/sano/work/src/github.com/hiroakis/gosec/rules/templates.go
[gosec] 2020/06/09 21:48:31 Checking file: /Users/sano/work/src/github.com/hiroakis/gosec/rules/tls.go
[gosec] 2020/06/09 21:48:31 Checking file: /Users/sano/work/src/github.com/hiroakis/gosec/rules/tls_config.go
[gosec] 2020/06/09 21:48:31 Checking file: /Users/sano/work/src/github.com/hiroakis/gosec/rules/unsafe.go
[gosec] 2020/06/09 21:48:31 Checking file: /Users/sano/work/src/github.com/hiroakis/gosec/rules/weakcrypto.go
[gosec] 2020/06/09 21:48:31 Import directory: /Users/sano/work/src/github.com/hiroakis/gosec/.git/refs/heads/feature
[gosec] 2020/06/09 21:48:31 Import directory: /Users/sano/work/src/github.com/hiroakis/gosec/cmd/gosec
[gosec] 2020/06/09 21:48:31 Checking package: main
[gosec] 2020/06/09 21:48:31 Checking file: /Users/sano/work/src/github.com/hiroakis/gosec/cmd/gosec/main.go
[gosec] 2020/06/09 21:48:31 Checking file: /Users/sano/work/src/github.com/hiroakis/gosec/cmd/gosec/sort_issues.go
[gosec] 2020/06/09 21:48:31 Checking file: /Users/sano/work/src/github.com/hiroakis/gosec/cmd/gosec/version.go
[gosec] 2020/06/09 21:48:31 Import directory: /Users/sano/work/src/github.com/hiroakis/gosec/cmd/gosecutil
[gosec] 2020/06/09 21:48:31 Checking package: main
[gosec] 2020/06/09 21:48:31 Checking file: /Users/sano/work/src/github.com/hiroakis/gosec/cmd/gosecutil/tools.go
[gosec] 2020/06/09 21:48:31 Import directory: /Users/sano/work/src/github.com/hiroakis/gosec/cmd/tlsconfig
[gosec] 2020/06/09 21:48:32 Checking package: main
[gosec] 2020/06/09 21:48:32 Checking file: /Users/sano/work/src/github.com/hiroakis/gosec/cmd/tlsconfig/header_template.go
[gosec] 2020/06/09 21:48:32 Checking file: /Users/sano/work/src/github.com/hiroakis/gosec/cmd/tlsconfig/rule_template.go
[gosec] 2020/06/09 21:48:32 Checking file: /Users/sano/work/src/github.com/hiroakis/gosec/cmd/tlsconfig/tls_version_go14.go
[gosec] 2020/06/09 21:48:32 Checking file: /Users/sano/work/src/github.com/hiroakis/gosec/cmd/tlsconfig/tlsconfig.go
[gosec] 2020/06/09 21:48:32 Import directory: /Users/sano/work/src/github.com/hiroakis/gosec/output
[gosec] 2020/06/09 21:48:32 Checking package: output
[gosec] 2020/06/09 21:48:32 Checking file: /Users/sano/work/src/github.com/hiroakis/gosec/output/formatter.go
[gosec] 2020/06/09 21:48:32 Checking file: /Users/sano/work/src/github.com/hiroakis/gosec/output/junit_xml_format.go
[gosec] 2020/06/09 21:48:32 Checking file: /Users/sano/work/src/github.com/hiroakis/gosec/output/sonarqube_format.go
[gosec] 2020/06/09 21:48:32 Checking file: /Users/sano/work/src/github.com/hiroakis/gosec/output/template.go
Results:

Golang errors in file: [.git/logs/refs/heads/feature]:

  > [line 0 : column 0] - importing dir ".git/logs/refs/heads/feature": .git/logs/refs/heads/feature/ignore-dot-git-dir.go:1:1: expected 'package', found 0000000000000000000000000000000000000000 (and 4 more errors)


Golang errors in file: [.git/logs/refs/remotes/origin/feature]:

  > [line 0 : column 0] - importing dir ".git/logs/refs/remotes/origin/feature": .git/logs/refs/remotes/origin/feature/ignore-dot-git-dir.go:1:1: expected 'package', found 0000000000000000000000000000000000000000 (and 4 more errors)


Golang errors in file: [.git/refs/heads/feature]:

  > [line 0 : column 0] - importing dir ".git/refs/heads/feature": .git/refs/heads/feature/ignore-dot-git-dir.go:1:1: expected 'package', found 6360


Golang errors in file: [.git/refs/remotes/origin/feature]:

  > [line 0 : column 0] - importing dir ".git/refs/remotes/origin/feature": .git/refs/remotes/origin/feature/ignore-dot-git-dir.go:1:1: expected 'package', found 6360



Summary:
   Files: 50
   Lines: 7915
   Nosec: 23
  Issues: 0

@codecov-commenter
Copy link

Codecov Report

Merging #485 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #485   +/-   ##
=======================================
  Coverage   71.75%   71.75%           
=======================================
  Files           9        9           
  Lines         662      662           
=======================================
  Hits          475      475           
  Misses        164      164           
  Partials       23       23           

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6202b38...6360db5. Read the comment docs.

Copy link
Member

@ccojocar ccojocar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for fixing this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants