mirror of
https://github.com/gitleaks/gitleaks.git
synced 2026-11-27 19:54:24 +01:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
db08fc0564 | ||
|
|
dbb6d4cc5f | ||
|
|
d0f44da4c2 | ||
|
|
cb6b01cc5d | ||
|
|
392d79b9e2 | ||
|
|
f8e609d4bf | ||
|
|
573bf46fd1 | ||
|
|
d65592bbcc | ||
|
|
169a137e7f |
No files matched your search
@@ -1,6 +1,11 @@
|
||||
CHANGELOG
|
||||
=========
|
||||
|
||||
1.21.0
|
||||
----
|
||||
- added support for cloning repositories using github api
|
||||
- auditing PRs now allows for whitelisting files
|
||||
|
||||
1.20.0
|
||||
----
|
||||
- adding gitlab user and group support
|
||||
|
||||
@@ -105,11 +105,7 @@ The code return codes are:
|
||||
2: error encountered
|
||||
```
|
||||
|
||||
### GitLab
|
||||
To audit public repositories for user on GitLab use `--gitlab-user=` and for group `--gitlab-org=`. For private repositories add `GITLAB_TOKEN` environment variable with your personal access token (is used to list all repositories via API) and set `--ssh-key=` to SSH key path (is used to clone repository).
|
||||
If self hosted GitLab server add `GITLAB_URL` environment variable with your URL.
|
||||
|
||||
#### Additional information
|
||||
### Additional information
|
||||
* Additional documentation about how gitleaks functions can be found on the [wiki page](https://github.com/zricethezav/gitleaks/wiki)
|
||||
* The below links detail the various approaches to remediating unwanted data in git repos
|
||||
* [Removing sensitive data from a repository (github.com)](https://help.github.com/articles/removing-sensitive-data-from-a-repository/)
|
||||
@@ -122,6 +118,14 @@ If self hosted GitLab server add `GITLAB_URL` environment variable with your URL
|
||||
* How does gitleaks differ to Github token scanning?
|
||||
* [Github recently announced](https://blog.github.com/2018-10-16-future-of-software/#github-token-scanning-for-public-repositories-public-beta) a new capability to their cloud platform that detects exposed credentials for a number of common services and platforms and automatically notifies the provider for revocation or similar action. Gitleaks provides a similar detection capability for non-Github cloud users, in which repositories can be easily audited and results provided in a number of formats.
|
||||
|
||||
### Give Thanks
|
||||
If using gitleaks has made you job easier consider donating to an organization, C-U at Home, that does vital work for those who most need it in the community of Champaign-Urbana, IL (my home).
|
||||
|
||||
From C-U at Home:
|
||||
|
||||
```C-U at Home is a grassroots, 501 c (3), faith-based homelessness ministry with facilities located in the Champaign-Urbana area. Due to our not-for-profit status, all gifts made to C-U at Home (both monetary and in-kind) are tax deductible. Our ministry is funded 100% by the community and we have made it a priority not to accept any state or federal funds. We feel that through community dollars, we can stay true to our mission. While our mission statement reads, “C-U at Home engages and mobilizes our community to house and support the most vulnerable homeless on their journey of healing and restoration,” our connection with those we serve goes much deeper.```
|
||||
|
||||
<b>Donate</b>: https://www.cuathome.us/give/
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -14,6 +14,7 @@ import (
|
||||
log "github.com/sirupsen/logrus"
|
||||
"golang.org/x/oauth2"
|
||||
git "gopkg.in/src-d/go-git.v4"
|
||||
gitHttp "gopkg.in/src-d/go-git.v4/plumbing/transport/http"
|
||||
"gopkg.in/src-d/go-git.v4/storage/memory"
|
||||
)
|
||||
|
||||
@@ -177,6 +178,7 @@ func cloneGithubRepo(githubRepo *github.Repository) (*RepoDescriptor, error) {
|
||||
repo *git.Repository
|
||||
err error
|
||||
)
|
||||
githubToken := os.Getenv("GITHUB_TOKEN")
|
||||
if opts.ExcludeForks && githubRepo.GetFork() {
|
||||
return nil, fmt.Errorf("skipping %s, excluding forks", *githubRepo.Name)
|
||||
}
|
||||
@@ -191,22 +193,38 @@ func cloneGithubRepo(githubRepo *github.Repository) (*RepoDescriptor, error) {
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("unable to generater owner temp dir: %v", err)
|
||||
}
|
||||
if sshAuth != nil {
|
||||
if sshAuth != nil && githubToken == "" {
|
||||
repo, err = git.PlainClone(fmt.Sprintf("%s/%s", ownerDir, *githubRepo.Name), false, &git.CloneOptions{
|
||||
URL: *githubRepo.SSHURL,
|
||||
Auth: sshAuth,
|
||||
})
|
||||
} else if githubToken != "" {
|
||||
repo, err = git.PlainClone(fmt.Sprintf("%s/%s", ownerDir, *githubRepo.Name), false, &git.CloneOptions{
|
||||
URL: *githubRepo.CloneURL,
|
||||
Auth: &gitHttp.BasicAuth{
|
||||
Username: "fakeUsername", // yes, this can be anything except an empty string
|
||||
Password: githubToken,
|
||||
},
|
||||
})
|
||||
} else {
|
||||
repo, err = git.PlainClone(fmt.Sprintf("%s/%s", ownerDir, *githubRepo.Name), false, &git.CloneOptions{
|
||||
URL: *githubRepo.CloneURL,
|
||||
})
|
||||
}
|
||||
} else {
|
||||
if sshAuth != nil {
|
||||
if sshAuth != nil && githubToken == "" {
|
||||
repo, err = git.Clone(memory.NewStorage(), nil, &git.CloneOptions{
|
||||
URL: *githubRepo.SSHURL,
|
||||
Auth: sshAuth,
|
||||
})
|
||||
} else if githubToken != "" {
|
||||
repo, err = git.Clone(memory.NewStorage(), nil, &git.CloneOptions{
|
||||
URL: *githubRepo.CloneURL,
|
||||
Auth: &gitHttp.BasicAuth{
|
||||
Username: "fakeUsername", // yes, this can be anything except an empty string
|
||||
Password: githubToken,
|
||||
},
|
||||
})
|
||||
} else {
|
||||
repo, err = git.Clone(memory.NewStorage(), nil, &git.CloneOptions{
|
||||
URL: *githubRepo.CloneURL,
|
||||
|
||||
@@ -176,6 +176,7 @@ func TestRun(t *testing.T) {
|
||||
description string
|
||||
expectedErrMsg string
|
||||
whiteListRepos []string
|
||||
whiteListFiles []*regexp.Regexp
|
||||
numLeaks int
|
||||
configPath string
|
||||
commitPerPage int
|
||||
@@ -298,6 +299,18 @@ func TestRun(t *testing.T) {
|
||||
expectedErrMsg: "",
|
||||
commitPerPage: 1,
|
||||
},
|
||||
{
|
||||
testOpts: Options{
|
||||
GithubPR: "https://github.com/gitleakstest/gronit/pull/1",
|
||||
},
|
||||
description: "test github pr with whitelisted files",
|
||||
numLeaks: 0,
|
||||
expectedErrMsg: "",
|
||||
commitPerPage: 1,
|
||||
whiteListFiles: []*regexp.Regexp{
|
||||
regexp.MustCompile("main.go"),
|
||||
},
|
||||
},
|
||||
}
|
||||
g := goblin.Goblin(t)
|
||||
for _, test := range tests {
|
||||
@@ -309,6 +322,11 @@ func TestRun(t *testing.T) {
|
||||
if test.commitPerPage != 0 {
|
||||
githubPages = test.commitPerPage
|
||||
}
|
||||
if test.whiteListFiles != nil {
|
||||
whiteListFiles = test.whiteListFiles
|
||||
} else {
|
||||
whiteListFiles = nil
|
||||
}
|
||||
opts = test.testOpts
|
||||
leaks, err := run()
|
||||
if err != nil {
|
||||
|
||||
@@ -130,7 +130,7 @@ type entropyRange struct {
|
||||
}
|
||||
|
||||
const defaultGithubURL = "https://api.github.com/"
|
||||
const version = "1.20.0"
|
||||
const version = "1.21.0"
|
||||
const errExit = 2
|
||||
const leakExit = 1
|
||||
const defaultConfig = `
|
||||
@@ -171,7 +171,7 @@ regex = '''xox[baprs]-([0-9a-zA-Z]{10,48})?'''
|
||||
|
||||
[whitelist]
|
||||
files = [
|
||||
"(.*?)(jpg|gif|doc|pdf|bin)$"
|
||||
"(.*?)(jpg|gif|doc|pdf|bin)$"
|
||||
]
|
||||
#commits = [
|
||||
# "BADHA5H1",
|
||||
@@ -488,11 +488,6 @@ func auditGitReference(repo *RepoDescriptor, ref *plumbing.Reference) []Leak {
|
||||
if bin || err != nil {
|
||||
return nil
|
||||
}
|
||||
for _, re := range whiteListFiles {
|
||||
if re.FindString(f.Name) != "" {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
content, err := f.Contents()
|
||||
if err != nil {
|
||||
return nil
|
||||
@@ -560,12 +555,6 @@ func auditGitReference(repo *RepoDescriptor, ref *plumbing.Reference) []Leak {
|
||||
} else if to != nil {
|
||||
filePath = to.Path()
|
||||
}
|
||||
for _, re := range whiteListFiles {
|
||||
if re.FindString(filePath) != "" {
|
||||
skipFile = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if skipFile {
|
||||
continue
|
||||
}
|
||||
@@ -604,12 +593,19 @@ func auditGitReference(repo *RepoDescriptor, ref *plumbing.Reference) []Leak {
|
||||
// will skip lines that include a whitelisted regex. A list of leaks is returned.
|
||||
// If verbose mode (-v/--verbose) is set, then checkDiff will log leaks as they are discovered.
|
||||
func inspect(diff gitDiff) []Leak {
|
||||
lines := strings.Split(diff.content, "\n")
|
||||
var (
|
||||
leaks []Leak
|
||||
skipLine bool
|
||||
)
|
||||
|
||||
for _, re := range whiteListFiles {
|
||||
if re.FindString(diff.filePath) != "" {
|
||||
return leaks
|
||||
}
|
||||
}
|
||||
|
||||
lines := strings.Split(diff.content, "\n")
|
||||
|
||||
for _, line := range lines {
|
||||
skipLine = false
|
||||
for leakType, re := range regexes {
|
||||
|
||||
Reference in new issue
Block a user