mirror of
https://github.com/gitleaks/gitleaks.git
synced 2026-11-29 12:44:22 +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
|
CHANGELOG
|
||||||
=========
|
=========
|
||||||
|
|
||||||
|
1.21.0
|
||||||
|
----
|
||||||
|
- added support for cloning repositories using github api
|
||||||
|
- auditing PRs now allows for whitelisting files
|
||||||
|
|
||||||
1.20.0
|
1.20.0
|
||||||
----
|
----
|
||||||
- adding gitlab user and group support
|
- adding gitlab user and group support
|
||||||
|
|||||||
@@ -105,11 +105,7 @@ The code return codes are:
|
|||||||
2: error encountered
|
2: error encountered
|
||||||
```
|
```
|
||||||
|
|
||||||
### GitLab
|
### Additional information
|
||||||
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 documentation about how gitleaks functions can be found on the [wiki page](https://github.com/zricethezav/gitleaks/wiki)
|
* 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
|
* 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/)
|
* [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?
|
* 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.
|
* [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"
|
log "github.com/sirupsen/logrus"
|
||||||
"golang.org/x/oauth2"
|
"golang.org/x/oauth2"
|
||||||
git "gopkg.in/src-d/go-git.v4"
|
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"
|
"gopkg.in/src-d/go-git.v4/storage/memory"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -177,6 +178,7 @@ func cloneGithubRepo(githubRepo *github.Repository) (*RepoDescriptor, error) {
|
|||||||
repo *git.Repository
|
repo *git.Repository
|
||||||
err error
|
err error
|
||||||
)
|
)
|
||||||
|
githubToken := os.Getenv("GITHUB_TOKEN")
|
||||||
if opts.ExcludeForks && githubRepo.GetFork() {
|
if opts.ExcludeForks && githubRepo.GetFork() {
|
||||||
return nil, fmt.Errorf("skipping %s, excluding forks", *githubRepo.Name)
|
return nil, fmt.Errorf("skipping %s, excluding forks", *githubRepo.Name)
|
||||||
}
|
}
|
||||||
@@ -191,22 +193,38 @@ func cloneGithubRepo(githubRepo *github.Repository) (*RepoDescriptor, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("unable to generater owner temp dir: %v", err)
|
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{
|
repo, err = git.PlainClone(fmt.Sprintf("%s/%s", ownerDir, *githubRepo.Name), false, &git.CloneOptions{
|
||||||
URL: *githubRepo.SSHURL,
|
URL: *githubRepo.SSHURL,
|
||||||
Auth: sshAuth,
|
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 {
|
} else {
|
||||||
repo, err = git.PlainClone(fmt.Sprintf("%s/%s", ownerDir, *githubRepo.Name), false, &git.CloneOptions{
|
repo, err = git.PlainClone(fmt.Sprintf("%s/%s", ownerDir, *githubRepo.Name), false, &git.CloneOptions{
|
||||||
URL: *githubRepo.CloneURL,
|
URL: *githubRepo.CloneURL,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if sshAuth != nil {
|
if sshAuth != nil && githubToken == "" {
|
||||||
repo, err = git.Clone(memory.NewStorage(), nil, &git.CloneOptions{
|
repo, err = git.Clone(memory.NewStorage(), nil, &git.CloneOptions{
|
||||||
URL: *githubRepo.SSHURL,
|
URL: *githubRepo.SSHURL,
|
||||||
Auth: sshAuth,
|
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 {
|
} else {
|
||||||
repo, err = git.Clone(memory.NewStorage(), nil, &git.CloneOptions{
|
repo, err = git.Clone(memory.NewStorage(), nil, &git.CloneOptions{
|
||||||
URL: *githubRepo.CloneURL,
|
URL: *githubRepo.CloneURL,
|
||||||
|
|||||||
@@ -176,6 +176,7 @@ func TestRun(t *testing.T) {
|
|||||||
description string
|
description string
|
||||||
expectedErrMsg string
|
expectedErrMsg string
|
||||||
whiteListRepos []string
|
whiteListRepos []string
|
||||||
|
whiteListFiles []*regexp.Regexp
|
||||||
numLeaks int
|
numLeaks int
|
||||||
configPath string
|
configPath string
|
||||||
commitPerPage int
|
commitPerPage int
|
||||||
@@ -298,6 +299,18 @@ func TestRun(t *testing.T) {
|
|||||||
expectedErrMsg: "",
|
expectedErrMsg: "",
|
||||||
commitPerPage: 1,
|
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)
|
g := goblin.Goblin(t)
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
@@ -309,6 +322,11 @@ func TestRun(t *testing.T) {
|
|||||||
if test.commitPerPage != 0 {
|
if test.commitPerPage != 0 {
|
||||||
githubPages = test.commitPerPage
|
githubPages = test.commitPerPage
|
||||||
}
|
}
|
||||||
|
if test.whiteListFiles != nil {
|
||||||
|
whiteListFiles = test.whiteListFiles
|
||||||
|
} else {
|
||||||
|
whiteListFiles = nil
|
||||||
|
}
|
||||||
opts = test.testOpts
|
opts = test.testOpts
|
||||||
leaks, err := run()
|
leaks, err := run()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -130,7 +130,7 @@ type entropyRange struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const defaultGithubURL = "https://api.github.com/"
|
const defaultGithubURL = "https://api.github.com/"
|
||||||
const version = "1.20.0"
|
const version = "1.21.0"
|
||||||
const errExit = 2
|
const errExit = 2
|
||||||
const leakExit = 1
|
const leakExit = 1
|
||||||
const defaultConfig = `
|
const defaultConfig = `
|
||||||
@@ -171,7 +171,7 @@ regex = '''xox[baprs]-([0-9a-zA-Z]{10,48})?'''
|
|||||||
|
|
||||||
[whitelist]
|
[whitelist]
|
||||||
files = [
|
files = [
|
||||||
"(.*?)(jpg|gif|doc|pdf|bin)$"
|
"(.*?)(jpg|gif|doc|pdf|bin)$"
|
||||||
]
|
]
|
||||||
#commits = [
|
#commits = [
|
||||||
# "BADHA5H1",
|
# "BADHA5H1",
|
||||||
@@ -488,11 +488,6 @@ func auditGitReference(repo *RepoDescriptor, ref *plumbing.Reference) []Leak {
|
|||||||
if bin || err != nil {
|
if bin || err != nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
for _, re := range whiteListFiles {
|
|
||||||
if re.FindString(f.Name) != "" {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
content, err := f.Contents()
|
content, err := f.Contents()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil
|
return nil
|
||||||
@@ -560,12 +555,6 @@ func auditGitReference(repo *RepoDescriptor, ref *plumbing.Reference) []Leak {
|
|||||||
} else if to != nil {
|
} else if to != nil {
|
||||||
filePath = to.Path()
|
filePath = to.Path()
|
||||||
}
|
}
|
||||||
for _, re := range whiteListFiles {
|
|
||||||
if re.FindString(filePath) != "" {
|
|
||||||
skipFile = true
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if skipFile {
|
if skipFile {
|
||||||
continue
|
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.
|
// 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.
|
// If verbose mode (-v/--verbose) is set, then checkDiff will log leaks as they are discovered.
|
||||||
func inspect(diff gitDiff) []Leak {
|
func inspect(diff gitDiff) []Leak {
|
||||||
lines := strings.Split(diff.content, "\n")
|
|
||||||
var (
|
var (
|
||||||
leaks []Leak
|
leaks []Leak
|
||||||
skipLine bool
|
skipLine bool
|
||||||
)
|
)
|
||||||
|
|
||||||
|
for _, re := range whiteListFiles {
|
||||||
|
if re.FindString(diff.filePath) != "" {
|
||||||
|
return leaks
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
lines := strings.Split(diff.content, "\n")
|
||||||
|
|
||||||
for _, line := range lines {
|
for _, line := range lines {
|
||||||
skipLine = false
|
skipLine = false
|
||||||
for leakType, re := range regexes {
|
for leakType, re := range regexes {
|
||||||
|
|||||||
Reference in new issue
Block a user