mirror of
https://github.com/gitleaks/gitleaks.git
synced 2026-11-26 19:30:55 +01:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3932ed6baf | ||
|
|
981b636920 | ||
|
|
c8e15c731a | ||
|
|
901f932a89 | ||
|
|
c0a9580a65 | ||
|
|
8be91eea5d | ||
|
|
1c6f2252b8 | ||
|
|
58d130c5f3 | ||
|
|
091ea81e68 | ||
|
|
f036dce6ab | ||
|
|
2d58f1f94e | ||
|
|
86cfe0848b | ||
|
|
973d74e592 | ||
|
|
3909ebe03b | ||
|
|
65f42020af | ||
|
|
65a91ae976 | ||
|
|
7db08bfd90 | ||
|
|
af26553292 | ||
|
|
d5e431e7d4 | ||
|
|
54ba3ec377 | ||
|
|
656ef1c9a7 | ||
|
|
b8accd7273 | ||
|
|
238c31beaa | ||
|
|
eb31190f31 | ||
|
|
389d45e380 | ||
|
|
81b3a6e279 | ||
|
|
c50906373c | ||
|
|
40545fb680 | ||
|
|
2acc34dfdf | ||
|
|
ede68fd95d | ||
|
|
6c60c3dde3 | ||
|
|
ad505754fc | ||
|
|
21d81879e2 | ||
|
|
b5ca2ba614 | ||
|
|
ef4655fcf1 | ||
|
|
01b553a75d | ||
|
|
fae366a404 | ||
|
|
6129b1a15d | ||
|
|
31d03a1146 | ||
|
|
eabc7b5c12 | ||
|
|
1dc7569f95 | ||
|
|
1797e9c966 | ||
|
|
e2eaceb4cd | ||
|
|
c637b129ec | ||
|
|
8470e43d7f | ||
|
|
94f5950d68 | ||
|
|
fe69a17c9c | ||
|
|
6ca7a11d88 | ||
|
|
cfbb600fcb | ||
|
|
e36b550851 | ||
|
|
2232dc191c | ||
|
|
bdc688dd53 | ||
|
|
e0f6399d5c | ||
|
|
3e88ac6726 | ||
|
|
d0088f6c7c | ||
|
|
0d7c18cb39 | ||
|
|
d0e98416b9 | ||
|
|
b7438011b4 | ||
|
|
4e59d3bf19 | ||
|
|
e4b26aea4a | ||
|
|
473d0d55a7 | ||
|
|
8bd4649b01 | ||
|
|
a69df84325 | ||
|
|
0faebdefea | ||
|
|
a728e3abf3 | ||
|
|
e87c62fe72 | ||
|
|
4801818e3d | ||
|
|
b4a0577786 | ||
|
|
212232f80a | ||
|
|
11dcb44e41 | ||
|
|
af0df6ea2c | ||
|
|
9db91442b3 | ||
|
|
9d76070806 | ||
|
|
2fa580f1bb | ||
|
|
c6f15b768e | ||
|
|
779937ca87 | ||
|
|
731856e974 | ||
|
|
baf54631c7 | ||
|
|
3e760d7fed | ||
|
|
679f00dc9c | ||
|
|
dae5c142d7 | ||
|
|
8e8873286e | ||
|
|
6693cbdde3 | ||
|
|
8b3ce2cb1e | ||
|
|
94cae90d1e | ||
|
|
c4b07f5113 | ||
|
|
01d73028f8 | ||
|
|
862f1203ed | ||
|
|
581e81c16e | ||
|
|
6c166c9530 | ||
|
|
4181ede6cd | ||
|
|
10745be661 | ||
|
|
ee2d73c740 | ||
|
|
e7fbcf5333 | ||
|
|
2810eccc82 | ||
|
|
baff419091 | ||
|
|
d13e0fdfde | ||
|
|
5a300c3c64 | ||
|
|
d8ddb9630a | ||
|
|
1537eeb5fa | ||
|
|
1a492537dd | ||
|
|
bd4107b002 | ||
|
|
7b48cadf6d | ||
|
|
6eab8a7a0a | ||
|
|
c6d14e5b7d | ||
|
|
ce95cafd54 | ||
|
|
4024faceab | ||
|
|
1afa931248 | ||
|
|
2474c39311 | ||
|
|
f6460a7365 | ||
|
|
b47e00858e | ||
|
|
b200a13c8d | ||
|
|
e6fabdbb31 | ||
|
|
cdd654eab7 | ||
|
|
2f07b96333 | ||
|
|
62e74b2b18 | ||
|
|
e75693b131 | ||
|
|
3cd14d4696 | ||
|
|
d29cc9892c | ||
|
|
d996882f4e | ||
|
|
17b6aa856d | ||
|
|
c21a9cf121 | ||
|
|
d3c4342c15 | ||
|
|
b4c2f8e69c | ||
|
|
a0f72a4e35 | ||
|
|
24844002de | ||
|
|
593edeae21 | ||
|
|
6df770d261 | ||
|
|
4f0c9dcede | ||
|
|
52425a8ca9 | ||
|
|
454acebe5a | ||
|
|
6fcf91e934 | ||
|
|
f89b8f2b29 | ||
|
|
648a7ba577 | ||
|
|
7c5594c39d | ||
|
|
274e8212a6 | ||
|
|
36c6ddaf86 | ||
|
|
15ed72bc09 | ||
|
|
ace8de93a9 | ||
|
|
45a4c0a284 | ||
|
|
c5e1e8abc0 | ||
|
|
ef38b69c39 | ||
|
|
ac6bde9996 | ||
|
|
23568cc0ba | ||
|
|
e61c2cfae7 | ||
|
|
38e0b11995 | ||
|
|
31903d1a80 | ||
|
|
3655284b57 | ||
|
|
db79a96118 | ||
|
|
5152e1fc63 | ||
|
|
c04e137b28 | ||
|
|
9b3342fbff | ||
|
|
d9a060a12d | ||
|
|
77f2fdd09a | ||
|
|
dba1ef6104 | ||
|
|
725da55905 | ||
|
|
cfac551ab8 | ||
|
|
c559fdbf04 | ||
|
|
e2ac47cd06 | ||
|
|
8ef16d9efb | ||
|
|
b6f726654e | ||
|
|
8cbb84c50f | ||
|
|
f3eac0c958 | ||
|
|
3211cfbbb1 | ||
|
|
c6934f5eab | ||
|
|
f8c054b879 | ||
|
|
ad2a64c82b | ||
|
|
9e0028fe73 | ||
|
|
dfbd01a980 | ||
|
|
86737955de | ||
|
|
7f0b027486 | ||
|
|
4d04ea079f | ||
|
|
6e1c41b536 | ||
|
|
275232f8c8 | ||
|
|
c8f9560aa3 | ||
|
|
315ee56024 | ||
|
|
e446ba0738 | ||
|
|
2ccd40677d | ||
|
|
41ef2a8cd2 | ||
|
|
d8acd1354f | ||
|
|
e28cfd1ad5 | ||
|
|
e5f5e64cdb | ||
|
|
b55d88dc15 | ||
|
|
f3360cbf66 | ||
|
|
065b621604 | ||
|
|
fd87df475c | ||
|
|
c7b6792956 | ||
|
|
1f2d11003d | ||
|
|
6432f11a6b | ||
|
|
7d53fb5951 | ||
|
|
b9aa3ef97d | ||
|
|
c271497ecb | ||
|
|
e05c4645ac | ||
|
|
63d8e6e21b |
No files matched your search
@@ -0,0 +1,4 @@
|
||||
# These are supported funding model platforms
|
||||
|
||||
github: [zricethezav]
|
||||
custom: ["https://www.paypal.me/zricethezav"]
|
||||
@@ -0,0 +1,29 @@
|
||||
---
|
||||
name: Bug report
|
||||
about: Create a report to help us improve
|
||||
title: ''
|
||||
labels: bug
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
**Describe the bug**
|
||||
A clear and concise description of what the bug is.
|
||||
|
||||
**To Reproduce**
|
||||
Steps to reproduce the behavior:
|
||||
|
||||
**Expected behavior**
|
||||
A clear and concise description of what you expected to happen.
|
||||
|
||||
**Screenshots**
|
||||
If applicable, add screenshots to help explain your problem.
|
||||
|
||||
**Basic Info (please complete the following information):**
|
||||
- OS:
|
||||
- Gitleaks Version:
|
||||
|
||||
**Additional context**
|
||||
Add any other context about the problem here.
|
||||
|
||||
cc @zricethezav
|
||||
@@ -0,0 +1,22 @@
|
||||
---
|
||||
name: Feature request
|
||||
about: Suggest an idea for this project
|
||||
title: ''
|
||||
labels: enhancement
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
**Is your feature request related to a problem? Please describe.**
|
||||
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
|
||||
|
||||
**Describe the solution you'd like**
|
||||
A clear and concise description of what you want to happen.
|
||||
|
||||
**Describe alternatives you've considered**
|
||||
A clear and concise description of any alternative solutions or features you've considered.
|
||||
|
||||
**Additional context**
|
||||
Add any other context or screenshots about the feature request here.
|
||||
|
||||
cc @zricethezav
|
||||
@@ -0,0 +1,8 @@
|
||||
### Description:
|
||||
Explain the purpose of the PR.
|
||||
|
||||
### Checklist:
|
||||
|
||||
* [ ] Does your PR pass tests?
|
||||
* [ ] Have you written new tests for your changes?
|
||||
* [ ] Have you lint your code locally prior to submission?
|
||||
+4
-4
@@ -4,10 +4,10 @@
|
||||
*.dll
|
||||
*.so
|
||||
*.dylib
|
||||
*.DS_STORE
|
||||
*.idea
|
||||
gitleaks
|
||||
build
|
||||
|
||||
# Test binary
|
||||
*.test
|
||||
*.out
|
||||
|
||||
examples
|
||||
src/gitleaksConfig
|
||||
+3
-15
@@ -1,20 +1,8 @@
|
||||
sudo: required
|
||||
language: go
|
||||
go:
|
||||
- 1.11
|
||||
- 1.14.x
|
||||
services:
|
||||
- docker
|
||||
script:
|
||||
- env GO111MODULE=on make test
|
||||
after_success:
|
||||
- env GO111MODULE=on go build
|
||||
- export REPO=zricethezav/gitleaks
|
||||
- export TAG=`if [ "$TRAVIS_BRANCH" == "master" ]; then echo "latest"; else echo $TRAVIS_BRANCH;
|
||||
fi`
|
||||
- if [ "$TRAVIS_PULL_REQUEST" = "false" ]; then make deploy; fi
|
||||
env:
|
||||
global:
|
||||
- secure: kUjq6Jgnm57V+ikDoYJ4IrFu4bLMHkaBb9uLtbQj0A545zZt4Dbooarnwqbfz2efqqMDZ9TXP6kN6677yWm0DyvFOCYx/Xq2innnVbBJczQciEUb5PI/9fcmLOfTe/QgGNi0GZOCdIOGlki2sbKxob6tTOUsm52ugRSJU92cXkX8w+Gzc6pC6fAb4moLE2QpwK1xWDHm2sHiZYExpBOH8eidSH5VPGVdNE9QmUA/FwwJ9NFGsZ8BgWCJPy7IJreyixsv2nNpiZNHoj0UgKe4wylzceu4sG/yQDIYk3fLVWBXSm/nSA17QYIjVMzQFjSAVC5dRqzq8HzFYiAYLKzkoOtrbBqEGtXzYZMN6yC8zEedk9gX6P6mvGpWYBy280uumcpGl6eoKYj5ke2H6kfcCUhMNTGZP17nmnTa1KFLAz1nxB1jfJwwO6v1l+xdytju5yAhm049Af7VyDM5GmE2x5ha48uKvK7wHtv+IKiZbbcR9ExsXvm21+7NVjQvRPzAw4/Sor9SG/yjoA/Sf7e4evy1w3fALv4WlaSisj5Yalmv7mzeeFZaIB7EIq6OryeRld2Rr1MZwwhZgIs7+SWwpjKfwhkfLVEUvSWCdnS2tnTydK6R6OFxfG5TGfR/WHooXLHEv5gMuKhUu/CqnbLyvI+8IOH2ybz2AtZWjf5n7oY=
|
||||
- secure: cIxKSkBNkPFAn243eHtwHJb8z6Uty1cZ43ZK/UABjwJoSrhu/roK4soqdZLwdVRA/0QswAlp6AC25Zs3ngLKGxxFHoeB8Tx6VLanE1zoi8OT0I2KbT92FdrLV4HlcRshKZtTFoTCfgVKPnWNKC+hil97CQzQPGRpZLBSfNefk5uCMnQiAzaJ5lyWPx+sjLHzpVlGA6aQx9ZeBQqngQJoDHKc0K3hKwug4h9mkkhyaYE3kgxtsdOYlHvOtQgVk+Zih5uW7ABOQCyAOaQVipXBC+uiuNf2DeAuGDaX69DTRKqPzuIasbhwyGqlfsr2JeofEWgZGmTaWGKMi03hnIY+U9+lHjygBW1qqVglODboouUrV3LwER9kqrT+ZFTM5Ca8VB+Gx5khkknbjWd06jpzRQxNXdukYN89kEaAHkBH844G99pMDqcZ32lHK7lpCu8n1H/Liz3ygoV6ScJXnYAP6y9rrd3bb9KEmnKhmFacVLRIAUw1vN/cgspJpl/Mk6s5rvGwsbQih1OxGyooOLxGjEGWqVDFgHFtyiwX9s9kT+hNTwKgbhp7Ragk/QuDYUPZ3Vum7HoiNPS9KpQNstLvDckdtd8h13JIw6nX+xdWbNKjjdYbAZRstJHUROQtNq3XdWNQ9YjqbCoybaxCOwOUTwOiTSWNKXjTFbFI5mR/ZO0=
|
||||
- COMMIT=${TRAVIS_COMMIT::8}
|
||||
- secure: o6uPX071qGRKgOQmitxiDr1j+KRW8W6ru0wmKNBFuUlZvQudwCUZMnVfk6OeofT1IgLCHmLS8ST81cTyeXqOQhYVZrlxTmEUpDHHRTu6dOj3eqRzdJow1LIWNpw5xfOaqXUdQ8+SQ47ZeSFapsmaY9oeRDvSJ8zLS4qUdgUylvZFJWjSrjzi2xemJa1l3MDdZRhEaNkfMliDGCv2vuUFp7tYz0QtyqBkBMORQl53dzgrcQcsRjDSE274WJl9CUg1l0pNMFsAbVCUGwUqCmKace9LXZ9JV00TRdg4EpryDsUCi23q0THnwstvRffwyJrw+xbhY/X3GKC4zOKqiCLJ4MTPQEIKlpVJQ9e9lWJ8FYhpUrl3QaHfEPINJ0taUfGhCyNzi5QBkSWbTcWVmRMmu+QIy7moW9crcz2xmVEUey7AaGwZT2Kk6JGw26w5q9IUy1Z9mwaljmHrUTqZrOX4Hj3UblpkHN+mGkoia/ipta5KhN5lTTIs4N3V+El7O2R2GggBrVHNiSualfydo+RX8k/S6PM1/C88IQO3Y2utoJrr415CznncvhF9Sc6tncZcShcNQj1iEOSsGxY2noW265eHzTMKJ/xuN6Bp9OXVK+8iOcUsz1T7F0UqwY3xnD8F7fBZ7IGG41DsXBDIcPmb+SIYbhv0uJjm3BEuv4TzIU0=
|
||||
- make test
|
||||
- make security-scan
|
||||
-245
@@ -1,245 +0,0 @@
|
||||
CHANGELOG
|
||||
=========
|
||||
2.1.0
|
||||
- `--commit` does not iterate on commit history. Now it directly accesses the commit object. https://github.com/zricethezav/gitleaks/pull/236
|
||||
- Fixing logging local repo path https://github.com/zricethezav/gitleaks/pull/204
|
||||
- Better README examples https://github.com/zricethezav/gitleaks/pull/202
|
||||
- Better logging on Windows https://github.com/zricethezav/gitleaks/pull/230
|
||||
- Better error messaging
|
||||
- Bunch new default rules https://github.com/zricethezav/gitleaks/pull/231 https://github.com/zricethezav/gitleaks/pull/241
|
||||
- `--repo-config` works on orgs and users now https://github.com/zricethezav/gitleaks/pull/239
|
||||
- Proper exit codes https://github.com/zricethezav/gitleaks/pull/244
|
||||
- Gitlab Token support https://github.com/zricethezav/gitleaks/pull/184
|
||||
|
||||
2.0.0
|
||||
----
|
||||
- rules introduced in the gitleaks configurationn
|
||||
- removing `--entropy` option
|
||||
- removing `--single-search` option
|
||||
|
||||
1.25.1
|
||||
----
|
||||
- Fixing #188
|
||||
|
||||
1.25.0
|
||||
----
|
||||
- Pretty big refactor, see `src` directory
|
||||
- Dropping dep for go modules
|
||||
- Separating email and author
|
||||
- Readding branch support with `--branch=`
|
||||
|
||||
1.24.0
|
||||
----
|
||||
- `--commit` now allows users to target a specific commit to audit
|
||||
- `--commit-stop` audit all commits up to and including what is specified at `--commit-stop`
|
||||
- Updated go-git version to 4.9.1
|
||||
|
||||
1.23.0
|
||||
----
|
||||
-- `--repo-config` allows users to load configs specific to a repo target
|
||||
|
||||
1.22.0
|
||||
----
|
||||
- context inclusion for redactions
|
||||
- noise reduction for entropy signals
|
||||
|
||||
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
|
||||
|
||||
1.19.3
|
||||
----
|
||||
- memoizing root commit
|
||||
- only count commits (not commit + parent) for total commit number
|
||||
|
||||
1.19.2
|
||||
----
|
||||
- fixed a bug where gitleaks was skipping the initial commit
|
||||
- commit cache now checks curr commit + parent commit hash
|
||||
- removed newlines from commit message
|
||||
|
||||
1.19.1
|
||||
----
|
||||
- mistakenly removed default whitelist files
|
||||
|
||||
1.19.0
|
||||
----
|
||||
- removed `--all-refs`. By default gitleaks now scans all branches, remote and local.
|
||||
- added commit memoizer to prevent duplicate commit audits
|
||||
- removed branch whitelist
|
||||
- removed branch from report as a commit is an object independent of branch
|
||||
- Better regexes for facebook, github, twitter (no more unbounded wildcards)
|
||||
|
||||
1.18.0
|
||||
----
|
||||
- fixing slack token
|
||||
- defaulting to single thread process
|
||||
- `--max-go=` --> `--threads=`
|
||||
- guarding `--threads=` > max threads available (you aint gettin any more performance)
|
||||
|
||||
1.17.0
|
||||
----
|
||||
- Default regex added to search: slack, telegram.
|
||||
- Default whitelisting: bin, doc, jpeg, gif
|
||||
|
||||
1.16.1
|
||||
----
|
||||
- Fixing default ssh auth logic
|
||||
|
||||
1.16.0
|
||||
----
|
||||
- Better commit coverage. Now iterates through each commit in git log and generates a patch with each commit's parent.
|
||||
- Removing the need for --private/-p option. Instead gitleaks will determine if the repo is private or not.
|
||||
|
||||
|
||||
1.15.0
|
||||
----
|
||||
- Whitelist repos use regex now
|
||||
- Whitelist repo check before clone
|
||||
|
||||
1.14.0
|
||||
----
|
||||
- Entropy Range support in gitleaks config
|
||||
|
||||
1.13.0
|
||||
----
|
||||
- Github PR support
|
||||
- Github has its own go file. All other services, bitbucket, gitlab, etc should follow this convention
|
||||
|
||||
1.12.1
|
||||
----
|
||||
- Show program usage when no arguments are provided
|
||||
- Exit program after the -h or --help options are used
|
||||
|
||||
1.12.0
|
||||
----
|
||||
- removing --csv option
|
||||
- --report option now requires .json or .csv in filename
|
||||
- adding total time to audit in logs
|
||||
|
||||
1.11.1
|
||||
----
|
||||
- fix commit whitelist logic
|
||||
|
||||
1.11.0
|
||||
-----
|
||||
- Commit depth option
|
||||
- Commit stats output
|
||||
|
||||
1.10.0
|
||||
-----
|
||||
- Add entropy option
|
||||
|
||||
1.9.0
|
||||
-----
|
||||
- exclude fork option
|
||||
|
||||
1.8.0
|
||||
-----
|
||||
- whitelist repos
|
||||
- sample config option
|
||||
|
||||
1.7.3
|
||||
-----
|
||||
- style points
|
||||
|
||||
1.7.2
|
||||
-----
|
||||
- Fixing dangling goroutines, removing channel messaging
|
||||
|
||||
1.7.1
|
||||
-----
|
||||
- Fixing bug where single repos were not being audited
|
||||
|
||||
1.7.0
|
||||
-----
|
||||
- Exit code == 2 on error
|
||||
- Cleaning up some logs
|
||||
- Removing some unreachable code
|
||||
|
||||
1.6.1
|
||||
-----
|
||||
- Recover from panic when diffing
|
||||
|
||||
1.6.0
|
||||
-----
|
||||
- Default maximum goroutines spawned is number of cores your CPU run with. See benchmarks in wiki.
|
||||
- Cleanup after each repo audit for organizations rather than waiting for the entire organization to complete. Eliminates the risk of running out of disk space.
|
||||
|
||||
|
||||
1.5.0
|
||||
-----
|
||||
- Support for CSV reporting
|
||||
- Refactoring Github user/owner audits
|
||||
|
||||
1.4.0
|
||||
-----
|
||||
- Support for single commit repos
|
||||
- Bumped go-git version from 4.5.0 to 4.7.0
|
||||
|
||||
1.3.0
|
||||
-----
|
||||
- Target specific branch
|
||||
|
||||
1.2.1
|
||||
-----
|
||||
- Check errors when generating commit patch
|
||||
|
||||
1.2.0
|
||||
-----
|
||||
- Added support for providing an alternate GitHub URL to support scanning GitHub Enterprise repositories
|
||||
|
||||
1.1.2
|
||||
-----
|
||||
- Added version option
|
||||
- Introduced changelog
|
||||
|
||||
1.1.1
|
||||
-----
|
||||
- Fixed commit patch order
|
||||
- Updated Readme
|
||||
|
||||
1.1.0
|
||||
-----
|
||||
- Fixed Twitter typo
|
||||
- Fixed sample docker command
|
||||
- Default clone option to "in-memory"
|
||||
- Added clone option for "disk"
|
||||
- Updated Makefile
|
||||
|
||||
1.0.0
|
||||
-----
|
||||
- Rewrite, see Readme.md: https://github.com/zricethezav/gitleaks/releases/tag/v1.0.0
|
||||
|
||||
0.4.0
|
||||
-----
|
||||
- Added support for external regexes
|
||||
|
||||
0.3.0
|
||||
-----
|
||||
- Added local scan
|
||||
- Meaningful exit codes
|
||||
- Timestamped logs
|
||||
- Refactored for some maintainability
|
||||
|
||||
0.2.0
|
||||
-----
|
||||
- Additionally regex checking
|
||||
- $HOME/.gitleaks/ directory for clones and reports
|
||||
- Pagination for Org/User list... no more partial repo lists
|
||||
- Persistent repos for Orgs and Users (no more re-cloning)
|
||||
- Updated README
|
||||
- Multi-staged Docker build
|
||||
- Travis CI
|
||||
|
||||
0.1.0
|
||||
-----
|
||||
- full git history search
|
||||
- regex/entropy checks
|
||||
- report generation
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
# Contributing Guidelines
|
||||
|
||||
The gitleaks project is under [GNU General Public License v3.0](LICENSE.md) and accepts
|
||||
contributions via GitHub pull requests.
|
||||
|
||||
## How to Contribute
|
||||
|
||||
Open a PR. Give the PR a descriptive title. Add some comments describing what is the purpose of the PR.
|
||||
|
||||
__BUT before you do that!__
|
||||
|
||||
Make sure you pass this list of requirements.
|
||||
|
||||
- You've run `go fmt`.
|
||||
- You've run `golint`.
|
||||
- You've added test cases for your changes.
|
||||
- You've updated [the changelog](CHANGELOG.md).
|
||||
- Your tests pass.
|
||||
|
||||
+4
-3
@@ -1,9 +1,10 @@
|
||||
FROM golang:1.11.6 AS build
|
||||
FROM golang:1.15.5 AS build
|
||||
WORKDIR /go/src/github.com/zricethezav/gitleaks
|
||||
ARG ldflags
|
||||
COPY . .
|
||||
RUN GO111MODULE=on CGO_ENABLED=0 go build -o bin/gitleaks *.go
|
||||
RUN GO111MODULE=on CGO_ENABLED=0 go build -o bin/gitleaks -ldflags "-X="${ldflags} *.go
|
||||
|
||||
FROM alpine:3.7
|
||||
FROM alpine:3.11
|
||||
RUN apk add --no-cache bash git openssh
|
||||
COPY --from=build /go/src/github.com/zricethezav/gitleaks/bin/* /usr/bin/
|
||||
ENTRYPOINT ["gitleaks"]
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2019 Zachary Rice
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
-674
@@ -1,674 +0,0 @@
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 3, 29 June 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The GNU General Public License is a free, copyleft license for
|
||||
software and other kinds of works.
|
||||
|
||||
The licenses for most software and other practical works are designed
|
||||
to take away your freedom to share and change the works. By contrast,
|
||||
the GNU General Public License is intended to guarantee your freedom to
|
||||
share and change all versions of a program--to make sure it remains free
|
||||
software for all its users. We, the Free Software Foundation, use the
|
||||
GNU General Public License for most of our software; it applies also to
|
||||
any other work released this way by its authors. You can apply it to
|
||||
your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
them if you wish), that you receive source code or can get it if you
|
||||
want it, that you can change the software or use pieces of it in new
|
||||
free programs, and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to prevent others from denying you
|
||||
these rights or asking you to surrender the rights. Therefore, you have
|
||||
certain responsibilities if you distribute copies of the software, or if
|
||||
you modify it: responsibilities to respect the freedom of others.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must pass on to the recipients the same
|
||||
freedoms that you received. You must make sure that they, too, receive
|
||||
or can get the source code. And you must show them these terms so they
|
||||
know their rights.
|
||||
|
||||
Developers that use the GNU GPL protect your rights with two steps:
|
||||
(1) assert copyright on the software, and (2) offer you this License
|
||||
giving you legal permission to copy, distribute and/or modify it.
|
||||
|
||||
For the developers' and authors' protection, the GPL clearly explains
|
||||
that there is no warranty for this free software. For both users' and
|
||||
authors' sake, the GPL requires that modified versions be marked as
|
||||
changed, so that their problems will not be attributed erroneously to
|
||||
authors of previous versions.
|
||||
|
||||
Some devices are designed to deny users access to install or run
|
||||
modified versions of the software inside them, although the manufacturer
|
||||
can do so. This is fundamentally incompatible with the aim of
|
||||
protecting users' freedom to change the software. The systematic
|
||||
pattern of such abuse occurs in the area of products for individuals to
|
||||
use, which is precisely where it is most unacceptable. Therefore, we
|
||||
have designed this version of the GPL to prohibit the practice for those
|
||||
products. If such problems arise substantially in other domains, we
|
||||
stand ready to extend this provision to those domains in future versions
|
||||
of the GPL, as needed to protect the freedom of users.
|
||||
|
||||
Finally, every program is threatened constantly by software patents.
|
||||
States should not allow patents to restrict development and use of
|
||||
software on general-purpose computers, but in those that do, we wish to
|
||||
avoid the special danger that patents applied to a free program could
|
||||
make it effectively proprietary. To prevent this, the GPL assures that
|
||||
patents cannot be used to render the program non-free.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
TERMS AND CONDITIONS
|
||||
|
||||
0. Definitions.
|
||||
|
||||
"This License" refers to version 3 of the GNU General Public License.
|
||||
|
||||
"Copyright" also means copyright-like laws that apply to other kinds of
|
||||
works, such as semiconductor masks.
|
||||
|
||||
"The Program" refers to any copyrightable work licensed under this
|
||||
License. Each licensee is addressed as "you". "Licensees" and
|
||||
"recipients" may be individuals or organizations.
|
||||
|
||||
To "modify" a work means to copy from or adapt all or part of the work
|
||||
in a fashion requiring copyright permission, other than the making of an
|
||||
exact copy. The resulting work is called a "modified version" of the
|
||||
earlier work or a work "based on" the earlier work.
|
||||
|
||||
A "covered work" means either the unmodified Program or a work based
|
||||
on the Program.
|
||||
|
||||
To "propagate" a work means to do anything with it that, without
|
||||
permission, would make you directly or secondarily liable for
|
||||
infringement under applicable copyright law, except executing it on a
|
||||
computer or modifying a private copy. Propagation includes copying,
|
||||
distribution (with or without modification), making available to the
|
||||
public, and in some countries other activities as well.
|
||||
|
||||
To "convey" a work means any kind of propagation that enables other
|
||||
parties to make or receive copies. Mere interaction with a user through
|
||||
a computer network, with no transfer of a copy, is not conveying.
|
||||
|
||||
An interactive user interface displays "Appropriate Legal Notices"
|
||||
to the extent that it includes a convenient and prominently visible
|
||||
feature that (1) displays an appropriate copyright notice, and (2)
|
||||
tells the user that there is no warranty for the work (except to the
|
||||
extent that warranties are provided), that licensees may convey the
|
||||
work under this License, and how to view a copy of this License. If
|
||||
the interface presents a list of user commands or options, such as a
|
||||
menu, a prominent item in the list meets this criterion.
|
||||
|
||||
1. Source Code.
|
||||
|
||||
The "source code" for a work means the preferred form of the work
|
||||
for making modifications to it. "Object code" means any non-source
|
||||
form of a work.
|
||||
|
||||
A "Standard Interface" means an interface that either is an official
|
||||
standard defined by a recognized standards body, or, in the case of
|
||||
interfaces specified for a particular programming language, one that
|
||||
is widely used among developers working in that language.
|
||||
|
||||
The "System Libraries" of an executable work include anything, other
|
||||
than the work as a whole, that (a) is included in the normal form of
|
||||
packaging a Major Component, but which is not part of that Major
|
||||
Component, and (b) serves only to enable use of the work with that
|
||||
Major Component, or to implement a Standard Interface for which an
|
||||
implementation is available to the public in source code form. A
|
||||
"Major Component", in this context, means a major essential component
|
||||
(kernel, window system, and so on) of the specific operating system
|
||||
(if any) on which the executable work runs, or a compiler used to
|
||||
produce the work, or an object code interpreter used to run it.
|
||||
|
||||
The "Corresponding Source" for a work in object code form means all
|
||||
the source code needed to generate, install, and (for an executable
|
||||
work) run the object code and to modify the work, including scripts to
|
||||
control those activities. However, it does not include the work's
|
||||
System Libraries, or general-purpose tools or generally available free
|
||||
programs which are used unmodified in performing those activities but
|
||||
which are not part of the work. For example, Corresponding Source
|
||||
includes interface definition files associated with source files for
|
||||
the work, and the source code for shared libraries and dynamically
|
||||
linked subprograms that the work is specifically designed to require,
|
||||
such as by intimate data communication or control flow between those
|
||||
subprograms and other parts of the work.
|
||||
|
||||
The Corresponding Source need not include anything that users
|
||||
can regenerate automatically from other parts of the Corresponding
|
||||
Source.
|
||||
|
||||
The Corresponding Source for a work in source code form is that
|
||||
same work.
|
||||
|
||||
2. Basic Permissions.
|
||||
|
||||
All rights granted under this License are granted for the term of
|
||||
copyright on the Program, and are irrevocable provided the stated
|
||||
conditions are met. This License explicitly affirms your unlimited
|
||||
permission to run the unmodified Program. The output from running a
|
||||
covered work is covered by this License only if the output, given its
|
||||
content, constitutes a covered work. This License acknowledges your
|
||||
rights of fair use or other equivalent, as provided by copyright law.
|
||||
|
||||
You may make, run and propagate covered works that you do not
|
||||
convey, without conditions so long as your license otherwise remains
|
||||
in force. You may convey covered works to others for the sole purpose
|
||||
of having them make modifications exclusively for you, or provide you
|
||||
with facilities for running those works, provided that you comply with
|
||||
the terms of this License in conveying all material for which you do
|
||||
not control copyright. Those thus making or running the covered works
|
||||
for you must do so exclusively on your behalf, under your direction
|
||||
and control, on terms that prohibit them from making any copies of
|
||||
your copyrighted material outside their relationship with you.
|
||||
|
||||
Conveying under any other circumstances is permitted solely under
|
||||
the conditions stated below. Sublicensing is not allowed; section 10
|
||||
makes it unnecessary.
|
||||
|
||||
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||
|
||||
No covered work shall be deemed part of an effective technological
|
||||
measure under any applicable law fulfilling obligations under article
|
||||
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
||||
similar laws prohibiting or restricting circumvention of such
|
||||
measures.
|
||||
|
||||
When you convey a covered work, you waive any legal power to forbid
|
||||
circumvention of technological measures to the extent such circumvention
|
||||
is effected by exercising rights under this License with respect to
|
||||
the covered work, and you disclaim any intention to limit operation or
|
||||
modification of the work as a means of enforcing, against the work's
|
||||
users, your or third parties' legal rights to forbid circumvention of
|
||||
technological measures.
|
||||
|
||||
4. Conveying Verbatim Copies.
|
||||
|
||||
You may convey verbatim copies of the Program's source code as you
|
||||
receive it, in any medium, provided that you conspicuously and
|
||||
appropriately publish on each copy an appropriate copyright notice;
|
||||
keep intact all notices stating that this License and any
|
||||
non-permissive terms added in accord with section 7 apply to the code;
|
||||
keep intact all notices of the absence of any warranty; and give all
|
||||
recipients a copy of this License along with the Program.
|
||||
|
||||
You may charge any price or no price for each copy that you convey,
|
||||
and you may offer support or warranty protection for a fee.
|
||||
|
||||
5. Conveying Modified Source Versions.
|
||||
|
||||
You may convey a work based on the Program, or the modifications to
|
||||
produce it from the Program, in the form of source code under the
|
||||
terms of section 4, provided that you also meet all of these conditions:
|
||||
|
||||
a) The work must carry prominent notices stating that you modified
|
||||
it, and giving a relevant date.
|
||||
|
||||
b) The work must carry prominent notices stating that it is
|
||||
released under this License and any conditions added under section
|
||||
7. This requirement modifies the requirement in section 4 to
|
||||
"keep intact all notices".
|
||||
|
||||
c) You must license the entire work, as a whole, under this
|
||||
License to anyone who comes into possession of a copy. This
|
||||
License will therefore apply, along with any applicable section 7
|
||||
additional terms, to the whole of the work, and all its parts,
|
||||
regardless of how they are packaged. This License gives no
|
||||
permission to license the work in any other way, but it does not
|
||||
invalidate such permission if you have separately received it.
|
||||
|
||||
d) If the work has interactive user interfaces, each must display
|
||||
Appropriate Legal Notices; however, if the Program has interactive
|
||||
interfaces that do not display Appropriate Legal Notices, your
|
||||
work need not make them do so.
|
||||
|
||||
A compilation of a covered work with other separate and independent
|
||||
works, which are not by their nature extensions of the covered work,
|
||||
and which are not combined with it such as to form a larger program,
|
||||
in or on a volume of a storage or distribution medium, is called an
|
||||
"aggregate" if the compilation and its resulting copyright are not
|
||||
used to limit the access or legal rights of the compilation's users
|
||||
beyond what the individual works permit. Inclusion of a covered work
|
||||
in an aggregate does not cause this License to apply to the other
|
||||
parts of the aggregate.
|
||||
|
||||
6. Conveying Non-Source Forms.
|
||||
|
||||
You may convey a covered work in object code form under the terms
|
||||
of sections 4 and 5, provided that you also convey the
|
||||
machine-readable Corresponding Source under the terms of this License,
|
||||
in one of these ways:
|
||||
|
||||
a) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by the
|
||||
Corresponding Source fixed on a durable physical medium
|
||||
customarily used for software interchange.
|
||||
|
||||
b) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by a
|
||||
written offer, valid for at least three years and valid for as
|
||||
long as you offer spare parts or customer support for that product
|
||||
model, to give anyone who possesses the object code either (1) a
|
||||
copy of the Corresponding Source for all the software in the
|
||||
product that is covered by this License, on a durable physical
|
||||
medium customarily used for software interchange, for a price no
|
||||
more than your reasonable cost of physically performing this
|
||||
conveying of source, or (2) access to copy the
|
||||
Corresponding Source from a network server at no charge.
|
||||
|
||||
c) Convey individual copies of the object code with a copy of the
|
||||
written offer to provide the Corresponding Source. This
|
||||
alternative is allowed only occasionally and noncommercially, and
|
||||
only if you received the object code with such an offer, in accord
|
||||
with subsection 6b.
|
||||
|
||||
d) Convey the object code by offering access from a designated
|
||||
place (gratis or for a charge), and offer equivalent access to the
|
||||
Corresponding Source in the same way through the same place at no
|
||||
further charge. You need not require recipients to copy the
|
||||
Corresponding Source along with the object code. If the place to
|
||||
copy the object code is a network server, the Corresponding Source
|
||||
may be on a different server (operated by you or a third party)
|
||||
that supports equivalent copying facilities, provided you maintain
|
||||
clear directions next to the object code saying where to find the
|
||||
Corresponding Source. Regardless of what server hosts the
|
||||
Corresponding Source, you remain obligated to ensure that it is
|
||||
available for as long as needed to satisfy these requirements.
|
||||
|
||||
e) Convey the object code using peer-to-peer transmission, provided
|
||||
you inform other peers where the object code and Corresponding
|
||||
Source of the work are being offered to the general public at no
|
||||
charge under subsection 6d.
|
||||
|
||||
A separable portion of the object code, whose source code is excluded
|
||||
from the Corresponding Source as a System Library, need not be
|
||||
included in conveying the object code work.
|
||||
|
||||
A "User Product" is either (1) a "consumer product", which means any
|
||||
tangible personal property which is normally used for personal, family,
|
||||
or household purposes, or (2) anything designed or sold for incorporation
|
||||
into a dwelling. In determining whether a product is a consumer product,
|
||||
doubtful cases shall be resolved in favor of coverage. For a particular
|
||||
product received by a particular user, "normally used" refers to a
|
||||
typical or common use of that class of product, regardless of the status
|
||||
of the particular user or of the way in which the particular user
|
||||
actually uses, or expects or is expected to use, the product. A product
|
||||
is a consumer product regardless of whether the product has substantial
|
||||
commercial, industrial or non-consumer uses, unless such uses represent
|
||||
the only significant mode of use of the product.
|
||||
|
||||
"Installation Information" for a User Product means any methods,
|
||||
procedures, authorization keys, or other information required to install
|
||||
and execute modified versions of a covered work in that User Product from
|
||||
a modified version of its Corresponding Source. The information must
|
||||
suffice to ensure that the continued functioning of the modified object
|
||||
code is in no case prevented or interfered with solely because
|
||||
modification has been made.
|
||||
|
||||
If you convey an object code work under this section in, or with, or
|
||||
specifically for use in, a User Product, and the conveying occurs as
|
||||
part of a transaction in which the right of possession and use of the
|
||||
User Product is transferred to the recipient in perpetuity or for a
|
||||
fixed term (regardless of how the transaction is characterized), the
|
||||
Corresponding Source conveyed under this section must be accompanied
|
||||
by the Installation Information. But this requirement does not apply
|
||||
if neither you nor any third party retains the ability to install
|
||||
modified object code on the User Product (for example, the work has
|
||||
been installed in ROM).
|
||||
|
||||
The requirement to provide Installation Information does not include a
|
||||
requirement to continue to provide support service, warranty, or updates
|
||||
for a work that has been modified or installed by the recipient, or for
|
||||
the User Product in which it has been modified or installed. Access to a
|
||||
network may be denied when the modification itself materially and
|
||||
adversely affects the operation of the network or violates the rules and
|
||||
protocols for communication across the network.
|
||||
|
||||
Corresponding Source conveyed, and Installation Information provided,
|
||||
in accord with this section must be in a format that is publicly
|
||||
documented (and with an implementation available to the public in
|
||||
source code form), and must require no special password or key for
|
||||
unpacking, reading or copying.
|
||||
|
||||
7. Additional Terms.
|
||||
|
||||
"Additional permissions" are terms that supplement the terms of this
|
||||
License by making exceptions from one or more of its conditions.
|
||||
Additional permissions that are applicable to the entire Program shall
|
||||
be treated as though they were included in this License, to the extent
|
||||
that they are valid under applicable law. If additional permissions
|
||||
apply only to part of the Program, that part may be used separately
|
||||
under those permissions, but the entire Program remains governed by
|
||||
this License without regard to the additional permissions.
|
||||
|
||||
When you convey a copy of a covered work, you may at your option
|
||||
remove any additional permissions from that copy, or from any part of
|
||||
it. (Additional permissions may be written to require their own
|
||||
removal in certain cases when you modify the work.) You may place
|
||||
additional permissions on material, added by you to a covered work,
|
||||
for which you have or can give appropriate copyright permission.
|
||||
|
||||
Notwithstanding any other provision of this License, for material you
|
||||
add to a covered work, you may (if authorized by the copyright holders of
|
||||
that material) supplement the terms of this License with terms:
|
||||
|
||||
a) Disclaiming warranty or limiting liability differently from the
|
||||
terms of sections 15 and 16 of this License; or
|
||||
|
||||
b) Requiring preservation of specified reasonable legal notices or
|
||||
author attributions in that material or in the Appropriate Legal
|
||||
Notices displayed by works containing it; or
|
||||
|
||||
c) Prohibiting misrepresentation of the origin of that material, or
|
||||
requiring that modified versions of such material be marked in
|
||||
reasonable ways as different from the original version; or
|
||||
|
||||
d) Limiting the use for publicity purposes of names of licensors or
|
||||
authors of the material; or
|
||||
|
||||
e) Declining to grant rights under trademark law for use of some
|
||||
trade names, trademarks, or service marks; or
|
||||
|
||||
f) Requiring indemnification of licensors and authors of that
|
||||
material by anyone who conveys the material (or modified versions of
|
||||
it) with contractual assumptions of liability to the recipient, for
|
||||
any liability that these contractual assumptions directly impose on
|
||||
those licensors and authors.
|
||||
|
||||
All other non-permissive additional terms are considered "further
|
||||
restrictions" within the meaning of section 10. If the Program as you
|
||||
received it, or any part of it, contains a notice stating that it is
|
||||
governed by this License along with a term that is a further
|
||||
restriction, you may remove that term. If a license document contains
|
||||
a further restriction but permits relicensing or conveying under this
|
||||
License, you may add to a covered work material governed by the terms
|
||||
of that license document, provided that the further restriction does
|
||||
not survive such relicensing or conveying.
|
||||
|
||||
If you add terms to a covered work in accord with this section, you
|
||||
must place, in the relevant source files, a statement of the
|
||||
additional terms that apply to those files, or a notice indicating
|
||||
where to find the applicable terms.
|
||||
|
||||
Additional terms, permissive or non-permissive, may be stated in the
|
||||
form of a separately written license, or stated as exceptions;
|
||||
the above requirements apply either way.
|
||||
|
||||
8. Termination.
|
||||
|
||||
You may not propagate or modify a covered work except as expressly
|
||||
provided under this License. Any attempt otherwise to propagate or
|
||||
modify it is void, and will automatically terminate your rights under
|
||||
this License (including any patent licenses granted under the third
|
||||
paragraph of section 11).
|
||||
|
||||
However, if you cease all violation of this License, then your
|
||||
license from a particular copyright holder is reinstated (a)
|
||||
provisionally, unless and until the copyright holder explicitly and
|
||||
finally terminates your license, and (b) permanently, if the copyright
|
||||
holder fails to notify you of the violation by some reasonable means
|
||||
prior to 60 days after the cessation.
|
||||
|
||||
Moreover, your license from a particular copyright holder is
|
||||
reinstated permanently if the copyright holder notifies you of the
|
||||
violation by some reasonable means, this is the first time you have
|
||||
received notice of violation of this License (for any work) from that
|
||||
copyright holder, and you cure the violation prior to 30 days after
|
||||
your receipt of the notice.
|
||||
|
||||
Termination of your rights under this section does not terminate the
|
||||
licenses of parties who have received copies or rights from you under
|
||||
this License. If your rights have been terminated and not permanently
|
||||
reinstated, you do not qualify to receive new licenses for the same
|
||||
material under section 10.
|
||||
|
||||
9. Acceptance Not Required for Having Copies.
|
||||
|
||||
You are not required to accept this License in order to receive or
|
||||
run a copy of the Program. Ancillary propagation of a covered work
|
||||
occurring solely as a consequence of using peer-to-peer transmission
|
||||
to receive a copy likewise does not require acceptance. However,
|
||||
nothing other than this License grants you permission to propagate or
|
||||
modify any covered work. These actions infringe copyright if you do
|
||||
not accept this License. Therefore, by modifying or propagating a
|
||||
covered work, you indicate your acceptance of this License to do so.
|
||||
|
||||
10. Automatic Licensing of Downstream Recipients.
|
||||
|
||||
Each time you convey a covered work, the recipient automatically
|
||||
receives a license from the original licensors, to run, modify and
|
||||
propagate that work, subject to this License. You are not responsible
|
||||
for enforcing compliance by third parties with this License.
|
||||
|
||||
An "entity transaction" is a transaction transferring control of an
|
||||
organization, or substantially all assets of one, or subdividing an
|
||||
organization, or merging organizations. If propagation of a covered
|
||||
work results from an entity transaction, each party to that
|
||||
transaction who receives a copy of the work also receives whatever
|
||||
licenses to the work the party's predecessor in interest had or could
|
||||
give under the previous paragraph, plus a right to possession of the
|
||||
Corresponding Source of the work from the predecessor in interest, if
|
||||
the predecessor has it or can get it with reasonable efforts.
|
||||
|
||||
You may not impose any further restrictions on the exercise of the
|
||||
rights granted or affirmed under this License. For example, you may
|
||||
not impose a license fee, royalty, or other charge for exercise of
|
||||
rights granted under this License, and you may not initiate litigation
|
||||
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
||||
any patent claim is infringed by making, using, selling, offering for
|
||||
sale, or importing the Program or any portion of it.
|
||||
|
||||
11. Patents.
|
||||
|
||||
A "contributor" is a copyright holder who authorizes use under this
|
||||
License of the Program or a work on which the Program is based. The
|
||||
work thus licensed is called the contributor's "contributor version".
|
||||
|
||||
A contributor's "essential patent claims" are all patent claims
|
||||
owned or controlled by the contributor, whether already acquired or
|
||||
hereafter acquired, that would be infringed by some manner, permitted
|
||||
by this License, of making, using, or selling its contributor version,
|
||||
but do not include claims that would be infringed only as a
|
||||
consequence of further modification of the contributor version. For
|
||||
purposes of this definition, "control" includes the right to grant
|
||||
patent sublicenses in a manner consistent with the requirements of
|
||||
this License.
|
||||
|
||||
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
||||
patent license under the contributor's essential patent claims, to
|
||||
make, use, sell, offer for sale, import and otherwise run, modify and
|
||||
propagate the contents of its contributor version.
|
||||
|
||||
In the following three paragraphs, a "patent license" is any express
|
||||
agreement or commitment, however denominated, not to enforce a patent
|
||||
(such as an express permission to practice a patent or covenant not to
|
||||
sue for patent infringement). To "grant" such a patent license to a
|
||||
party means to make such an agreement or commitment not to enforce a
|
||||
patent against the party.
|
||||
|
||||
If you convey a covered work, knowingly relying on a patent license,
|
||||
and the Corresponding Source of the work is not available for anyone
|
||||
to copy, free of charge and under the terms of this License, through a
|
||||
publicly available network server or other readily accessible means,
|
||||
then you must either (1) cause the Corresponding Source to be so
|
||||
available, or (2) arrange to deprive yourself of the benefit of the
|
||||
patent license for this particular work, or (3) arrange, in a manner
|
||||
consistent with the requirements of this License, to extend the patent
|
||||
license to downstream recipients. "Knowingly relying" means you have
|
||||
actual knowledge that, but for the patent license, your conveying the
|
||||
covered work in a country, or your recipient's use of the covered work
|
||||
in a country, would infringe one or more identifiable patents in that
|
||||
country that you have reason to believe are valid.
|
||||
|
||||
If, pursuant to or in connection with a single transaction or
|
||||
arrangement, you convey, or propagate by procuring conveyance of, a
|
||||
covered work, and grant a patent license to some of the parties
|
||||
receiving the covered work authorizing them to use, propagate, modify
|
||||
or convey a specific copy of the covered work, then the patent license
|
||||
you grant is automatically extended to all recipients of the covered
|
||||
work and works based on it.
|
||||
|
||||
A patent license is "discriminatory" if it does not include within
|
||||
the scope of its coverage, prohibits the exercise of, or is
|
||||
conditioned on the non-exercise of one or more of the rights that are
|
||||
specifically granted under this License. You may not convey a covered
|
||||
work if you are a party to an arrangement with a third party that is
|
||||
in the business of distributing software, under which you make payment
|
||||
to the third party based on the extent of your activity of conveying
|
||||
the work, and under which the third party grants, to any of the
|
||||
parties who would receive the covered work from you, a discriminatory
|
||||
patent license (a) in connection with copies of the covered work
|
||||
conveyed by you (or copies made from those copies), or (b) primarily
|
||||
for and in connection with specific products or compilations that
|
||||
contain the covered work, unless you entered into that arrangement,
|
||||
or that patent license was granted, prior to 28 March 2007.
|
||||
|
||||
Nothing in this License shall be construed as excluding or limiting
|
||||
any implied license or other defenses to infringement that may
|
||||
otherwise be available to you under applicable patent law.
|
||||
|
||||
12. No Surrender of Others' Freedom.
|
||||
|
||||
If conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot convey a
|
||||
covered work so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you may
|
||||
not convey it at all. For example, if you agree to terms that obligate you
|
||||
to collect a royalty for further conveying from those to whom you convey
|
||||
the Program, the only way you could satisfy both those terms and this
|
||||
License would be to refrain entirely from conveying the Program.
|
||||
|
||||
13. Use with the GNU Affero General Public License.
|
||||
|
||||
Notwithstanding any other provision of this License, you have
|
||||
permission to link or combine any covered work with a work licensed
|
||||
under version 3 of the GNU Affero General Public License into a single
|
||||
combined work, and to convey the resulting work. The terms of this
|
||||
License will continue to apply to the part which is the covered work,
|
||||
but the special requirements of the GNU Affero General Public License,
|
||||
section 13, concerning interaction through a network will apply to the
|
||||
combination as such.
|
||||
|
||||
14. Revised Versions of this License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions of
|
||||
the GNU General Public License from time to time. Such new versions will
|
||||
be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the
|
||||
Program specifies that a certain numbered version of the GNU General
|
||||
Public License "or any later version" applies to it, you have the
|
||||
option of following the terms and conditions either of that numbered
|
||||
version or of any later version published by the Free Software
|
||||
Foundation. If the Program does not specify a version number of the
|
||||
GNU General Public License, you may choose any version ever published
|
||||
by the Free Software Foundation.
|
||||
|
||||
If the Program specifies that a proxy can decide which future
|
||||
versions of the GNU General Public License can be used, that proxy's
|
||||
public statement of acceptance of a version permanently authorizes you
|
||||
to choose that version for the Program.
|
||||
|
||||
Later license versions may give you additional or different
|
||||
permissions. However, no additional obligations are imposed on any
|
||||
author or copyright holder as a result of your choosing to follow a
|
||||
later version.
|
||||
|
||||
15. Disclaimer of Warranty.
|
||||
|
||||
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
||||
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
||||
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
||||
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
||||
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
||||
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
||||
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
|
||||
16. Limitation of Liability.
|
||||
|
||||
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
||||
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
||||
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
||||
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
||||
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
||||
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
||||
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
||||
SUCH DAMAGES.
|
||||
|
||||
17. Interpretation of Sections 15 and 16.
|
||||
|
||||
If the disclaimer of warranty and limitation of liability provided
|
||||
above cannot be given local legal effect according to their terms,
|
||||
reviewing courts shall apply local law that most closely approximates
|
||||
an absolute waiver of all civil liability in connection with the
|
||||
Program, unless a warranty or assumption of liability accompanies a
|
||||
copy of the Program in return for a fee.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
state the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program does terminal interaction, make it output a short
|
||||
notice like this when it starts in an interactive mode:
|
||||
|
||||
<program> Copyright (C) <year> <name of author>
|
||||
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||
parts of the General Public License. Of course, your program's commands
|
||||
might be different; for a GUI interface, you would use an "about box".
|
||||
|
||||
You should also get your employer (if you work as a programmer) or school,
|
||||
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
||||
For more information on this, and how to apply and follow the GNU GPL, see
|
||||
<http://www.gnu.org/licenses/>.
|
||||
|
||||
The GNU General Public License does not permit incorporating your program
|
||||
into proprietary programs. If your program is a subroutine library, you
|
||||
may consider it more useful to permit linking proprietary applications with
|
||||
the library. If this is what you want to do, use the GNU Lesser General
|
||||
Public License instead of this License. But first, please read
|
||||
<http://www.gnu.org/philosophy/why-not-lgpl.html>.
|
||||
@@ -1,22 +1,49 @@
|
||||
.PHONY: test build-all deploy
|
||||
.PHONY: test test-cover build release-builds
|
||||
|
||||
VERSION := `git fetch --tags && git tag | sort -V | tail -1`
|
||||
PKG=github.com/zricethezav/gitleaks
|
||||
LDFLAGS=-ldflags "-X=github.com/zricethezav/gitleaks/v7/version.Version=$(VERSION)"
|
||||
_LDFLAGS="github.com/zricethezav/gitleaks/v7/version.Version=$(VERSION)"
|
||||
COVER=--cover --coverprofile=cover.out
|
||||
|
||||
test-cover:
|
||||
go test ./... --race $(COVER) $(PKG) -v
|
||||
go tool cover -html=cover.out
|
||||
|
||||
test:
|
||||
go get golang.org/x/lint/golint
|
||||
go fmt
|
||||
golint
|
||||
go test --race --cover github.com/zricethezav/gitleaks/src -v
|
||||
deploy:
|
||||
@echo "$(DOCKER_PASSWORD)" | docker login -u "$(DOCKER_USERNAME)" --password-stdin
|
||||
docker build -f Dockerfile -t $(REPO):$(TAG) .
|
||||
echo "Pushing $(REPO):$(COMMIT) $(REPO):$(TAG)"
|
||||
docker push $(REPO)
|
||||
build-all:
|
||||
go fmt ./...
|
||||
go vet ./...
|
||||
golint ./...
|
||||
go test ./... --race $(PKG) -v
|
||||
|
||||
build:
|
||||
go fmt ./...
|
||||
golint ./...
|
||||
go vet ./...
|
||||
go mod tidy
|
||||
go build $(LDFLAGS)
|
||||
|
||||
security-scan:
|
||||
go get github.com/securego/gosec/cmd/gosec
|
||||
gosec -no-fail ./...
|
||||
|
||||
release-builds:
|
||||
rm -rf build
|
||||
mkdir build
|
||||
env GOOS="windows" GOARCH="amd64" go build -o "build/gitleaks-windows-amd64.exe"
|
||||
env GOOS="windows" GOARCH="386" go build -o "build/gitleaks-windows-386.exe"
|
||||
env GOOS="linux" GOARCH="amd64" go build -o "build/gitleaks-linux-amd64"
|
||||
env GOOS="linux" GOARCH="arm" go build -o "build/gitleaks-linux-arm"
|
||||
env GOOS="linux" GOARCH="mips" go build -o "build/gitleaks-linux-mips"
|
||||
env GOOS="linux" GOARCH="mips" go build -o "build/gitleaks-linux-mips"
|
||||
env GOOS="darwin" GOARCH="amd64" go build -o "build/gitleaks-darwin-amd64"
|
||||
env GOOS="windows" GOARCH="amd64" go build -o "build/gitleaks-windows-amd64.exe" $(LDFLAGS)
|
||||
env GOOS="windows" GOARCH="386" go build -o "build/gitleaks-windows-386.exe" $(LDFLAGS)
|
||||
env GOOS="linux" GOARCH="amd64" go build -o "build/gitleaks-linux-amd64" $(LDFLAGS)
|
||||
env GOOS="linux" GOARCH="arm" go build -o "build/gitleaks-linux-arm" $(LDFLAGS)
|
||||
env GOOS="linux" GOARCH="mips" go build -o "build/gitleaks-linux-mips" $(LDFLAGS)
|
||||
env GOOS="linux" GOARCH="mips" go build -o "build/gitleaks-linux-mips" $(LDFLAGS)
|
||||
env GOOS="darwin" GOARCH="amd64" go build -o "build/gitleaks-darwin-amd64" $(LDFLAGS)
|
||||
|
||||
deploy:
|
||||
@echo "$(DOCKER_PASSWORD)" | docker login -u "$(DOCKER_USERNAME)" --password-stdin
|
||||
docker build --build-arg ldflags=$(_LDFLAGS) -f Dockerfile -t zricethezav/gitleaks:latest -t zricethezav/gitleaks:$(VERSION) .
|
||||
echo "Pushing zricethezav/gitleaks:$(VERSION) and zricethezav/gitleaks:latest"
|
||||
docker push zricethezav/gitleaks
|
||||
|
||||
dockerbuild:
|
||||
docker build --build-arg ldflags=$(_LDFLAGS) -f Dockerfile -t zricethezav/gitleaks:latest -t zricethezav/gitleaks:$(VERSION) .
|
||||
@@ -1,195 +1,267 @@
|
||||
Gitleaks
|
||||
--------
|
||||
|
||||
<p align="left">
|
||||
<p align="center">
|
||||
<img alt="gitleaks" src="https://raw.githubusercontent.com/zricethezav/gifs/master/gitleakslogo.png" height="70" />
|
||||
<p align="center">
|
||||
<a href="https://travis-ci.org/zricethezav/gitleaks"><img alt="Travis" src="https://img.shields.io/travis/zricethezav/gitleaks/master.svg?style=flat-square"></a>
|
||||
<a href="https://gitter.im/gitleaks/gitleaks"><img alt="Travis" src="https://badges.gitter.im/gitleaks/gitleaks.svg?style=flat-square"></a>
|
||||
</p>
|
||||
</p>
|
||||
|
||||
Audit git repos for secrets. Gitleaks provides a way for you to find unencrypted secrets and other unwanted data types in git source code repositories. As part of it's core functionality, it provides:
|
||||
|
||||
* Github and Gitlab support including support for bulk organization and repository owner (user) repository scans, as well as pull request scanning for use in common CI workflows.
|
||||
* Support for private repository scans, and repositories that require key based authentication
|
||||
* Output in CSV and JSON formats for consumption in other reporting tools and frameworks
|
||||
* Externalised configuration for environment specific customisation including regex rules
|
||||
* Customizable repository name, file type, commit ID, branch name and regex whitelisting to reduce false positives
|
||||
* High performance through the use of src-d's [go-git](https://github.com/src-d/go-git) framework
|
||||
|
||||
It has been successfully used in a number of different scenarios, including:
|
||||
|
||||
* Adhoc scans of local and remote repositories by filesystem path or clone URL
|
||||
* Automated scans of github users and organizations (Both public and enterprise platforms)
|
||||
* As part of a CICD workflow to identify secrets before they make it deeper into your codebase
|
||||
* As part of a wider secrets auditing automation capability for git data in large environments
|
||||
Gitleaks is a SAST tool for detecting hardcoded secrets like passwords, api keys, and tokens in git repos. Gitleaks aims to be the **easy-to-use, all-in-one solution** for finding secrets, past or present, in your code.
|
||||
|
||||
### Features:
|
||||
- Scan for [commited](https://github.com/zricethezav/gitleaks#Scanning) secrets
|
||||
- Scan for [unstaged](https://github.com/zricethezav/gitleaks#scan-unstaged-changes) secrets as part of shifting security left
|
||||
- Scan [directories and files](https://github.com/zricethezav/gitleaks#scan-local-directory)
|
||||
- Available [Github Action](https://github.com/marketplace/actions/gitleaks)
|
||||
- [Custom rules](https://github.com/zricethezav/gitleaks#configuration) via toml configuration
|
||||
- High performance using [go-git](https://github.com/go-git/go-git)
|
||||
- JSON, SARIF, and CSV reporting
|
||||
- Private repo scans using key or password based authentication
|
||||
|
||||
|
||||
## Example execution
|
||||
### Installation
|
||||
Gitleaks can be installed with Homebrew, Docker, and Go. Gitleaks is also available in binary form for many popular platforms and OS types from the [releases page](https://github.com/zricethezav/gitleaks/releases).
|
||||
|
||||
|
||||
<p align="left">
|
||||
<img src="https://cdn.rawgit.com/zricethezav/5bf8259b7fea0170becffc06b8588edb/raw/f762769fe20ef3669bff34612b1bede6457631e6/termtosvg_je8bp82s.svg">
|
||||
</p>
|
||||
|
||||
## Installation
|
||||
|
||||
Written in Go, gitleaks is available in binary form for many popular platforms and OS types from the [releases page](https://github.com/zricethezav/gitleaks/releases). Alternatively, executed via Docker or it can be installed using Go directly, as per the below;
|
||||
|
||||
#### MacOS
|
||||
##### MacOS
|
||||
|
||||
```
|
||||
brew install gitleaks
|
||||
```
|
||||
|
||||
#### Docker
|
||||
##### Docker
|
||||
|
||||
```bash
|
||||
docker pull zricethezav/gitleaks
|
||||
```
|
||||
|
||||
#### Go
|
||||
|
||||
##### Go
|
||||
```bash
|
||||
go get -u github.com/zricethezav/gitleaks
|
||||
GO111MODULE=on go get github.com/zricethezav/gitleaks/v7
|
||||
```
|
||||
|
||||
## Usage and Options
|
||||
|
||||
gitleaks has a wide range of configuration options that can be adjusted at runtime or via a configuration file based on your specific requirements.
|
||||
|
||||
### Usage and Options
|
||||
```
|
||||
Usage:
|
||||
gitleaks [OPTIONS]
|
||||
|
||||
Application Options:
|
||||
-r, --repo= Repo url to audit
|
||||
--github-user= Github user to audit
|
||||
--github-org= Github organization to audit
|
||||
--github-url= GitHub API Base URL, use for GitHub Enterprise. Example: https://github.example.com/api/v3/ (default: https://api.github.com/)
|
||||
--github-pr= Github PR url to audit. This does not clone the repo. GITHUB_TOKEN must be set
|
||||
--gitlab-user= GitLab user ID to audit
|
||||
--gitlab-org= GitLab group ID to audit
|
||||
--commit-stop= sha of commit to stop at
|
||||
--commit= sha of commit to audit
|
||||
--depth= maximum commit depth
|
||||
--repo-path= Path to repo
|
||||
--owner-path= Path to owner directory (repos discovered)
|
||||
--threads= Maximum number of threads gitleaks spawns
|
||||
--disk Clones repo(s) to disk
|
||||
--config= path to gitleaks config
|
||||
--ssh-key= path to ssh key
|
||||
--exclude-forks exclude forks for organization/user audits
|
||||
--repo-config Load config from target repo. Config file must be ".gitleaks.toml"
|
||||
--branch= Branch to audit
|
||||
-l, --log= log level
|
||||
-v, --verbose Show verbose output from gitleaks audit
|
||||
--report= path to write report file
|
||||
--redact redact secrets from log messages and report
|
||||
--version version number
|
||||
--sample-config prints a sample config file
|
||||
-v, --verbose Show verbose output from scan
|
||||
-q, --quiet Sets log level to error and only output leaks, one json object per line
|
||||
-r, --repo-url= Repository URL
|
||||
-p, --path= Path to directory (repo if contains .git) or file
|
||||
-c, --config-path= Path to config
|
||||
--repo-config-path= Path to gitleaks config relative to repo root
|
||||
--version Version number
|
||||
--username= Username for git repo
|
||||
--password= Password for git repo
|
||||
--access-token= Access token for git repo
|
||||
--threads= Maximum number of threads gitleaks spawns
|
||||
--ssh-key= Path to ssh key used for auth
|
||||
--unstaged Run gitleaks on unstaged code
|
||||
--branch= Branch to scan
|
||||
--redact Redact secrets from log messages and leaks
|
||||
--debug Log debug messages
|
||||
--leaks-exit-code= Exit code when leaks have been encountered (default: 1)
|
||||
--no-git Treat git repos as plain directories and scan those
|
||||
files
|
||||
-o, --report= Report output path
|
||||
-f, --format= JSON, CSV, SARIF (default: json)
|
||||
--files-at-commit= Sha of commit to scan all files at commit
|
||||
--commit= Sha of commit to scan or "latest" to scan the last
|
||||
commit of the repository
|
||||
--commits= Comma separated list of a commits to scan
|
||||
--commits-file= Path to file of line separated list of commits to scan
|
||||
--commit-from= Commit to start scan from
|
||||
--commit-to= Commit to stop scan
|
||||
--commit-since= Scan commits more recent than a specific date. Ex:
|
||||
'2006-01-02' or '2006-01-02T15:04:05-0700' format.
|
||||
--commit-until= Scan commits older than a specific date. Ex:
|
||||
'2006-01-02' or '2006-01-02T15:04:05-0700' format.
|
||||
--depth= Number of commits to scan
|
||||
|
||||
Help Options:
|
||||
-h, --help Show this help message
|
||||
-h, --help Show this help message
|
||||
```
|
||||
|
||||
### Docker usage examples
|
||||
|
||||
Run gitleaks against:
|
||||
### [Scanning](https://www.youtube.com/watch?v=WUzpRL8mKCk)
|
||||
|
||||
###### Public repository
|
||||
|
||||
```bash
|
||||
docker run --rm --name=gitleaks zricethezav/gitleaks -v -r https://github.com/zricethezav/gitleaks.git
|
||||
#### Basic repo-url scan:
|
||||
This scans the entire history of tests/secrets and logs leaks as they are encountered `-v`/`--verbose` being set.
|
||||
```
|
||||
gitleaks --repo-url=https://github.com/my-insecure/repo -v
|
||||
```
|
||||
|
||||
###### Local repository already cloned into /tmp/
|
||||
|
||||
```bash
|
||||
docker run --rm --name=gitleaks -v /tmp/:/code/ zricethezav/gitleaks -v --repo-path=/code/gitleaks
|
||||
#### Basic repo-url scan output to a report:
|
||||
If we want the report in sarif or csv we can set the `-f/--format` option
|
||||
```
|
||||
gitleaks --repo-url=https://github.com/my-insecure/repo -v --report=my-report.json
|
||||
```
|
||||
|
||||
###### Specific Github Pull request
|
||||
|
||||
You need GitHub token with `repo` access. [How create token](https://help.github.com/en/articles/creating-a-personal-access-token-for-the-command-line).
|
||||
|
||||
```bash
|
||||
export GITHUB_TOKEN=""
|
||||
|
||||
docker run --rm --name=gitleaks \
|
||||
-e GITHUB_TOKEN=${GITHUB_TOKEN} \
|
||||
zricethezav/gitleaks \
|
||||
--github-pr=https://github.com/owner/repo/pull/9000
|
||||
#### Scan specific commit:
|
||||
```
|
||||
gitleaks --repo-url=https://github.com/my-insecure/repo --commit=commit-sha -v
|
||||
```
|
||||
|
||||
###### Private repository
|
||||
|
||||
You need private SSH key associated with user which have pull access to private repo.
|
||||
|
||||
```bash
|
||||
export SSH_KEY_DIR=$(echo $HOME)/.ssh
|
||||
export SSH_KEY_NAME=id_rsa
|
||||
export REPO="git@github.com:zricethezav/gitleaks.git"
|
||||
|
||||
docker run --rm --name=gitleaks \
|
||||
--mount type=bind,src=${SSH_KEY_DIR},dst=/root/.ssh,readonly \
|
||||
zricethezav/gitleaks \
|
||||
--ssh-key=/root/.ssh/${SSH_KEY_NAME} \
|
||||
--verbose \
|
||||
--repo=${REPO}
|
||||
#### Scan local repo:
|
||||
```
|
||||
gitleaks --path=path/to/local/repo -v
|
||||
```
|
||||
|
||||
###### Specific Github organization with private repos
|
||||
|
||||
You need GitHub token with `repo` access. [How create token](https://help.github.com/en/articles/creating-a-personal-access-token-for-the-command-line).
|
||||
|
||||
```bash
|
||||
export GITHUB_TOKEN=""
|
||||
export ORG="github_org_name" # "git" in "https://github.com/git/", for instance.
|
||||
|
||||
docker run --rm --name=gitleaks \
|
||||
-e GITHUB_TOKEN=${GITHUB_TOKEN} \
|
||||
zricethezav/gitleaks \
|
||||
--verbose \
|
||||
--disk \
|
||||
--threads=$(($(nproc --all) - 1)) \
|
||||
--github-org=${ORG}
|
||||
#### Scan repos contain in a parent directory:
|
||||
If we had `repo1`, `repo2`, `repo3` all under `path/to/local`, gitleaks will discover and scan those repos.
|
||||
```
|
||||
gitleaks --path=path/to/local/ -v
|
||||
```
|
||||
|
||||
By default repos cloned to memory. Using `--disk` for clone to disk or you can quickly out of memory.
|
||||
|
||||
For speed up analyze operation using `--threads` parameter, which set to `ALL - 1` treads at your instance CPU.
|
||||
|
||||
|
||||
## Exit Codes
|
||||
|
||||
Gitleaks provides consistent exist codes to assist in automation workflows such as CICD platforms and bulk scanning.
|
||||
|
||||
These can be effectively used in conjunction with the report output file to detect and return meaningful data back to the user or external system about if leaks have been detected, and where they reside.
|
||||
|
||||
The code return codes are:
|
||||
|
||||
#### Scan local directory:
|
||||
You might want to scan the current contents of a repo, ignoring git alltogether. You can use the `--no-git` option to do this.
|
||||
```
|
||||
0: no leaks
|
||||
1: leaks present
|
||||
2: error encountered
|
||||
gitleaks --path=path/to/local/repo -v --no-git
|
||||
```
|
||||
|
||||
## Additional information
|
||||
#### Scan a file:
|
||||
Or you might want to scan a single file using gitleaks rules. You can do this by specifying the file in `--path` and including the `--no-git` option.
|
||||
```
|
||||
gitleaks --path=path/to/local/repo/main.go -v --no-git
|
||||
```
|
||||
|
||||
* 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/)
|
||||
* [Removing sensitive files from commit history (atlassian.com)](https://community.atlassian.com/t5/Bitbucket-questions/Remove-sensitive-files-from-commit-history/qaq-p/243807)
|
||||
* [Rewrite git history with the BFG (theguardian.com)](https://www.theguardian.com/info/developer-blog/2013/apr/29/rewrite-git-history-with-the-bfg)
|
||||
* [Auditing Bitbucket Server Data for Credentials in AWS (sourcedgroup.com)](https://www.sourcedgroup.com/blog/auditing-bitbucket-server-data-credentials-in-aws)
|
||||
|
||||
This blog post details how gitleaks was used to audit data in Atlassian Bitbucket server when hosted on AWS and visualise the results in a compliance dashboard using Splunk.
|
||||
|
||||
* 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).
|
||||
|
||||
Donate: https://www.cuathome.us/give/
|
||||
#### Scan unstaged changes:
|
||||
If you have unstaged changes are are currently at the root of the repo, you can run `gitleaks` with no `--path` or `--repo-url` specified which will run a scan on your uncommitted changes. Or if you want to specify a
|
||||
path, you can run:
|
||||
```
|
||||
gitleaks --path=path/to/local/repo -v --unstaged
|
||||
```
|
||||
|
||||
|
||||
### Configuration
|
||||
Provide your own gitleaks configurations with `--config-path` or `--repo-config-path`. The difference between the two is `--config-path` loads a local gitleaks config whereas `--repo-config-path` will load a configuration present in the repo you want to scan. For example, `gitleaks --repo-config-path=".github/gitleaks.config"`.
|
||||
The default configuration Gitleaks uses is located [here](https://github.com/zricethezav/gitleaks/blob/master/config/default.go). More configuration examples can be seen [here](https://github.com/zricethezav/gitleaks/tree/master/examples). Configuration files contain a few different toml tables which will be explained below.
|
||||
### Rules summary
|
||||
|
||||
The rules are written in [TOML](https://github.com/toml-lang/toml) as defined in [TomlLoader struct](https://github.com/zricethezav/gitleaks/blob/master/config/config.go#L57-L87), and can be summarized as:
|
||||
|
||||
```
|
||||
|
||||
|
||||
[[rules]]
|
||||
description = "a string describing one of many rule in this config"
|
||||
regex = '''one-go-style-regex-for-this-rule'''
|
||||
file = '''a-file-name-regex'''
|
||||
path = '''a-file-path-regex'''
|
||||
tags = ["tag","another tag"]
|
||||
[[rules.entropies]] # note these are strings, not floats
|
||||
Min = "3.5"
|
||||
Max = "4.5"
|
||||
Group = "1"
|
||||
[rules.allowlist]
|
||||
description = "a string"
|
||||
files = ['''one-file-name-regex''']
|
||||
commits = [ "commit-A", "commit-B"]
|
||||
paths = ['''one-file-path-regex''']
|
||||
regexes = ['''one-regex-within-the-already-matched-regex''']
|
||||
|
||||
[allowlist]
|
||||
description = "a description string for a global allowlist config"
|
||||
commits = [ "commit-A", "commit-B"]
|
||||
files = [ '''file-regex-a''', '''file-regex-b''']
|
||||
paths = [ '''path-regex-a''', '''path-regex-b''']
|
||||
repos = [ '''repo-regex-a''', '''repo-regex-b''']
|
||||
regexes = ['''one-regex-within-the-already-matched-regex''']
|
||||
```
|
||||
|
||||
Regular expressions are _NOT_ the full Perl set, so there are no look-aheads or look-behinds.
|
||||
|
||||
|
||||
### Examples
|
||||
#### Example 1
|
||||
The first and most commonly edited array of tables is `[[rules]]`. This is where you can define your own custom rules for Gitleaks to use while scanning repos. Example keys/values within the `[[rules]]` table:
|
||||
```
|
||||
[[rules]]
|
||||
description = "generic secret regex"
|
||||
regex = '''secret(.{0,20})([0-9a-zA-Z-._{}$\/\+=]{20,120})'''
|
||||
tags = ["secret", "example"]
|
||||
```
|
||||
#### Example 2
|
||||
We can also **combine** regular expressions AND entropy:
|
||||
```
|
||||
[[rules]]
|
||||
description = "entropy and regex example"
|
||||
regex = '''secret(.{0,20})['|"]([0-9a-zA-Z-._{}$\/\+=]{20,120})['|"]'''
|
||||
[[rules.Entropies]]
|
||||
Min = "4.5"
|
||||
Max = "4.7"
|
||||
```
|
||||
Translating this rule to English, this rule states: "if we encounter a line of code that matches *regex* AND the line falls within the bounds of a [Shannon entropy](https://en.wikipedia.org/wiki/Entropy_(information_theory)) of 4.5 to 4.7, then the line must be a leak"
|
||||
|
||||
#### Example 3
|
||||
Let's compare two lines of code:
|
||||
```
|
||||
aws_secret='ABCDEF+c2L7yXeGvUyrPgYsDnWRRC1AYEXAMPLE'
|
||||
```
|
||||
and
|
||||
```
|
||||
aws_secret=os.getenv('AWS_SECRET_ACCESS_KEY')
|
||||
|
||||
```
|
||||
The first line of code is an example of a hardcoded secret being assigned to the variable `aws_secret`. The second line of code is an example of a secret being assigned via env variables to `aws_secret`. Both would be caught by the rule defined in *example 2* but only the first line is actually a leak. Let's define a new rule that will capture only the first line of code. We can do this by combining regular expression **groups** and entropy.
|
||||
```
|
||||
[[rules]]
|
||||
description = "entropy and regex example"
|
||||
regex = '''secret(.{0,20})['|"]([0-9a-zA-Z-._{}$\/\+=]{20,120})['|"]'''
|
||||
[[rules.Entropies]]
|
||||
Min = "4.5"
|
||||
Max = "4.7"
|
||||
Group = "2"
|
||||
```
|
||||
Notice how we added `Group = "2"` to this rule. We can translate this rule to English: "if we encounter a line of code that matches regex AND the entropy of the *second regex group* falls within the bounds of a [Shannon entropy](https://en.wikipedia.org/wiki/Entropy_(information_theory)) of 4.5 to 4.7, then the line must be a leak"
|
||||
|
||||
### Example 4: Using allowlist regex
|
||||
|
||||
The proper Perl regex for AWS secret keys is
|
||||
`(?<![A-Za-z0-9\\+])[A-Za-z0-9\\+=]{40}(?![A-Za-z0-9\\+=])`
|
||||
but the Go library doesn't do lookahead/lookbehind, so
|
||||
we'll look for 40 base64 characters, then allowlist
|
||||
if they're embedded in a string of 41 base64 characters, that is,
|
||||
without any delimiters. This will make a false negative for, say:
|
||||
```
|
||||
foo=+awsSecretAccessKeyisBase64=40characters
|
||||
```
|
||||
So you can use the following to effectively create the proper Perl regex:
|
||||
```
|
||||
[[rules]]
|
||||
description = "AWS secret key regardless of labeling"
|
||||
regex = '''.?[A-Za-z0-9\\+=]{40}.?'''
|
||||
[rules.allowlist]
|
||||
description = "41 base64 characters is not an AWS secret key"
|
||||
regexes = ['''[A-Za-z0-9\\+=]{41}''']
|
||||
|
||||
```
|
||||
|
||||
|
||||
|
||||
### Exit Codes
|
||||
You can always set the exit code when leaves are encountered with the `--leaks-exit-code` flag. Default exit codes below:
|
||||
```
|
||||
0 - no leaks present
|
||||
1 - leaks or error encountered
|
||||
```
|
||||
|
||||
### Sponsors ❤️
|
||||
#### Corporate Sponsors
|
||||
[](https://gammanet.com/?utm_source=gitleaks&utm_medium=homepage&utm_campaign=gitleaks_promotion)
|
||||
|
||||
Gamma proactively detects and remediates data leaks across cloud apps. Scan your public repos for secret leaks with [Gamma](https://gammanet.com/github-demo?utm_source=gitleaks&utm_medium=homepage&utm_campaign=gitleaks_promotion)
|
||||
|
||||
#### Individual Sponsors
|
||||
These users are [sponsors](https://github.com/sponsors/zricethezav) of gitleaks:
|
||||
|
||||
[](https://github.com/adamdecaf) |
|
||||
---|
|
||||
----
|
||||
|
||||
|
||||
#### Logo Attribution
|
||||
The Gitleaks logo uses the Git Logo created <a href="https://twitter.com/jasonlong">Jason Long</a> is licensed under the <a href="https://creativecommons.org/licenses/by/3.0/">Creative Commons Attribution 3.0 Unported License</a>.
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"regexp"
|
||||
)
|
||||
|
||||
// used for ignoring .git directories when the --no-git flag is set
|
||||
// related issue: https://github.com/zricethezav/gitleaks/issues/486
|
||||
const dotGit = `/\.git/`
|
||||
|
||||
// AllowList is struct containing items that if encountered will allowlist
|
||||
// a commit/line of code that would be considered a leak.
|
||||
type AllowList struct {
|
||||
Description string
|
||||
Regexes []*regexp.Regexp
|
||||
Commits []string
|
||||
Files []*regexp.Regexp
|
||||
Paths []*regexp.Regexp
|
||||
Repos []*regexp.Regexp
|
||||
}
|
||||
|
||||
// CommitAllowed checks if a commit is allowlisted
|
||||
func (a *AllowList) CommitAllowed(commit string) bool {
|
||||
for _, hash := range a.Commits {
|
||||
if commit == hash {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// FileAllowed checks if a file is allowlisted
|
||||
func (a *AllowList) FileAllowed(fileName string) bool {
|
||||
return anyRegexMatch(fileName, a.Files)
|
||||
}
|
||||
|
||||
// PathAllowed checks if a path is allowlisted
|
||||
func (a *AllowList) PathAllowed(filePath string) bool {
|
||||
return anyRegexMatch(filePath, a.Paths)
|
||||
}
|
||||
|
||||
// RegexAllowed checks if a regex is allowlisted
|
||||
func (a *AllowList) RegexAllowed(content string) bool {
|
||||
return anyRegexMatch(content, a.Regexes)
|
||||
}
|
||||
|
||||
// RepoAllowed checks if a regex is allowlisted
|
||||
func (a *AllowList) RepoAllowed(repo string) bool {
|
||||
return anyRegexMatch(repo, a.Repos)
|
||||
}
|
||||
|
||||
// IgnoreDotGit appends a `\.git` rule to ignore all .git paths. This is used for --no-git scans
|
||||
func (a *AllowList) IgnoreDotGit() error {
|
||||
re, err := regexp.Compile(dotGit)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
a.Paths = append(a.Paths, re)
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,288 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"path"
|
||||
"regexp"
|
||||
"strconv"
|
||||
|
||||
"github.com/zricethezav/gitleaks/v7/options"
|
||||
|
||||
"github.com/BurntSushi/toml"
|
||||
"github.com/go-git/go-git/v5"
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
// Config is a composite struct of Rules and Allowlists
|
||||
// Each Rule contains a description, regular expression, tags, and allowlists if available
|
||||
type Config struct {
|
||||
Rules []Rule
|
||||
Allowlist AllowList
|
||||
}
|
||||
|
||||
// Entropy represents an entropy range
|
||||
type Entropy struct {
|
||||
Min float64
|
||||
Max float64
|
||||
Group int
|
||||
}
|
||||
|
||||
// TomlAllowList is a struct used in the TomlLoader that loads in allowlists from
|
||||
// specific rules or globally at the top level config
|
||||
type TomlAllowList struct {
|
||||
Description string
|
||||
Regexes []string
|
||||
Commits []string
|
||||
Files []string
|
||||
Paths []string
|
||||
Repos []string
|
||||
}
|
||||
|
||||
// TomlLoader gets loaded with the values from a gitleaks toml config
|
||||
// see the config in config/defaults.go for an example. TomlLoader is used
|
||||
// to generate Config values (compiling regexes, etc).
|
||||
type TomlLoader struct {
|
||||
AllowList TomlAllowList
|
||||
Rules []struct {
|
||||
Description string
|
||||
Regex string
|
||||
File string
|
||||
Path string
|
||||
ReportGroup int
|
||||
Tags []string
|
||||
Entropies []struct {
|
||||
Min string
|
||||
Max string
|
||||
Group string
|
||||
}
|
||||
AllowList TomlAllowList
|
||||
}
|
||||
}
|
||||
|
||||
// NewConfig will create a new config struct which contains
|
||||
// rules on how gitleaks will proceed with its scan.
|
||||
// If no options are passed via cli then NewConfig will return
|
||||
// a default config which can be seen in config.go
|
||||
func NewConfig(options options.Options) (Config, error) {
|
||||
var cfg Config
|
||||
tomlLoader := TomlLoader{}
|
||||
|
||||
var err error
|
||||
if options.ConfigPath != "" {
|
||||
_, err = toml.DecodeFile(options.ConfigPath, &tomlLoader)
|
||||
// append a allowlist rule for allowlisting the config
|
||||
tomlLoader.AllowList.Files = append(tomlLoader.AllowList.Files, path.Base(options.ConfigPath))
|
||||
} else {
|
||||
_, err = toml.Decode(DefaultConfig, &tomlLoader)
|
||||
}
|
||||
if err != nil {
|
||||
return cfg, err
|
||||
}
|
||||
|
||||
cfg, err = tomlLoader.Parse()
|
||||
if err != nil {
|
||||
return cfg, err
|
||||
}
|
||||
|
||||
return cfg, nil
|
||||
}
|
||||
|
||||
// Parse will parse the values set in a TomlLoader and use those values
|
||||
// to create compiled regular expressions and rules used in scans
|
||||
func (tomlLoader TomlLoader) Parse() (Config, error) {
|
||||
var cfg Config
|
||||
for _, rule := range tomlLoader.Rules {
|
||||
// check and make sure the rule is valid
|
||||
if rule.Regex == "" && rule.Path == "" && rule.File == "" && len(rule.Entropies) == 0 {
|
||||
log.Warnf("Rule %s does not define any actionable data", rule.Description)
|
||||
continue
|
||||
}
|
||||
re, err := regexp.Compile(rule.Regex)
|
||||
if err != nil {
|
||||
return cfg, fmt.Errorf("problem loading config: %v", err)
|
||||
}
|
||||
fileNameRe, err := regexp.Compile(rule.File)
|
||||
if err != nil {
|
||||
return cfg, fmt.Errorf("problem loading config: %v", err)
|
||||
}
|
||||
filePathRe, err := regexp.Compile(rule.Path)
|
||||
if err != nil {
|
||||
return cfg, fmt.Errorf("problem loading config: %v", err)
|
||||
}
|
||||
|
||||
// rule specific allowlists
|
||||
var allowList AllowList
|
||||
|
||||
allowList.Description = rule.AllowList.Description
|
||||
|
||||
// rule specific regexes
|
||||
for _, re := range rule.AllowList.Regexes {
|
||||
allowListedRegex, err := regexp.Compile(re)
|
||||
if err != nil {
|
||||
return cfg, fmt.Errorf("problem loading config: %v", err)
|
||||
}
|
||||
allowList.Regexes = append(allowList.Regexes, allowListedRegex)
|
||||
}
|
||||
|
||||
// rule specific filenames
|
||||
for _, re := range rule.AllowList.Files {
|
||||
allowListedRegex, err := regexp.Compile(re)
|
||||
if err != nil {
|
||||
return cfg, fmt.Errorf("problem loading config: %v", err)
|
||||
}
|
||||
allowList.Files = append(allowList.Files, allowListedRegex)
|
||||
}
|
||||
|
||||
// rule specific paths
|
||||
for _, re := range rule.AllowList.Paths {
|
||||
allowListedRegex, err := regexp.Compile(re)
|
||||
if err != nil {
|
||||
return cfg, fmt.Errorf("problem loading config: %v", err)
|
||||
}
|
||||
allowList.Paths = append(allowList.Paths, allowListedRegex)
|
||||
}
|
||||
|
||||
// rule specific commits
|
||||
allowList.Commits = rule.AllowList.Commits
|
||||
|
||||
var entropies []Entropy
|
||||
for _, e := range rule.Entropies {
|
||||
min, err := strconv.ParseFloat(e.Min, 64)
|
||||
if err != nil {
|
||||
return cfg, err
|
||||
}
|
||||
max, err := strconv.ParseFloat(e.Max, 64)
|
||||
if err != nil {
|
||||
return cfg, err
|
||||
}
|
||||
if e.Group == "" {
|
||||
e.Group = "0"
|
||||
}
|
||||
group, err := strconv.ParseInt(e.Group, 10, 64)
|
||||
if err != nil {
|
||||
return cfg, err
|
||||
} else if int(group) >= len(re.SubexpNames()) {
|
||||
return cfg, fmt.Errorf("problem loading config: group cannot be higher than number of groups in regexp")
|
||||
} else if group < 0 {
|
||||
return cfg, fmt.Errorf("problem loading config: group cannot be lower than 0")
|
||||
} else if min > 8.0 || min < 0.0 || max > 8.0 || max < 0.0 {
|
||||
return cfg, fmt.Errorf("problem loading config: invalid entropy ranges, must be within 0.0-8.0")
|
||||
} else if min > max {
|
||||
return cfg, fmt.Errorf("problem loading config: entropy Min value cannot be higher than Max value")
|
||||
}
|
||||
|
||||
entropies = append(entropies, Entropy{Min: min, Max: max, Group: int(group)})
|
||||
}
|
||||
|
||||
r := Rule{
|
||||
Description: rule.Description,
|
||||
Regex: re,
|
||||
File: fileNameRe,
|
||||
Path: filePathRe,
|
||||
ReportGroup: rule.ReportGroup,
|
||||
Tags: rule.Tags,
|
||||
AllowList: allowList,
|
||||
Entropies: entropies,
|
||||
}
|
||||
|
||||
cfg.Rules = append(cfg.Rules, r)
|
||||
}
|
||||
|
||||
// global regex allowLists
|
||||
for _, allowListRegex := range tomlLoader.AllowList.Regexes {
|
||||
re, err := regexp.Compile(allowListRegex)
|
||||
if err != nil {
|
||||
return cfg, fmt.Errorf("problem loading config: %v", err)
|
||||
}
|
||||
cfg.Allowlist.Regexes = append(cfg.Allowlist.Regexes, re)
|
||||
}
|
||||
|
||||
// global file name allowLists
|
||||
for _, allowListFileName := range tomlLoader.AllowList.Files {
|
||||
re, err := regexp.Compile(allowListFileName)
|
||||
if err != nil {
|
||||
return cfg, fmt.Errorf("problem loading config: %v", err)
|
||||
}
|
||||
cfg.Allowlist.Files = append(cfg.Allowlist.Files, re)
|
||||
}
|
||||
|
||||
// global file path allowLists
|
||||
for _, allowListFilePath := range tomlLoader.AllowList.Paths {
|
||||
re, err := regexp.Compile(allowListFilePath)
|
||||
if err != nil {
|
||||
return cfg, fmt.Errorf("problem loading config: %v", err)
|
||||
}
|
||||
cfg.Allowlist.Paths = append(cfg.Allowlist.Paths, re)
|
||||
}
|
||||
|
||||
// global repo allowLists
|
||||
for _, allowListRepo := range tomlLoader.AllowList.Repos {
|
||||
re, err := regexp.Compile(allowListRepo)
|
||||
if err != nil {
|
||||
return cfg, fmt.Errorf("problem loading config: %v", err)
|
||||
}
|
||||
cfg.Allowlist.Repos = append(cfg.Allowlist.Repos, re)
|
||||
}
|
||||
|
||||
cfg.Allowlist.Commits = tomlLoader.AllowList.Commits
|
||||
cfg.Allowlist.Description = tomlLoader.AllowList.Description
|
||||
|
||||
return cfg, nil
|
||||
}
|
||||
|
||||
// LoadRepoConfig accepts a repo and config path related to the target repo's root.
|
||||
func LoadRepoConfig(repo *git.Repository, repoConfig string) (Config, error) {
|
||||
gitRepoConfig, err := repo.Config()
|
||||
if err != nil {
|
||||
return Config{}, err
|
||||
}
|
||||
if !gitRepoConfig.Core.IsBare {
|
||||
wt, err := repo.Worktree()
|
||||
if err != nil {
|
||||
return Config{}, err
|
||||
}
|
||||
_, err = wt.Filesystem.Stat(repoConfig)
|
||||
if err != nil {
|
||||
return Config{}, err
|
||||
}
|
||||
r, err := wt.Filesystem.Open(repoConfig)
|
||||
if err != nil {
|
||||
return Config{}, err
|
||||
}
|
||||
var tomlLoader TomlLoader
|
||||
_, err = toml.DecodeReader(r, &tomlLoader)
|
||||
if err != nil {
|
||||
return Config{}, err
|
||||
}
|
||||
|
||||
return tomlLoader.Parse()
|
||||
}
|
||||
|
||||
log.Debug("attempting to load repo config from bare worktree, this may use an old config")
|
||||
ref, err := repo.Head()
|
||||
if err != nil {
|
||||
return Config{}, err
|
||||
}
|
||||
|
||||
c, err := repo.CommitObject(ref.Hash())
|
||||
if err != nil {
|
||||
return Config{}, err
|
||||
}
|
||||
|
||||
f, err := c.File(repoConfig)
|
||||
if err != nil {
|
||||
return Config{}, err
|
||||
}
|
||||
|
||||
var tomlLoader TomlLoader
|
||||
r, err := f.Reader()
|
||||
if err != nil {
|
||||
return Config{}, err
|
||||
}
|
||||
_, err = toml.DecodeReader(r, &tomlLoader)
|
||||
if err != nil {
|
||||
return Config{}, err
|
||||
}
|
||||
|
||||
return tomlLoader.Parse()
|
||||
}
|
||||
@@ -0,0 +1,213 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"regexp"
|
||||
"testing"
|
||||
|
||||
"github.com/zricethezav/gitleaks/v7/options"
|
||||
)
|
||||
|
||||
func TestParse(t *testing.T) {
|
||||
tests := []struct {
|
||||
description string
|
||||
opts options.Options
|
||||
wantErr error
|
||||
wantFileRegex *regexp.Regexp
|
||||
wantMessages *regexp.Regexp
|
||||
wantAllowlist AllowList
|
||||
}{
|
||||
{
|
||||
description: "default config",
|
||||
opts: options.Options{},
|
||||
},
|
||||
{
|
||||
description: "test successful load",
|
||||
opts: options.Options{
|
||||
ConfigPath: "../test_data/test_configs/aws_key.toml",
|
||||
},
|
||||
},
|
||||
{
|
||||
description: "test bad toml",
|
||||
opts: options.Options{
|
||||
ConfigPath: "../test_data/test_configs/bad_aws_key.toml",
|
||||
},
|
||||
wantErr: fmt.Errorf("Near line 7 (last key parsed 'rules.description'): expected value but found \"AWS\" instead"),
|
||||
},
|
||||
{
|
||||
description: "test bad regex",
|
||||
opts: options.Options{
|
||||
ConfigPath: "../test_data/test_configs/bad_regex_aws_key.toml",
|
||||
},
|
||||
wantErr: fmt.Errorf("problem loading config: error parsing regexp: invalid nested repetition operator: `???`"),
|
||||
},
|
||||
{
|
||||
description: "test bad global allowlist file regex",
|
||||
opts: options.Options{
|
||||
ConfigPath: "../test_data/test_configs/bad_aws_key_global_allowlist_file.toml",
|
||||
},
|
||||
wantErr: fmt.Errorf("problem loading config: error parsing regexp: missing argument to repetition operator: `??`"),
|
||||
},
|
||||
{
|
||||
description: "test bad global file regex",
|
||||
opts: options.Options{
|
||||
ConfigPath: "../test_data/test_configs/bad_aws_key_file_regex.toml",
|
||||
},
|
||||
wantErr: fmt.Errorf("problem loading config: error parsing regexp: missing argument to repetition operator: `??`"),
|
||||
},
|
||||
{
|
||||
description: "test successful load big ol thing",
|
||||
opts: options.Options{
|
||||
ConfigPath: "../test_data/test_configs/large.toml",
|
||||
},
|
||||
},
|
||||
{
|
||||
description: "test load entropy",
|
||||
opts: options.Options{
|
||||
ConfigPath: "../test_data/test_configs/entropy.toml",
|
||||
},
|
||||
},
|
||||
{
|
||||
description: "test entropy bad range",
|
||||
opts: options.Options{
|
||||
ConfigPath: "../test_data/test_configs/bad_entropy_1.toml",
|
||||
},
|
||||
wantErr: fmt.Errorf("problem loading config: entropy Min value cannot be higher than Max value"),
|
||||
},
|
||||
{
|
||||
description: "test entropy value max",
|
||||
opts: options.Options{
|
||||
ConfigPath: "../test_data/test_configs/bad_entropy_2.toml",
|
||||
},
|
||||
wantErr: fmt.Errorf("strconv.ParseFloat: parsing \"x\": invalid syntax"),
|
||||
},
|
||||
{
|
||||
description: "test entropy value min",
|
||||
opts: options.Options{
|
||||
ConfigPath: "../test_data/test_configs/bad_entropy_3.toml",
|
||||
},
|
||||
wantErr: fmt.Errorf("strconv.ParseFloat: parsing \"x\": invalid syntax"),
|
||||
},
|
||||
{
|
||||
description: "test entropy value group",
|
||||
opts: options.Options{
|
||||
ConfigPath: "../test_data/test_configs/bad_entropy_4.toml",
|
||||
},
|
||||
wantErr: fmt.Errorf("strconv.ParseInt: parsing \"x\": invalid syntax"),
|
||||
},
|
||||
{
|
||||
description: "test entropy value group",
|
||||
opts: options.Options{
|
||||
ConfigPath: "../test_data/test_configs/bad_entropy_5.toml",
|
||||
},
|
||||
wantErr: fmt.Errorf("problem loading config: group cannot be lower than 0"),
|
||||
},
|
||||
{
|
||||
description: "test entropy value group",
|
||||
opts: options.Options{
|
||||
ConfigPath: "../test_data/test_configs/bad_entropy_6.toml",
|
||||
},
|
||||
wantErr: fmt.Errorf("problem loading config: group cannot be higher than number of groups in regexp"),
|
||||
},
|
||||
{
|
||||
description: "test entropy range limits",
|
||||
opts: options.Options{
|
||||
ConfigPath: "../test_data/test_configs/bad_entropy_7.toml",
|
||||
},
|
||||
wantErr: fmt.Errorf("problem loading config: invalid entropy ranges, must be within 0.0-8.0"),
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
_, err := NewConfig(test.opts)
|
||||
if err != nil {
|
||||
if test.wantErr == nil {
|
||||
t.Error(test.description, err)
|
||||
} else if test.wantErr.Error() != err.Error() {
|
||||
t.Errorf("expected err: %s, got %s", test.wantErr, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TestParseFields will test that fields are properly parsed from a config. As fields are added, then please
|
||||
// add tests here.
|
||||
func TestParseFields(t *testing.T) {
|
||||
tomlConfig := `
|
||||
[[rules]]
|
||||
description = "Some Groups without a reportGroup"
|
||||
regex = '(.)(.)'
|
||||
|
||||
[[rules]]
|
||||
description = "Some Groups"
|
||||
regex = '(.)(.)'
|
||||
reportGroup = 1
|
||||
`
|
||||
configPath, err := writeTestConfig(tomlConfig)
|
||||
defer os.Remove(configPath)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
config, err := NewConfig(options.Options{ConfigPath: configPath})
|
||||
if err != nil {
|
||||
t.Fatalf("Couldn't parse config: %v", err)
|
||||
}
|
||||
|
||||
expectedRuleFields := []struct {
|
||||
Description string
|
||||
ReportGroup int
|
||||
}{
|
||||
{
|
||||
Description: "Some Groups without a reportGroup",
|
||||
ReportGroup: 0,
|
||||
},
|
||||
{
|
||||
Description: "Some Groups",
|
||||
ReportGroup: 1,
|
||||
},
|
||||
}
|
||||
|
||||
if len(config.Rules) != len(expectedRuleFields) {
|
||||
t.Fatalf("expected %v rules", len(expectedRuleFields))
|
||||
}
|
||||
|
||||
for _, expected := range expectedRuleFields {
|
||||
rule, err := findRuleByDescription(config.Rules, expected.Description)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if rule.ReportGroup != expected.ReportGroup {
|
||||
t.Errorf("expected the rule with description '%v' to have a ReportGroup of %v", expected.Description, expected.ReportGroup)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func findRuleByDescription(rules []Rule, description string) (*Rule, error) {
|
||||
for _, rule := range rules {
|
||||
if rule.Description == description {
|
||||
return &rule, nil
|
||||
}
|
||||
}
|
||||
|
||||
return nil, fmt.Errorf("Couldn't find rule with the description: %s", description)
|
||||
}
|
||||
|
||||
func writeTestConfig(toml string) (string, error) {
|
||||
tmpfile, err := ioutil.TempFile("", "testConfig")
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("Couldn't create test config got: %w", err)
|
||||
}
|
||||
|
||||
if _, err := tmpfile.Write([]byte(toml)); err != nil {
|
||||
return "", fmt.Errorf("Couldn't create test config got: %w", err)
|
||||
}
|
||||
|
||||
if err := tmpfile.Close(); err != nil {
|
||||
return "", fmt.Errorf("Couldn't create test config got: %w", err)
|
||||
}
|
||||
|
||||
return tmpfile.Name(), nil
|
||||
}
|
||||
@@ -0,0 +1,164 @@
|
||||
package config
|
||||
|
||||
// DefaultConfig is the default gitleaks configuration. If --config={path-to-config} is set than the config located
|
||||
// at {path-to-config} will be used. Alternatively, if --repo-config is set then gitleaks will attempt to
|
||||
// use the config set in a gitleaks.toml or .gitleaks.toml file in the repo that is run with --repo-config set.
|
||||
const DefaultConfig = `
|
||||
title = "gitleaks config"
|
||||
|
||||
[[rules]]
|
||||
description = "AWS Access Key"
|
||||
regex = '''(A3T[A-Z0-9]|AKIA|AGPA|AIDA|AROA|AIPA|ANPA|ANVA|ASIA)[A-Z0-9]{16}'''
|
||||
tags = ["key", "AWS"]
|
||||
|
||||
[[rules]]
|
||||
description = "AWS Secret Key"
|
||||
regex = '''(?i)aws(.{0,20})?(?-i)['\"][0-9a-zA-Z\/+]{40}['\"]'''
|
||||
tags = ["key", "AWS"]
|
||||
|
||||
[[rules]]
|
||||
description = "AWS MWS key"
|
||||
regex = '''amzn\.mws\.[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}'''
|
||||
tags = ["key", "AWS", "MWS"]
|
||||
|
||||
[[rules]]
|
||||
description = "Facebook Secret Key"
|
||||
regex = '''(?i)(facebook|fb)(.{0,20})?(?-i)['\"][0-9a-f]{32}['\"]'''
|
||||
tags = ["key", "Facebook"]
|
||||
|
||||
[[rules]]
|
||||
description = "Facebook Client ID"
|
||||
regex = '''(?i)(facebook|fb)(.{0,20})?['\"][0-9]{13,17}['\"]'''
|
||||
tags = ["key", "Facebook"]
|
||||
|
||||
[[rules]]
|
||||
description = "Twitter Secret Key"
|
||||
regex = '''(?i)twitter(.{0,20})?[0-9a-z]{35,44}'''
|
||||
tags = ["key", "Twitter"]
|
||||
|
||||
[[rules]]
|
||||
description = "Twitter Client ID"
|
||||
regex = '''(?i)twitter(.{0,20})?[0-9a-z]{18,25}'''
|
||||
tags = ["client", "Twitter"]
|
||||
|
||||
[[rules]]
|
||||
description = "Github"
|
||||
regex = '''(?i)github(.{0,20})?(?-i)[0-9a-zA-Z]{35,40}'''
|
||||
tags = ["key", "Github"]
|
||||
|
||||
[[rules]]
|
||||
description = "LinkedIn Client ID"
|
||||
regex = '''(?i)linkedin(.{0,20})?(?-i)[0-9a-z]{12}'''
|
||||
tags = ["client", "LinkedIn"]
|
||||
|
||||
[[rules]]
|
||||
description = "LinkedIn Secret Key"
|
||||
regex = '''(?i)linkedin(.{0,20})?[0-9a-z]{16}'''
|
||||
tags = ["secret", "LinkedIn"]
|
||||
|
||||
[[rules]]
|
||||
description = "Slack"
|
||||
regex = '''xox[baprs]-([0-9a-zA-Z]{10,48})?'''
|
||||
tags = ["key", "Slack"]
|
||||
|
||||
[[rules]]
|
||||
description = "Asymmetric Private Key"
|
||||
regex = '''-----BEGIN ((EC|PGP|DSA|RSA|OPENSSH) )?PRIVATE KEY( BLOCK)?-----'''
|
||||
tags = ["key", "AsymmetricPrivateKey"]
|
||||
|
||||
[[rules]]
|
||||
description = "Google API key"
|
||||
regex = '''AIza[0-9A-Za-z\\-_]{35}'''
|
||||
tags = ["key", "Google"]
|
||||
|
||||
[[rules]]
|
||||
description = "Google (GCP) Service Account"
|
||||
regex = '''"type": "service_account"'''
|
||||
tags = ["key", "Google"]
|
||||
|
||||
[[rules]]
|
||||
description = "Heroku API key"
|
||||
regex = '''(?i)heroku(.{0,20})?[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}'''
|
||||
tags = ["key", "Heroku"]
|
||||
|
||||
[[rules]]
|
||||
description = "MailChimp API key"
|
||||
regex = '''(?i)(mailchimp|mc)(.{0,20})?[0-9a-f]{32}-us[0-9]{1,2}'''
|
||||
tags = ["key", "Mailchimp"]
|
||||
|
||||
[[rules]]
|
||||
description = "Mailgun API key"
|
||||
regex = '''((?i)(mailgun|mg)(.{0,20})?)?key-[0-9a-z]{32}'''
|
||||
tags = ["key", "Mailgun"]
|
||||
|
||||
[[rules]]
|
||||
description = "PayPal Braintree access token"
|
||||
regex = '''access_token\$production\$[0-9a-z]{16}\$[0-9a-f]{32}'''
|
||||
tags = ["key", "Paypal"]
|
||||
|
||||
[[rules]]
|
||||
description = "Picatic API key"
|
||||
regex = '''sk_live_[0-9a-z]{32}'''
|
||||
tags = ["key", "Picatic"]
|
||||
|
||||
[[rules]]
|
||||
description = "SendGrid API Key"
|
||||
regex = '''SG\.[\w_]{16,32}\.[\w_]{16,64}'''
|
||||
tags = ["key", "SendGrid"]
|
||||
|
||||
[[rules]]
|
||||
description = "Slack Webhook"
|
||||
regex = '''https://hooks.slack.com/services/T[a-zA-Z0-9_]{8}/B[a-zA-Z0-9_]{8}/[a-zA-Z0-9_]{24}'''
|
||||
tags = ["key", "slack"]
|
||||
|
||||
[[rules]]
|
||||
description = "Stripe API key"
|
||||
regex = '''(?i)stripe(.{0,20})?[sr]k_live_[0-9a-zA-Z]{24}'''
|
||||
tags = ["key", "Stripe"]
|
||||
|
||||
[[rules]]
|
||||
description = "Square access token"
|
||||
regex = '''sq0atp-[0-9A-Za-z\-_]{22}'''
|
||||
tags = ["key", "square"]
|
||||
|
||||
[[rules]]
|
||||
description = "Square OAuth secret"
|
||||
regex = '''sq0csp-[0-9A-Za-z\\-_]{43}'''
|
||||
tags = ["key", "square"]
|
||||
|
||||
[[rules]]
|
||||
description = "Twilio API key"
|
||||
regex = '''(?i)twilio(.{0,20})?SK[0-9a-f]{32}'''
|
||||
tags = ["key", "twilio"]
|
||||
|
||||
[[rules]]
|
||||
description = "Dynatrace ttoken"
|
||||
regex = '''dt0[a-zA-Z]{1}[0-9]{2}\.[A-Z0-9]{24}\.[A-Z0-9]{64}'''
|
||||
tags = ["key", "Dynatrace"]
|
||||
|
||||
[[rules]]
|
||||
description = "Shopify shared secret"
|
||||
regex = '''shpss_[a-fA-F0-9]{32}'''
|
||||
tags = ["key", "Shopify"]
|
||||
|
||||
[[rules]]
|
||||
description = "Shopify access token"
|
||||
regex = '''shpat_[a-fA-F0-9]{32}'''
|
||||
tags = ["key", "Shopify"]
|
||||
|
||||
[[rules]]
|
||||
description = "Shopify custom app access token"
|
||||
regex = '''shpca_[a-fA-F0-9]{32}'''
|
||||
tags = ["key", "Shopify"]
|
||||
|
||||
[[rules]]
|
||||
description = "Shopify private app access token"
|
||||
regex = '''shppa_[a-fA-F0-9]{32}'''
|
||||
tags = ["key", "Shopify"]
|
||||
|
||||
[allowlist]
|
||||
description = "Allowlisted files"
|
||||
files = ['''^\.?gitleaks.toml$''',
|
||||
'''(.*?)(png|jpg|gif|doc|docx|pdf|bin|xls|pyc|zip)$''',
|
||||
'''(go.mod|go.sum)$''']
|
||||
`
|
||||
+143
@@ -0,0 +1,143 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"math"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
)
|
||||
|
||||
// Rule is a struct that contains information that is loaded from a gitleaks config.
|
||||
// This struct is used in the Config struct as an array of Rules and is iterated
|
||||
// over during an scan. Each rule will be checked. If a regex match is found AND
|
||||
// that match is not allowlisted (globally or locally), then a leak will be appended
|
||||
// to the final scan report.
|
||||
type Rule struct {
|
||||
Description string
|
||||
Regex *regexp.Regexp
|
||||
File *regexp.Regexp
|
||||
Path *regexp.Regexp
|
||||
ReportGroup int
|
||||
Tags []string
|
||||
AllowList AllowList
|
||||
Entropies []Entropy
|
||||
}
|
||||
|
||||
// Inspect checks the content of a line for a leak
|
||||
func (r *Rule) Inspect(line string) string {
|
||||
offender := r.Regex.FindString(line)
|
||||
if offender == "" {
|
||||
return ""
|
||||
}
|
||||
|
||||
// check if offender is allowed
|
||||
if r.RegexAllowed(line) {
|
||||
return ""
|
||||
}
|
||||
|
||||
// check entropy
|
||||
groups := r.Regex.FindStringSubmatch(offender)
|
||||
if len(r.Entropies) != 0 && !r.ContainsEntropyLeak(groups) {
|
||||
return ""
|
||||
}
|
||||
|
||||
// 0 is a match for the full regex pattern
|
||||
if 0 < r.ReportGroup && r.ReportGroup < len(groups) {
|
||||
offender = groups[r.ReportGroup]
|
||||
}
|
||||
return offender
|
||||
}
|
||||
|
||||
// RegexAllowed checks if the content is allowlisted
|
||||
func (r *Rule) RegexAllowed(content string) bool {
|
||||
return anyRegexMatch(content, r.AllowList.Regexes)
|
||||
}
|
||||
|
||||
// CommitAllowed checks if a commit is allowlisted
|
||||
func (r *Rule) CommitAllowed(commit string) bool {
|
||||
return r.AllowList.CommitAllowed(commit)
|
||||
}
|
||||
|
||||
// ContainsEntropyLeak checks if there is an entropy leak
|
||||
func (r *Rule) ContainsEntropyLeak(groups []string) bool {
|
||||
for _, e := range r.Entropies {
|
||||
if len(groups) > e.Group {
|
||||
entropy := shannonEntropy(groups[e.Group])
|
||||
if entropy >= e.Min && entropy <= e.Max {
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// HasFileOrPathLeakOnly first checks if there are no entropy/regex rules, then checks if
|
||||
// there are any file/path leaks
|
||||
func (r *Rule) HasFileOrPathLeakOnly(filePath string) bool {
|
||||
if r.Regex.String() != "" {
|
||||
return false
|
||||
}
|
||||
if len(r.Entropies) != 0 {
|
||||
return false
|
||||
}
|
||||
if r.AllowList.FileAllowed(filepath.Base(filePath)) || r.AllowList.PathAllowed(filePath) {
|
||||
return false
|
||||
}
|
||||
return r.HasFileLeak(filepath.Base(filePath)) || r.HasFilePathLeak(filePath)
|
||||
}
|
||||
|
||||
// HasFileLeak checks if there is a file leak
|
||||
func (r *Rule) HasFileLeak(fileName string) bool {
|
||||
return regexMatched(fileName, r.File)
|
||||
}
|
||||
|
||||
// HasFilePathLeak checks if there is a path leak
|
||||
func (r *Rule) HasFilePathLeak(filePath string) bool {
|
||||
return regexMatched(filePath, r.Path)
|
||||
}
|
||||
|
||||
// shannonEntropy calculates the entropy of data using the formula defined here:
|
||||
// https://en.wiktionary.org/wiki/Shannon_entropy
|
||||
// Another way to think about what this is doing is calculating the number of bits
|
||||
// needed to on average encode the data. So, the higher the entropy, the more random the data, the
|
||||
// more bits needed to encode that data.
|
||||
func shannonEntropy(data string) (entropy float64) {
|
||||
if data == "" {
|
||||
return 0
|
||||
}
|
||||
|
||||
charCounts := make(map[rune]int)
|
||||
for _, char := range data {
|
||||
charCounts[char]++
|
||||
}
|
||||
|
||||
invLength := 1.0 / float64(len(data))
|
||||
for _, count := range charCounts {
|
||||
freq := float64(count) * invLength
|
||||
entropy -= freq * math.Log2(freq)
|
||||
}
|
||||
|
||||
return entropy
|
||||
}
|
||||
|
||||
// regexMatched matched an interface to a regular expression. The interface f can
|
||||
// be a string type or go-git *object.File type.
|
||||
func regexMatched(f string, re *regexp.Regexp) bool {
|
||||
if re == nil {
|
||||
return false
|
||||
}
|
||||
if re.FindString(f) != "" {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// anyRegexMatch matched an interface to a regular expression. The interface f can
|
||||
// be a string type or go-git *object.File type.
|
||||
func anyRegexMatch(f string, res []*regexp.Regexp) bool {
|
||||
for _, re := range res {
|
||||
if regexMatched(f, re) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
@@ -0,0 +1,195 @@
|
||||
title = "gitleaks config"
|
||||
|
||||
[[rules]]
|
||||
description = "AWS Access Key"
|
||||
regex = '''(A3T[A-Z0-9]|AKIA|AGPA|AIDA|AROA|AIPA|ANPA|ANVA|ASIA)[A-Z0-9]{16}'''
|
||||
tags = ["key", "AWS"]
|
||||
|
||||
[[rules]]
|
||||
description = "AWS cred file info"
|
||||
regex = '''(?i)(aws_access_key_id|aws_secret_access_key)(.{0,20})?=.[0-9a-zA-Z\/+]{20,40}'''
|
||||
tags = ["AWS"]
|
||||
|
||||
[[rules]]
|
||||
description = "AWS Secret Key"
|
||||
regex = '''(?i)aws(.{0,20})?(?-i)['\"][0-9a-zA-Z\/+]{40}['\"]'''
|
||||
tags = ["key", "AWS"]
|
||||
|
||||
[[rules]]
|
||||
description = "AWS MWS key"
|
||||
regex = '''amzn\.mws\.[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}'''
|
||||
tags = ["key", "AWS", "MWS"]
|
||||
|
||||
[[rules]]
|
||||
description = "Facebook Secret Key"
|
||||
regex = '''(?i)(facebook|fb)(.{0,20})?(?-i)['\"][0-9a-f]{32}['\"]'''
|
||||
tags = ["key", "Facebook"]
|
||||
|
||||
[[rules]]
|
||||
description = "Facebook Client ID"
|
||||
regex = '''(?i)(facebook|fb)(.{0,20})?['\"][0-9]{13,17}['\"]'''
|
||||
tags = ["key", "Facebook"]
|
||||
|
||||
[[rules]]
|
||||
description = "Twitter Secret Key"
|
||||
regex = '''(?i)twitter(.{0,20})?['\"][0-9a-z]{35,44}['\"]'''
|
||||
tags = ["key", "Twitter"]
|
||||
|
||||
[[rules]]
|
||||
description = "Twitter Client ID"
|
||||
regex = '''(?i)twitter(.{0,20})?['\"][0-9a-z]{18,25}['\"]'''
|
||||
tags = ["client", "Twitter"]
|
||||
|
||||
[[rules]]
|
||||
description = "Github"
|
||||
regex = '''(?i)github(.{0,20})?(?-i)['\"][0-9a-zA-Z]{35,40}['\"]'''
|
||||
tags = ["key", "Github"]
|
||||
|
||||
[[rules]]
|
||||
description = "LinkedIn Client ID"
|
||||
regex = '''(?i)linkedin(.{0,20})?(?-i)['\"][0-9a-z]{12}['\"]'''
|
||||
tags = ["client", "LinkedIn"]
|
||||
|
||||
[[rules]]
|
||||
description = "LinkedIn Secret Key"
|
||||
regex = '''(?i)linkedin(.{0,20})?['\"][0-9a-z]{16}['\"]'''
|
||||
tags = ["secret", "LinkedIn"]
|
||||
|
||||
[[rules]]
|
||||
description = "Slack"
|
||||
regex = '''xox[baprs]-([0-9a-zA-Z]{10,48})?'''
|
||||
tags = ["key", "Slack"]
|
||||
|
||||
[[rules]]
|
||||
description = "EC"
|
||||
regex = '''-----BEGIN EC PRIVATE KEY-----'''
|
||||
tags = ["key", "EC"]
|
||||
|
||||
|
||||
[[rules]]
|
||||
description = "Google API key"
|
||||
regex = '''AIza[0-9A-Za-z\\-_]{35}'''
|
||||
tags = ["key", "Google"]
|
||||
|
||||
|
||||
[[rules]]
|
||||
description = "Heroku API key"
|
||||
regex = '''(?i)heroku(.{0,20})?['"][0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}['"]'''
|
||||
tags = ["key", "Heroku"]
|
||||
|
||||
[[rules]]
|
||||
description = "MailChimp API key"
|
||||
regex = '''(?i)(mailchimp|mc)(.{0,20})?['"][0-9a-f]{32}-us[0-9]{1,2}['"]'''
|
||||
tags = ["key", "Mailchimp"]
|
||||
|
||||
[[rules]]
|
||||
description = "Mailgun API key"
|
||||
regex = '''(?i)(mailgun|mg)(.{0,20})?['"][0-9a-z]{32}['"]'''
|
||||
tags = ["key", "Mailgun"]
|
||||
|
||||
[[rules]]
|
||||
description = "PayPal Braintree access token"
|
||||
regex = '''access_token\$production\$[0-9a-z]{16}\$[0-9a-f]{32}'''
|
||||
tags = ["key", "Paypal"]
|
||||
|
||||
[[rules]]
|
||||
description = "Picatic API key"
|
||||
regex = '''sk_live_[0-9a-z]{32}'''
|
||||
tags = ["key", "Picatic"]
|
||||
|
||||
[[rules]]
|
||||
description = "Slack Webhook"
|
||||
regex = '''https://hooks.slack.com/services/T[a-zA-Z0-9_]{8}/B[a-zA-Z0-9_]{8}/[a-zA-Z0-9_]{24}'''
|
||||
tags = ["key", "slack"]
|
||||
|
||||
[[rules]]
|
||||
description = "Stripe API key"
|
||||
regex = '''(?i)stripe(.{0,20})?['\"][sk|rk]_live_[0-9a-zA-Z]{24}'''
|
||||
tags = ["key", "Stripe"]
|
||||
|
||||
[[rules]]
|
||||
description = "Square access token"
|
||||
regex = '''sq0atp-[0-9A-Za-z\-_]{22}'''
|
||||
tags = ["key", "square"]
|
||||
|
||||
[[rules]]
|
||||
description = "Square OAuth secret"
|
||||
regex = '''sq0csp-[0-9A-Za-z\\-_]{43}'''
|
||||
tags = ["key", "square"]
|
||||
|
||||
[[rules]]
|
||||
description = "Twilio API key"
|
||||
regex = '''(?i)twilio(.{0,20})?['\"][0-9a-f]{32}['\"]'''
|
||||
tags = ["key", "twilio"]
|
||||
|
||||
[[rules]]
|
||||
description = "Env Var"
|
||||
regex = '''(?i)(apikey|secret|key|api|password|pass|pw|host)=[0-9a-zA-Z-_.{}]{4,120}'''
|
||||
|
||||
[[rules]]
|
||||
description = "Port"
|
||||
regex = '''(?i)port(.{0,4})?[0-9]{1,10}'''
|
||||
[rules.allowlist]
|
||||
regexes = ['''(?i)port ''']
|
||||
description = "ignore export "
|
||||
|
||||
|
||||
|
||||
[[rules]]
|
||||
description = "Email"
|
||||
regex = '''[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}'''
|
||||
tags = ["email"]
|
||||
[rules.allowlist]
|
||||
files = ['''(?i)bashrc''']
|
||||
description = "ignore bashrc emails"
|
||||
|
||||
|
||||
[[rules]]
|
||||
description = "Generic Credential"
|
||||
regex = '''(?i)(dbpasswd|dbuser|dbname|dbhost|api_key|apikey|secret|key|api|password|user|guid|hostname|pw|auth)(.{0,20})?['|"]([0-9a-zA-Z-_\/+!{}/=]{4,120})['|"]'''
|
||||
tags = ["key", "API", "generic"]
|
||||
# ignore leaks with specific identifiers like slack and aws
|
||||
[rules.allowlist]
|
||||
description = "ignore slack, mailchimp, aws"
|
||||
regexes = [
|
||||
'''xox[baprs]-([0-9a-zA-Z]{10,48})''',
|
||||
'''(?i)(.{0,20})?['"][0-9a-f]{32}-us[0-9]{1,2}['"]''',
|
||||
'''(A3T[A-Z0-9]|AKIA|AGPA|AIDA|AROA|AIPA|ANPA|ANVA|ASIA)[A-Z0-9]{16}'''
|
||||
]
|
||||
|
||||
[[rules]]
|
||||
description = "High Entropy"
|
||||
regex = '''[0-9a-zA-Z-_!{}/=]{4,120}'''
|
||||
file = '''(?i)(dump.sql|high-entropy-misc.txt)$'''
|
||||
tags = ["entropy"]
|
||||
[[rules.Entropies]]
|
||||
Min = "4.3"
|
||||
Max = "7.0"
|
||||
[rules.allowlist]
|
||||
description = "ignore ssh key and pems"
|
||||
files = ['''(pem|ppk|env)$''']
|
||||
paths = ['''(.*)?ssh''']
|
||||
|
||||
[[rules]]
|
||||
description = "Potential bash var"
|
||||
regex='''(?i)(=)([0-9a-zA-Z-_!{}=]{4,120})'''
|
||||
tags = ["key", "bash", "API", "generic"]
|
||||
[[rules.Entropies]]
|
||||
Min = "3.5"
|
||||
Max = "4.5"
|
||||
Group = "1"
|
||||
|
||||
[[rules]]
|
||||
description = "WP-Config"
|
||||
regex='''define(.{0,20})?(DB_CHARSET|NONCE_SALT|LOGGED_IN_SALT|AUTH_SALT|NONCE_KEY|DB_HOST|DB_PASSWORD|AUTH_KEY|SECURE_AUTH_KEY|LOGGED_IN_KEY|DB_NAME|DB_USER)(.{0,20})?['|"].{10,120}['|"]'''
|
||||
tags = ["key", "API", "generic"]
|
||||
|
||||
[[rules]]
|
||||
description = "Files with keys and credentials"
|
||||
file = '''(?i)(id_rsa|passwd|id_rsa.pub|pgpass|pem|key|shadow)'''
|
||||
|
||||
# Global allowlist
|
||||
[allowlist]
|
||||
description = "image allowlists"
|
||||
files = ['''(.*?)(jpg|gif|doc|pdf|bin)$''']
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
#!/bin/sh
|
||||
|
||||
# This is an example of what adding gitleaks to a pre-commit hook would look like.
|
||||
|
||||
gitleaksEnabled=$(git config --bool hooks.gitleaks)
|
||||
cmd="/Users/zrice/go/src/github.com/zricethezav/gitleaks/gitleaks --verbose --redact --pretty"
|
||||
if [ $gitleaksEnabled == "true" ]; then
|
||||
$cmd
|
||||
if [ $? -eq 1 ]; then
|
||||
cat <<\EOF
|
||||
Error: gitleaks has detected sensitive information in your changes.
|
||||
If you know what you are doing you can disable this check using:
|
||||
|
||||
git config hooks.gitleaks false
|
||||
|
||||
EOF
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
@@ -0,0 +1,17 @@
|
||||
# This config contains a single rule which defines a regex and a range of entropy values. If a rule has
|
||||
# both regex and entropy then that rule uses BOTH the regex and entropy in combination when performing an scan.
|
||||
# In other words, if a line of code has an entropy value that is within the range of the entropies defined and
|
||||
# a regex match is found then that line of code contains a leak.
|
||||
|
||||
# So, for this example if a line of code has an entropy value of 4.6 AND matches the regex below then we got a leak.
|
||||
|
||||
[[rules]]
|
||||
description = "entropy and regex"
|
||||
regex = '''(?i)key(.{0,20})?['|"][0-9a-zA-Z]{16,45}['|"]'''
|
||||
tags = ["entropy"]
|
||||
[[rules.Entropies]]
|
||||
Min = "4.5"
|
||||
Max = "5.7"
|
||||
[[rules.Entropies]]
|
||||
Min = "5.5"
|
||||
Max = "6.3"
|
||||
@@ -0,0 +1,13 @@
|
||||
# This config contains a single rule that checks for AWS keys. However, it also contains a allowlist table
|
||||
# where you can define one or more allowlists. What this means is that if you have an example AWS key as part of your
|
||||
# code (in a test for example), then you can allowlist that specific key so gitleaks will not label it as a leak.
|
||||
# If this line was present in a git history: `aws_access_key_id='AKIAIO5FODNN7EXAMPLE``, gitleaks would match this line
|
||||
# with the rule below, but since we have a allowlist against that specific key, it would be ignored.
|
||||
|
||||
[[rules]]
|
||||
description = "AWS Access Key"
|
||||
regex = '''(A3T[A-Z0-9]|AKIA|AGPA|AIDA|AROA|AIPA|ANPA|ANVA|ASIA)[A-Z0-9]{16}'''
|
||||
tags = ["key", "AWS"]
|
||||
[rules.allowlist]
|
||||
regexes = ['''AKIAIO5FODNN7EXAMPLE.*''']
|
||||
description = "ignore example aws key"
|
||||
@@ -0,0 +1,6 @@
|
||||
# This is a simple gitleaks config that contains one rule which checks for AWS keys.
|
||||
|
||||
[[rules]]
|
||||
description = "AWS Access Key"
|
||||
regex = '''(A3T[A-Z0-9]|AKIA|AGPA|AIDA|AROA|AIPA|ANPA|ANVA|ASIA)[A-Z0-9]{16}'''
|
||||
tags = ["key", "AWS"]
|
||||
-219
@@ -1,219 +0,0 @@
|
||||
title = "sample gitleaks config"
|
||||
|
||||
# This is a sample config file for gitleaks. You can configure gitleaks what to search for and what to whitelist.
|
||||
# The output you are seeing here is the default gitleaks config. If GITLEAKS_CONFIG environment variable
|
||||
# is set, gitleaks will load configurations from that path. If option --config-path is set, gitleaks will load
|
||||
# configurations from that path. Gitleaks does not whitelist anything by default.
|
||||
# - https://www.ndss-symposium.org/wp-content/uploads/2019/02/ndss2019_04B-3_Meli_paper.pdf
|
||||
# - https://github.com/dxa4481/truffleHogRegexes/blob/master/truffleHogRegexes/regexes.json
|
||||
[[rules]]
|
||||
description = "AWS Client ID"
|
||||
regex = '''(A3T[A-Z0-9]|AKIA|AGPA|AIDA|AROA|AIPA|ANPA|ANVA|ASIA)[A-Z0-9]{16}'''
|
||||
tags = ["key", "AWS"]
|
||||
|
||||
[[rules]]
|
||||
description = "AWS Secret Key"
|
||||
regex = '''(?i)aws(.{0,20})?(?-i)['\"][0-9a-zA-Z\/+]{40}['\"]'''
|
||||
tags = ["key", "AWS"]
|
||||
|
||||
[[rules]]
|
||||
description = "AWS MWS key"
|
||||
regex = '''amzn\.mws\.[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}'''
|
||||
tags = ["key", "AWS", "MWS"]
|
||||
|
||||
[[rules]]
|
||||
description = "PKCS8"
|
||||
regex = '''-----BEGIN PRIVATE KEY-----'''
|
||||
tags = ["key", "PKCS8"]
|
||||
|
||||
[[rules]]
|
||||
description = "RSA"
|
||||
regex = '''-----BEGIN RSA PRIVATE KEY-----'''
|
||||
tags = ["key", "RSA"]
|
||||
|
||||
[[rules]]
|
||||
description = "SSH"
|
||||
regex = '''-----BEGIN OPENSSH PRIVATE KEY-----'''
|
||||
tags = ["key", "SSH"]
|
||||
|
||||
[[rules]]
|
||||
description = "PGP"
|
||||
regex = '''-----BEGIN PGP PRIVATE KEY BLOCK-----'''
|
||||
tags = ["key", "PGP"]
|
||||
|
||||
[[rules]]
|
||||
description = "Facebook Secret Key"
|
||||
regex = '''(?i)(facebook|fb)(.{0,20})?(?-i)['\"][0-9a-f]{32}['\"]'''
|
||||
tags = ["key", "Facebook"]
|
||||
|
||||
[[rules]]
|
||||
description = "Facebook Client ID"
|
||||
regex = '''(?i)(facebook|fb)(.{0,20})?['\"][0-9]{13,17}['\"]'''
|
||||
tags = ["key", "Facebook"]
|
||||
|
||||
[[rules]]
|
||||
description = "Facebook access token"
|
||||
regex = '''EAACEdEose0cBA[0-9A-Za-z]+'''
|
||||
tags = ["key", "Facebook"]
|
||||
|
||||
[[rules]]
|
||||
description = "Twitter Secret Key"
|
||||
regex = '''(?i)twitter(.{0,20})?['\"][0-9a-z]{35,44}['\"]'''
|
||||
tags = ["key", "Twitter"]
|
||||
|
||||
[[rules]]
|
||||
description = "Twitter Client ID"
|
||||
regex = '''(?i)twitter(.{0,20})?['\"][0-9a-z]{18,25}['\"]'''
|
||||
tags = ["client", "Twitter"]
|
||||
|
||||
[[rules]]
|
||||
description = "Github"
|
||||
regex = '''(?i)github(.{0,20})?(?-i)['\"][0-9a-zA-Z]{35,40}['\"]'''
|
||||
tags = ["key", "Github"]
|
||||
|
||||
[[rules]]
|
||||
description = "LinkedIn Client ID"
|
||||
regex = '''(?i)linkedin(.{0,20})?(?-i)['\"][0-9a-z]{12}['\"]'''
|
||||
tags = ["client", "Twitter"]
|
||||
|
||||
[[rules]]
|
||||
description = "LinkedIn Secret Key"
|
||||
regex = '''(?i)linkedin(.{0,20})?['\"][0-9a-z]{16}['\"]'''
|
||||
tags = ["secret", "Twitter"]
|
||||
|
||||
[[rules]]
|
||||
description = "Slack"
|
||||
regex = '''xox[baprs]-([0-9a-zA-Z]{10,48})?'''
|
||||
tags = ["key", "Slack"]
|
||||
|
||||
[[rules]]
|
||||
description = "EC"
|
||||
regex = '''-----BEGIN EC PRIVATE KEY-----'''
|
||||
tags = ["key", "EC"]
|
||||
|
||||
[[rules]]
|
||||
description = "Generic API key"
|
||||
regex = '''(?i)api_key(.{0,20})?['|"][0-9a-zA-Z]{32,45}['|"]'''
|
||||
tags = ["key", "API", "generic"]
|
||||
|
||||
[[rules]]
|
||||
description = "Generic Secret"
|
||||
regex = '''(?i)secret(.{0,20})?['|"][0-9a-zA-Z]{32,45}['|"]'''
|
||||
tags = ["key", "Secret", "generic"]
|
||||
|
||||
[[rules]]
|
||||
description = "Google API key"
|
||||
regex = '''AIza[0-9A-Za-z\\-_]{35}'''
|
||||
tags = ["key", "Google"]
|
||||
|
||||
[[rules]]
|
||||
description = "Google Cloud Platform API key"
|
||||
regex = '''(?i)(google|gcp|youtube|drive|yt)(.{0,20})?['\"][AIza[0-9a-z\\-_]{35}]['\"]'''
|
||||
tags = ["key", "Google", "GCP"]
|
||||
|
||||
[[rules]]
|
||||
description = "Google OAuth"
|
||||
regex = '''(?i)(google|gcp|auth)(.{0,20})?['"][0-9]+-[0-9a-z_]{32}\.apps\.googleusercontent\.com['"]'''
|
||||
tags = ["key", "Google", "OAuth"]
|
||||
|
||||
[[rules]]
|
||||
description = "Google OAuth access token"
|
||||
regex = '''ya29\.[0-9A-Za-z\-_]+'''
|
||||
tags = ["key", "Google", "OAuth"]
|
||||
|
||||
[[rules]]
|
||||
description = "Heroku API key"
|
||||
regex = '''(?i)heroku(.{0,20})?['"][0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}['"]'''
|
||||
tags = ["key", "Heroku"]
|
||||
|
||||
[[rules]]
|
||||
description = "MailChimp API key"
|
||||
regex = '''(?i)(mailchimp|mc)(.{0,20})?['"][0-9a-f]{32}-us[0-9]{1,2}['"]'''
|
||||
tags = ["key", "Mailchimp"]
|
||||
|
||||
[[rules]]
|
||||
description = "Mailgun API key"
|
||||
regex = '''(?i)(mailgun|mg)(.{0,20})?['"][0-9a-z]{32}['"]'''
|
||||
tags = ["key", "Mailgun"]
|
||||
|
||||
[[rules]]
|
||||
description = "Password in URL"
|
||||
regex = '''[a-zA-Z]{3,10}:\/\/[^\/\s:@]{3,20}:[^\/\s:@]{3,20}@.{1,100}\/?.?'''
|
||||
tags = ["key", "URL", "generic"]
|
||||
|
||||
[[rules]]
|
||||
description = "PayPal Braintree access token"
|
||||
regex = '''access_token\$production\$[0-9a-z]{16}\$[0-9a-f]{32}'''
|
||||
tags = ["key", "Paypal"]
|
||||
|
||||
[[rules]]
|
||||
description = "Picatic API key"
|
||||
regex = '''sk_live_[0-9a-z]{32}'''
|
||||
tags = ["key", "Picatic"]
|
||||
|
||||
[[rules]]
|
||||
description = "Slack Webhook"
|
||||
regex = '''https://hooks.slack.com/services/T[a-zA-Z0-9_]{8}/B[a-zA-Z0-9_]{8}/[a-zA-Z0-9_]{24}'''
|
||||
tags = ["key", "slack"]
|
||||
|
||||
[[rules]]
|
||||
description = "Stripe API key"
|
||||
regex = '''(?i)stripe(.{0,20})?['\"][sk|rk]_live_[0-9a-zA-Z]{24}'''
|
||||
tags = ["key", "Stripe"]
|
||||
|
||||
[[rules]]
|
||||
description = "Square access token"
|
||||
regex = '''sq0atp-[0-9A-Za-z\-_]{22}'''
|
||||
tags = ["key", "square"]
|
||||
|
||||
[[rules]]
|
||||
description = "Square OAuth secret"
|
||||
regex = '''sq0csp-[0-9A-Za-z\\-_]{43}'''
|
||||
tags = ["key", "square"]
|
||||
|
||||
[[rules]]
|
||||
description = "Twilio API key"
|
||||
regex = '''(?i)twilio(.{0,20})?['\"][0-9a-f]{32}['\"]'''
|
||||
tags = ["key", "twilio"]
|
||||
|
||||
[whitelist]
|
||||
files = [
|
||||
"(.*?)(jpg|gif|doc|pdf|bin)$"
|
||||
]
|
||||
#commits = [
|
||||
# "whitelisted-commit1",
|
||||
# "whitelisted-commit2",
|
||||
#]
|
||||
#repos = [
|
||||
# "whitelisted-repo"
|
||||
#]
|
||||
|
||||
# Additional Examples
|
||||
|
||||
# [[rules]]
|
||||
# description = "Generic Key"
|
||||
# regex = '''(?i)key(.{0,6})?(:|=|=>|:=)'''
|
||||
# entropies = [
|
||||
# "4.1-4.3",
|
||||
# "5.5-6.3",
|
||||
# ]
|
||||
# entropyROI = "line"
|
||||
# filetypes = [".go", ".py", ".c"]
|
||||
# tags = ["key"]
|
||||
# severity = "8"
|
||||
#
|
||||
#
|
||||
# [[rules]]
|
||||
# description = "Generic Key"
|
||||
# regex = '''(?i)key(.{0,6})?(:|=|=>|:=)'''
|
||||
# entropies = ["4.1-4.3"]
|
||||
# filetypes = [".gee"]
|
||||
# entropyROI = "line"
|
||||
# tags = ["key"]
|
||||
# severity = "medium"
|
||||
|
||||
# [[rules]]
|
||||
# description = "Any pem file"
|
||||
# filetypes = [".key"]
|
||||
# tags = ["pem"]
|
||||
# severity = "high"
|
||||
@@ -1,25 +1,17 @@
|
||||
module github.com/zricethezav/gitleaks
|
||||
module github.com/zricethezav/gitleaks/v7
|
||||
|
||||
go 1.15
|
||||
|
||||
replace github.com/go-git/go-git/v5 => github.com/zricethezav/go-git/v5 v5.2.2
|
||||
|
||||
require (
|
||||
github.com/BurntSushi/toml v0.3.1
|
||||
github.com/emirpasic/gods v1.12.0 // indirect
|
||||
github.com/franela/goblin v0.0.0-20181003173013-ead4ad1d2727
|
||||
github.com/google/go-github v15.0.0+incompatible
|
||||
github.com/google/go-querystring v1.0.0 // indirect
|
||||
github.com/hako/durafmt v0.0.0-20180520121703-7b7ae1e72ead
|
||||
github.com/ipfs/go-ipfs v0.4.19 // indirect
|
||||
github.com/go-git/go-git/v5 v5.2.0
|
||||
github.com/google/go-cmp v0.4.0 // indirect
|
||||
github.com/hako/durafmt v0.0.0-20191009132224-3f39dc1ed9f4
|
||||
github.com/jessevdk/go-flags v1.4.0
|
||||
github.com/mattn/go-colorable v0.1.2
|
||||
github.com/onsi/ginkgo v1.8.0 // indirect
|
||||
github.com/onsi/gomega v1.5.0 // indirect
|
||||
github.com/sirupsen/logrus v1.0.6
|
||||
github.com/xanzy/go-gitlab v0.11.3
|
||||
golang.org/x/lint v0.0.0-20190409202823-959b441ac422 // indirect
|
||||
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be
|
||||
golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6 // indirect
|
||||
google.golang.org/appengine v1.2.0 // indirect
|
||||
gopkg.in/airbrake/gobrake.v2 v2.0.9 // indirect
|
||||
gopkg.in/gemnasium/logrus-airbrake-hook.v2 v2.1.2 // indirect
|
||||
gopkg.in/src-d/go-billy.v4 v4.3.0 // indirect
|
||||
gopkg.in/src-d/go-git.v4 v4.9.1
|
||||
github.com/sergi/go-diff v1.1.0
|
||||
github.com/sirupsen/logrus v1.4.2
|
||||
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9
|
||||
gopkg.in/yaml.v2 v2.2.8 // indirect
|
||||
)
|
||||
@@ -4,123 +4,104 @@ github.com/alcortesm/tgz v0.0.0-20161220082320-9c5fe88206d7 h1:uSoVVbwJiQipAclBb
|
||||
github.com/alcortesm/tgz v0.0.0-20161220082320-9c5fe88206d7/go.mod h1:6zEj6s6u/ghQa61ZWa/C2Aw3RkjiTBOix7dkqa1VLIs=
|
||||
github.com/anmitsu/go-shlex v0.0.0-20161002113705-648efa622239 h1:kFOfPq6dUM1hTo4JG6LR5AXSUEsOjtdm0kw0FtQtMJA=
|
||||
github.com/anmitsu/go-shlex v0.0.0-20161002113705-648efa622239/go.mod h1:2FmKhYUyUczH0OGQWaF5ceTx0UBShxjsH6f8oGKYe2c=
|
||||
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 h1:0CwZNZbxp69SHPdPJAN/hZIm0C4OItdklCFmMRWYpio=
|
||||
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs=
|
||||
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/emirpasic/gods v1.9.0/go.mod h1:YfzfFFoVP/catgzJb4IKIqXjX78Ha8FMSDh3ymbK86o=
|
||||
github.com/emirpasic/gods v1.12.0 h1:QAUIPSaCu4G+POclxeqb3F+WPpdKqFGlw36+yOzGlrg=
|
||||
github.com/emirpasic/gods v1.12.0/go.mod h1:YfzfFFoVP/catgzJb4IKIqXjX78Ha8FMSDh3ymbK86o=
|
||||
github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568 h1:BHsljHzVlRcyQhjrss6TZTdY2VfCqZPbv5k3iBFa2ZQ=
|
||||
github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568/go.mod h1:xEzjJPgXI435gkrCt3MPfRiAkVrwSbHsst4LCFVfpJc=
|
||||
github.com/franela/goblin v0.0.0-20181003173013-ead4ad1d2727 h1:eouy4stZdUKn7n98c1+rdUTxWMg+jvhP+oHt0K8fiug=
|
||||
github.com/franela/goblin v0.0.0-20181003173013-ead4ad1d2727/go.mod h1:7dvUGVsVBjqR7JHJk0brhHOZYGmfBYOrK0ZhYMEtBr4=
|
||||
github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I=
|
||||
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
|
||||
github.com/gliderlabs/ssh v0.1.1 h1:j3L6gSLQalDETeEg/Jg0mGY0/y/N6zI2xX1978P0Uqw=
|
||||
github.com/gliderlabs/ssh v0.1.1/go.mod h1:U7qILu1NlMHj9FlMhZLlkCdDnU1DBEAqr0aevW3Awn0=
|
||||
github.com/golang/protobuf v1.2.0 h1:P3YflyNX/ehuJFLhxviNdFxQPkGK5cDcApsge1SqnvM=
|
||||
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
||||
github.com/google/go-cmp v0.2.0 h1:+dTQ8DZQJz0Mb/HjFlkptS1FeQ4cWSnN941F8aEG4SQ=
|
||||
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
|
||||
github.com/google/go-github v15.0.0+incompatible h1:jlPg2Cpsxb/FyEV/MFiIE9tW/2RAevQNZDPeHbf5a94=
|
||||
github.com/google/go-github v15.0.0+incompatible/go.mod h1:zLgOLi98H3fifZn+44m+umXrS52loVEgC2AApnigrVQ=
|
||||
github.com/google/go-querystring v1.0.0 h1:Xkwi/a1rcvNg1PPYe5vI8GbeBY/jrVuDX5ASuANWTrk=
|
||||
github.com/google/go-querystring v1.0.0/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck=
|
||||
github.com/hako/durafmt v0.0.0-20180520121703-7b7ae1e72ead h1:Y9WOGZY2nw5ksbEf5AIpk+vK52Tdg/VN/rHFRfEeeGQ=
|
||||
github.com/hako/durafmt v0.0.0-20180520121703-7b7ae1e72ead/go.mod h1:5Scbynm8dF1XAPwIwkGPqzkM/shndPm79Jd1003hTjE=
|
||||
github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI=
|
||||
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
|
||||
github.com/ipfs/go-ipfs v0.4.19 h1:ioUvuv1L3Zb9XgPi6S8selFMMlTa5AntQzVGvaoYHXM=
|
||||
github.com/ipfs/go-ipfs v0.4.19/go.mod h1:iXzbK+Wa6eePj3jQg/uY6Uoq5iOwY+GToD/bgaRadto=
|
||||
github.com/gliderlabs/ssh v0.2.2 h1:6zsha5zo/TWhRhwqCD3+EarCAgZ2yN28ipRnGPnwkI0=
|
||||
github.com/gliderlabs/ssh v0.2.2/go.mod h1:U7qILu1NlMHj9FlMhZLlkCdDnU1DBEAqr0aevW3Awn0=
|
||||
github.com/go-git/gcfg v1.5.0 h1:Q5ViNfGF8zFgyJWPqYwA7qGFoMTEiBmdlkcfRmpIMa4=
|
||||
github.com/go-git/gcfg v1.5.0/go.mod h1:5m20vg6GwYabIxaOonVkTdrILxQMpEShl1xiMF4ua+E=
|
||||
github.com/go-git/go-billy/v5 v5.0.0 h1:7NQHvd9FVid8VL4qVUMm8XifBK+2xCoZ2lSk0agRrHM=
|
||||
github.com/go-git/go-billy/v5 v5.0.0/go.mod h1:pmpqyWchKfYfrkb/UVH4otLvyi/5gJlGI4Hb3ZqZ3W0=
|
||||
github.com/go-git/go-git-fixtures/v4 v4.0.2-0.20200613231340-f56387b50c12 h1:PbKy9zOy4aAKrJ5pibIRpVO2BXnK1Tlcg+caKI7Ox5M=
|
||||
github.com/go-git/go-git-fixtures/v4 v4.0.2-0.20200613231340-f56387b50c12/go.mod h1:m+ICp2rF3jDhFgEZ/8yziagdT1C+ZpZcrJjappBCDSw=
|
||||
github.com/go-git/go-git/v5 v5.2.0 h1:YPBLG/3UK1we1ohRkncLjaXWLW+HKp5QNM/jTli2JgI=
|
||||
github.com/go-git/go-git/v5 v5.2.0/go.mod h1:kh02eMX+wdqqxgNMEyq8YgwlIOsDOa9homkUq1PoTMs=
|
||||
github.com/google/go-cmp v0.3.0 h1:crn/baboCvb5fXaQ0IJ1SGTsTVrWpDsCWC8EGETZijY=
|
||||
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
|
||||
github.com/google/go-cmp v0.4.0 h1:xsAVV57WRhGj6kEIi8ReJzQlHHqcBYCElAvkovg3B/4=
|
||||
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/hako/durafmt v0.0.0-20191009132224-3f39dc1ed9f4 h1:60gBOooTSmNtrqNaRvrDbi8VAne0REaek2agjnITKSw=
|
||||
github.com/hako/durafmt v0.0.0-20191009132224-3f39dc1ed9f4/go.mod h1:5Scbynm8dF1XAPwIwkGPqzkM/shndPm79Jd1003hTjE=
|
||||
github.com/imdario/mergo v0.3.9 h1:UauaLniWCFHWd+Jp9oCEkTBj8VO/9DKg3PV3VCNMDIg=
|
||||
github.com/imdario/mergo v0.3.9/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA=
|
||||
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 h1:BQSFePA1RWJOlocH6Fxy8MmwDt+yVQYULKfN0RoTN8A=
|
||||
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99/go.mod h1:1lJo3i6rXxKeerYnT8Nvf0QmHCRC1n8sfWVwXF2Frvo=
|
||||
github.com/jessevdk/go-flags v1.4.0 h1:4IU2WS7AumrZ/40jfhf4QVDMsQwqA7VEHozFRrGARJA=
|
||||
github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
|
||||
github.com/kevinburke/ssh_config v0.0.0-20180830205328-81db2a75821e h1:RgQk53JHp/Cjunrr1WlsXSZpqXn+uREuHvUVcK82CV8=
|
||||
github.com/kevinburke/ssh_config v0.0.0-20180830205328-81db2a75821e/go.mod h1:CT57kijsi8u/K/BOFA39wgDQJ9CxiF4nAY/ojJ6r6mM=
|
||||
github.com/kevinburke/ssh_config v0.0.0-20190725054713-01f96b0aa0cd h1:Coekwdh0v2wtGp9Gmz1Ze3eVRAWJMLokvN3QjdzCHLY=
|
||||
github.com/kevinburke/ssh_config v0.0.0-20190725054713-01f96b0aa0cd/go.mod h1:CT57kijsi8u/K/BOFA39wgDQJ9CxiF4nAY/ojJ6r6mM=
|
||||
github.com/konsorten/go-windows-terminal-sequences v1.0.1 h1:mweAR1A6xJ3oS2pRaGiHgQ4OO8tzTaLawm8vnODuwDk=
|
||||
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
|
||||
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
|
||||
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
|
||||
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
||||
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
|
||||
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
|
||||
github.com/mattn/go-colorable v0.1.2 h1:/bC9yWikZXAL9uJdulbSfyVNIR3n3trXl+v8+1sx8mU=
|
||||
github.com/mattn/go-colorable v0.1.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
|
||||
github.com/mattn/go-isatty v0.0.8 h1:HLtExJ+uU2HOZ+wI0Tt5DtUDrx8yhUqDcp7fYERX4CE=
|
||||
github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
|
||||
github.com/mitchellh/go-homedir v1.0.0 h1:vKb8ShqSby24Yrqr/yDYkuFz8d0WUjys40rvnGC8aR0=
|
||||
github.com/mitchellh/go-homedir v1.0.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
|
||||
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
|
||||
github.com/onsi/ginkgo v1.8.0 h1:VkHVNpR4iVnU8XQR6DBm8BqYjN7CRzw+xKUbVVbbW9w=
|
||||
github.com/onsi/ginkgo v1.8.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
|
||||
github.com/onsi/gomega v1.5.0 h1:izbySO9zDPmjJ8rDjLvkA2zJHIo+HkYXHnf7eN7SSyo=
|
||||
github.com/onsi/gomega v1.5.0/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
|
||||
github.com/pelletier/go-buffruneio v0.2.0 h1:U4t4R6YkofJ5xHm3dJzuRpPZ0mr5MMCoAWooScCR7aA=
|
||||
github.com/pelletier/go-buffruneio v0.2.0/go.mod h1:JkE26KsDizTr40EUHkXVtNPvgGtbSNq5BcowyYOWdKo=
|
||||
github.com/pkg/errors v0.8.0 h1:WdK/asTD0HN+q6hsWO3/vpuAkAr+tw6aNJNDFFf0+qw=
|
||||
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
|
||||
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
|
||||
github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y=
|
||||
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
|
||||
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs=
|
||||
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
|
||||
github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
|
||||
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/sergi/go-diff v1.0.0 h1:Kpca3qRNrduNnOQeazBd0ysaKrUJiIuISHxogkT9RPQ=
|
||||
github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo=
|
||||
github.com/sirupsen/logrus v1.0.6 h1:hcP1GmhGigz/O7h1WVUM5KklBp1JoNS9FggWKdj/j3s=
|
||||
github.com/sirupsen/logrus v1.0.6/go.mod h1:pMByvHTf9Beacp5x1UXfOR9xyW/9antXMhjMPG0dEzc=
|
||||
github.com/src-d/gcfg v1.4.0 h1:xXbNR5AlLSA315x2UO+fTSSAXCDf+Ar38/6oyGbDKQ4=
|
||||
github.com/src-d/gcfg v1.4.0/go.mod h1:p/UMsR43ujA89BJY9duynAwIpvqEujIH/jFlfL7jWoI=
|
||||
github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w=
|
||||
github.com/sergi/go-diff v1.1.0 h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0=
|
||||
github.com/sergi/go-diff v1.1.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM=
|
||||
github.com/sirupsen/logrus v1.4.2 h1:SPIRibHv4MatM3XXNO2BJeFLZwZ2LvZgfQ5+UNI2im4=
|
||||
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
|
||||
github.com/xanzy/go-gitlab v0.11.3 h1:gSYcSb+pCx3fco6/O3w784/omQVTcrgxRzyf14SBvUQ=
|
||||
github.com/xanzy/go-gitlab v0.11.3/go.mod h1:CRKHkvFWNU6C3AEfqLWjnCNnAs4nj8Zk95rX2S3X6Mw=
|
||||
github.com/xanzy/ssh-agent v0.2.0 h1:Adglfbi5p9Z0BmK2oKU9nTG+zKfniSfnaMYB+ULd+Ro=
|
||||
github.com/xanzy/ssh-agent v0.2.0/go.mod h1:0NyE30eGUDliuLEHJgYte/zncp2zdTStcOnWhgSqHD8=
|
||||
golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
|
||||
golang.org/x/crypto v0.0.0-20180910181607-0e37d006457b h1:2b9XGzhjiYsYPnKXoEfL7klWZQIt8IfyRCz62gCqqlQ=
|
||||
golang.org/x/crypto v0.0.0-20180910181607-0e37d006457b/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2 h1:VklqNMn3ovrHsnt90PveolxSbWFaJdECFbxSq0Mqo2M=
|
||||
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
|
||||
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
|
||||
github.com/xanzy/ssh-agent v0.2.1 h1:TCbipTQL2JiiCprBWx9frJ2eJlCYT00NmctrHxVAr70=
|
||||
github.com/xanzy/ssh-agent v0.2.1/go.mod h1:mLlQY/MoOhWBj+gOGMQkOeiEvkx+8pJSI+0Bx9h2kr4=
|
||||
github.com/zricethezav/go-git/v5 v5.2.1 h1:snaoKv8ksDSz7NfBRXsBr9Yr8IKEKWRWf1zdhFmcFvI=
|
||||
github.com/zricethezav/go-git/v5 v5.2.1/go.mod h1:kh02eMX+wdqqxgNMEyq8YgwlIOsDOa9homkUq1PoTMs=
|
||||
github.com/zricethezav/go-git/v5 v5.2.2 h1:VOVijF5OpIiHvFZXX94AJezdJ0b0kTyRyVNZ4yaqCRU=
|
||||
github.com/zricethezav/go-git/v5 v5.2.2/go.mod h1:kh02eMX+wdqqxgNMEyq8YgwlIOsDOa9homkUq1PoTMs=
|
||||
golang.org/x/crypto v0.0.0-20190219172222-a4c6cb3142f2/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/lint v0.0.0-20190409202823-959b441ac422 h1:QzoH/1pFpZguR8NrRHLcO6jKqfv2zpuSqZLgdm7ZmjI=
|
||||
golang.org/x/lint v0.0.0-20190409202823-959b441ac422/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
|
||||
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20180925072008-f04abc6bdfa7 h1:zKzVgSQ8WOSHzD7I4k8LQjrHUUCNOlBsgc0PcYLVNnY=
|
||||
golang.org/x/net v0.0.0-20180925072008-f04abc6bdfa7/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20190311183353-d8887717615a h1:oWX7TPOiFAMXLq8o0ikBYfCJVlRHBcsciT5bXOrH628=
|
||||
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be h1:vEDujvNQGv4jgYKudGeI/+DAX4Jffq6hpD55MmoEvKs=
|
||||
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
|
||||
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6 h1:bjcUS9ztw9kFmmIxJInhon/0Is3p+EHBKNgquIzo1OI=
|
||||
golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sys v0.0.0-20180903190138-2b024373dcd9/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20180925112736-b09afc3d579e h1:LSlw/Dbj0MkNvPYAAkGinYmGliq+aqS7eKPYlE4oWC4=
|
||||
golang.org/x/sys v0.0.0-20180925112736-b09afc3d579e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/crypto v0.0.0-20200302210943-78000ba7a073 h1:xMPOj6Pz6UipU1wXLkrtqpHbR0AVFnyPEQq/wRWz9lM=
|
||||
golang.org/x/crypto v0.0.0-20200302210943-78000ba7a073/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
golang.org/x/net v0.0.0-20200301022130-244492dfa37a h1:GuSPYbZzB5/dcLNCwLQLsg3obCJtX9IJhpXkvY7kzk0=
|
||||
golang.org/x/net v0.0.0-20200301022130-244492dfa37a/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9 h1:SQFwaSi55rU7vdNs9Yr0Z324VNlrF+0wMqRXT4St8ck=
|
||||
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223 h1:DH4skfRX4EBpamg7iV4ZlCpblAHI6s6TDM39bFZumv8=
|
||||
golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
|
||||
golang.org/x/sys v0.0.0-20190221075227-b4e8571b14e0/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20190422165155-953cdadca894 h1:Cz4ceDQGXuKRnVBDTS23GTn/pU5OE2C0WrNTOYK1Uuc=
|
||||
golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200302150141-5c8b2ff67527 h1:uYVVQ9WP/Ds2ROhcaGPeIdVq0RIXVLwsHlnvJ+cT1So=
|
||||
golang.org/x/sys v0.0.0-20200302150141-5c8b2ff67527/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/tools v0.0.0-20190311212946-11955173bddd h1:/e+gpKk9r3dJobndpTytxS2gOy6m5uvpg+ISQoEcusQ=
|
||||
golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
|
||||
google.golang.org/appengine v1.2.0 h1:S0iUepdCWODXRvtE+gcRDd15L+k+k1AiHlMiMjefH24=
|
||||
google.golang.org/appengine v1.2.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
|
||||
gopkg.in/airbrake/gobrake.v2 v2.0.9 h1:7z2uVWwn7oVeeugY1DtlPAy5H+KYgB1KeKTnqjNatLo=
|
||||
gopkg.in/airbrake/gobrake.v2 v2.0.9/go.mod h1:/h5ZAUhDkGaJfjzjKLSjv6zCL6O0LLBxU4K+aSYdM/U=
|
||||
golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs=
|
||||
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
|
||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
|
||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
|
||||
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/fsnotify.v1 v1.4.7 h1:xOHLXZwVvI9hhs+cLKq5+I5onOuwQLhQwiu63xxlHs4=
|
||||
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
|
||||
gopkg.in/gemnasium/logrus-airbrake-hook.v2 v2.1.2 h1:OAj3g0cR6Dx/R07QgQe8wkA9RNjB2u4i700xBkIT4e0=
|
||||
gopkg.in/gemnasium/logrus-airbrake-hook.v2 v2.1.2/go.mod h1:Xk6kEKp8OKb+X14hQBKWaSkCsqBpgog8nAV2xsGOxlo=
|
||||
gopkg.in/src-d/go-billy.v4 v4.2.1/go.mod h1:tm33zBoOwxjYHZIE+OV8bxTWFMJLrconzFMd38aARFk=
|
||||
gopkg.in/src-d/go-billy.v4 v4.3.0 h1:KtlZ4c1OWbIs4jCv5ZXrTqG8EQocr0g/d4DjNg70aek=
|
||||
gopkg.in/src-d/go-billy.v4 v4.3.0/go.mod h1:tm33zBoOwxjYHZIE+OV8bxTWFMJLrconzFMd38aARFk=
|
||||
gopkg.in/src-d/go-git-fixtures.v3 v3.1.1 h1:XWW/s5W18RaJpmo1l0IYGqXKuJITWRFuA45iOf1dKJs=
|
||||
gopkg.in/src-d/go-git-fixtures.v3 v3.1.1/go.mod h1:dLBcvytrw/TYZsNTWCnkNF2DSIlzWYqTe3rJR56Ac7g=
|
||||
gopkg.in/src-d/go-git.v4 v4.9.1 h1:0oKHJZY8tM7B71378cfTg2c5jmWyNlXvestTT6WfY+4=
|
||||
gopkg.in/src-d/go-git.v4 v4.9.1/go.mod h1:Vtut8izDyrM8BUVQnzJ+YvmNcem2J89EmfZYCkLokZk=
|
||||
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ=
|
||||
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
|
||||
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo=
|
||||
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f h1:BLraFXnmrev5lT+xlilqcH8XK9/i0At2xKjWk4p6zsU=
|
||||
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/warnings.v0 v0.1.2 h1:wFXVbFY8DY5/xOe1ECiWdKCzZlxgshcYVNkBHstARME=
|
||||
gopkg.in/warnings.v0 v0.1.2/go.mod h1:jksf8JmL6Qr/oQM2OXTHunEvvTAsrWBLb6OOjuVWRNI=
|
||||
gopkg.in/yaml.v2 v2.2.1 h1:mUhvW9EsL+naU5Q3cakzfE91YhliOondGd6ZrsDBHQE=
|
||||
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
|
||||
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v2 v2.2.4 h1:/eiJrUcujPVeJ3xlSWaiNi3uSVmDGBK1pDHUHAnao1I=
|
||||
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10=
|
||||
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
@@ -2,26 +2,73 @@ package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
"strings"
|
||||
"os/signal"
|
||||
"time"
|
||||
|
||||
"github.com/zricethezav/gitleaks/v7/config"
|
||||
"github.com/zricethezav/gitleaks/v7/options"
|
||||
"github.com/zricethezav/gitleaks/v7/scan"
|
||||
|
||||
"github.com/hako/durafmt"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"github.com/zricethezav/gitleaks/src"
|
||||
)
|
||||
|
||||
func main() {
|
||||
leakCount, err := gitleaks.Run(gitleaks.ParseOpts())
|
||||
// this block sets up a go routine to listen for an interrupt signal
|
||||
// which will immediately exit gitleaks
|
||||
stopChan := make(chan os.Signal, 1)
|
||||
signal.Notify(stopChan, os.Interrupt)
|
||||
go listenForInterrupt(stopChan)
|
||||
|
||||
// setup options
|
||||
opts, err := options.ParseOptions()
|
||||
if err != nil {
|
||||
if strings.Contains(err.Error(), "whitelisted") {
|
||||
log.Info(err.Error())
|
||||
os.Exit(0)
|
||||
}
|
||||
log.Error(err)
|
||||
os.Exit(gitleaks.ErrExit)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
if leakCount == 0 {
|
||||
os.Exit(gitleaks.NoLeaks)
|
||||
} else {
|
||||
os.Exit(gitleaks.LeakExit)
|
||||
err = opts.Guard()
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
// setup configs
|
||||
cfg, err := config.NewConfig(opts)
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
// setup scanner
|
||||
scanner, err := scan.NewScanner(opts, cfg)
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
// run and time the scan
|
||||
start := time.Now()
|
||||
scannerReport, err := scanner.Scan()
|
||||
log.Info("scan time: ", durafmt.Parse(time.Now().Sub(start)))
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
// report scan
|
||||
if err := scan.WriteReport(scannerReport, opts, cfg); err != nil {
|
||||
log.Error(err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
if len(scannerReport.Leaks) != 0 {
|
||||
os.Exit(opts.CodeOnLeak)
|
||||
}
|
||||
}
|
||||
|
||||
func listenForInterrupt(stopScan chan os.Signal) {
|
||||
<-stopScan
|
||||
log.Warn("halting gitleaks scan")
|
||||
os.Exit(1)
|
||||
}
|
||||
@@ -0,0 +1,216 @@
|
||||
package options
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"os/user"
|
||||
"strings"
|
||||
|
||||
"github.com/zricethezav/gitleaks/v7/version"
|
||||
|
||||
"github.com/go-git/go-git/v5"
|
||||
"github.com/go-git/go-git/v5/plumbing"
|
||||
"github.com/go-git/go-git/v5/plumbing/transport"
|
||||
"github.com/go-git/go-git/v5/plumbing/transport/http"
|
||||
"github.com/go-git/go-git/v5/plumbing/transport/ssh"
|
||||
"github.com/jessevdk/go-flags"
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
// Options stores values of command line options
|
||||
type Options struct {
|
||||
Verbose bool `short:"v" long:"verbose" description:"Show verbose output from scan"`
|
||||
Quiet bool `short:"q" long:"quiet" description:"Sets log level to error and only output leaks, one json object per line"`
|
||||
RepoURL string `short:"r" long:"repo-url" description:"Repository URL"`
|
||||
Path string `short:"p" long:"path" description:"Path to directory (repo if contains .git) or file"`
|
||||
ConfigPath string `short:"c" long:"config-path" description:"Path to config"`
|
||||
RepoConfigPath string `long:"repo-config-path" description:"Path to gitleaks config relative to repo root"`
|
||||
ClonePath string `long:"clone-path" description:"Path to clone repo to disk"`
|
||||
Version bool `long:"version" description:"Version number"`
|
||||
Username string `long:"username" description:"Username for git repo"`
|
||||
Password string `long:"password" description:"Password for git repo"`
|
||||
AccessToken string `long:"access-token" description:"Access token for git repo"`
|
||||
Threads int `long:"threads" description:"Maximum number of threads gitleaks spawns"`
|
||||
SSH string `long:"ssh-key" description:"Path to ssh key used for auth"`
|
||||
Unstaged bool `long:"unstaged" description:"Run gitleaks on unstaged code"`
|
||||
Branch string `long:"branch" description:"Branch to scan"`
|
||||
Redact bool `long:"redact" description:"Redact secrets from log messages and leaks"`
|
||||
Debug bool `long:"debug" description:"Log debug messages"`
|
||||
NoGit bool `long:"no-git" description:"Treat git repos as plain directories and scan those files"`
|
||||
CodeOnLeak int `long:"leaks-exit-code" default:"1" description:"Exit code when leaks have been encountered"`
|
||||
|
||||
// Report Options
|
||||
Report string `short:"o" long:"report" description:"Report output path"`
|
||||
ReportFormat string `short:"f" long:"format" default:"json" description:"JSON, CSV, SARIF"`
|
||||
|
||||
// Commit Options
|
||||
FilesAtCommit string `long:"files-at-commit" description:"Sha of commit to scan all files at commit"`
|
||||
Commit string `long:"commit" description:"Sha of commit to scan or \"latest\" to scan the last commit of the repository"`
|
||||
Commits string `long:"commits" description:"Comma separated list of a commits to scan"`
|
||||
CommitsFile string `long:"commits-file" description:"Path to file of line separated list of commits to scan"`
|
||||
CommitFrom string `long:"commit-from" description:"Commit to start scan from"`
|
||||
CommitTo string `long:"commit-to" description:"Commit to stop scan"`
|
||||
CommitSince string `long:"commit-since" description:"Scan commits more recent than a specific date. Ex: '2006-01-02' or '2006-01-02T15:04:05-0700' format."`
|
||||
CommitUntil string `long:"commit-until" description:"Scan commits older than a specific date. Ex: '2006-01-02' or '2006-01-02T15:04:05-0700' format."`
|
||||
Depth int `long:"depth" description:"Number of commits to scan"`
|
||||
}
|
||||
|
||||
// ParseOptions is responsible for parsing options passed in by cli. An Options struct
|
||||
// is returned if successful. This struct is passed around the program
|
||||
// and will determine how the program executes. If err, an err message or help message
|
||||
// will be displayed and the program will exit with code 0.
|
||||
func ParseOptions() (Options, error) {
|
||||
var opts Options
|
||||
parser := flags.NewParser(&opts, flags.Default)
|
||||
_, err := parser.Parse()
|
||||
|
||||
if err != nil {
|
||||
if flagsErr, ok := err.(*flags.Error); ok && flagsErr.Type != flags.ErrHelp {
|
||||
parser.WriteHelp(os.Stdout)
|
||||
}
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
if opts.Version {
|
||||
if version.Version == "" {
|
||||
fmt.Println("Gitleaks uses LDFLAGS to pull most recent version. Build with 'make build' for version")
|
||||
} else {
|
||||
fmt.Printf("%s\n", version.Version)
|
||||
}
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
if opts.Debug {
|
||||
log.SetLevel(log.DebugLevel)
|
||||
}
|
||||
if opts.Quiet {
|
||||
log.SetLevel(log.ErrorLevel)
|
||||
}
|
||||
|
||||
return opts, nil
|
||||
}
|
||||
|
||||
// Guard checks to makes sure there are no invalid options set.
|
||||
// If invalid sets of options are present, a descriptive error will return
|
||||
// else nil is returned
|
||||
func (opts Options) Guard() error {
|
||||
if !oneOrNoneSet(opts.RepoURL, opts.Path) {
|
||||
return fmt.Errorf("only one target option must can be set. target options: repo, owner-path, repo-path, host")
|
||||
}
|
||||
if !oneOrNoneSet(opts.AccessToken, opts.Password) {
|
||||
log.Warn("both access-token and password are set. Only password will be attempted")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func oneOrNoneSet(optStr ...string) bool {
|
||||
c := 0
|
||||
for _, s := range optStr {
|
||||
if s != "" {
|
||||
c++
|
||||
}
|
||||
}
|
||||
if c <= 1 {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// CloneOptions returns a git.cloneOptions pointer. The authentication method
|
||||
// is determined by what is passed in via command-Line options. If No
|
||||
// Username/PW or AccessToken is available and the repo target is not using the
|
||||
// git protocol then the repo must be a available via no auth.
|
||||
func (opts Options) CloneOptions() (*git.CloneOptions, error) {
|
||||
var err error
|
||||
progress := ioutil.Discard
|
||||
if opts.Verbose {
|
||||
progress = os.Stdout
|
||||
}
|
||||
|
||||
cloneOpts := &git.CloneOptions{
|
||||
URL: opts.RepoURL,
|
||||
Progress: progress,
|
||||
}
|
||||
if opts.Depth != 0 {
|
||||
cloneOpts.Depth = opts.Depth
|
||||
}
|
||||
if opts.Branch != "" {
|
||||
cloneOpts.ReferenceName = plumbing.NewBranchReferenceName(opts.Branch)
|
||||
}
|
||||
|
||||
var auth transport.AuthMethod
|
||||
|
||||
if strings.HasPrefix(opts.RepoURL, "git") {
|
||||
// using git protocol so needs ssh auth
|
||||
auth, err = SSHAuth(opts)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
} else if opts.Password != "" && opts.Username != "" {
|
||||
// auth using username and password
|
||||
auth = &http.BasicAuth{
|
||||
Username: opts.Username,
|
||||
Password: opts.Password,
|
||||
}
|
||||
} else if opts.AccessToken != "" {
|
||||
auth = &http.BasicAuth{
|
||||
Username: "gitleaks_user",
|
||||
Password: opts.AccessToken,
|
||||
}
|
||||
} else if os.Getenv("GITLEAKS_ACCESS_TOKEN") != "" {
|
||||
auth = &http.BasicAuth{
|
||||
Username: "gitleaks_user",
|
||||
Password: os.Getenv("GITLEAKS_ACCESS_TOKEN"),
|
||||
}
|
||||
}
|
||||
if auth != nil {
|
||||
cloneOpts.Auth = auth
|
||||
}
|
||||
return cloneOpts, nil
|
||||
}
|
||||
|
||||
// SSHAuth tried to generate ssh public keys based on what was passed via cli. If no
|
||||
// path was passed via cli then this will attempt to retrieve keys from the default
|
||||
// location for ssh keys, $HOME/.ssh/id_rsa. This function is only called if the
|
||||
// repo url using the git:// protocol.
|
||||
func SSHAuth(opts Options) (*ssh.PublicKeys, error) {
|
||||
if opts.SSH != "" {
|
||||
return ssh.NewPublicKeysFromFile("git", opts.SSH, "")
|
||||
}
|
||||
c, err := user.Current()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defaultPath := fmt.Sprintf("%s/.ssh/id_rsa", c.HomeDir)
|
||||
return ssh.NewPublicKeysFromFile("git", defaultPath, "")
|
||||
}
|
||||
|
||||
// OpenLocal checks what options are set, if no remote targets are set
|
||||
// then return true
|
||||
func (opts Options) OpenLocal() bool {
|
||||
if opts.Unstaged || opts.Path != "" || opts.RepoURL == "" {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// CheckUncommitted returns a boolean that indicates whether or not gitleaks should check unstaged pre-commit changes
|
||||
// or if gitleaks should check the entire git history
|
||||
func (opts Options) CheckUncommitted() bool {
|
||||
// check to make sure no remote shit is set
|
||||
if opts.Unstaged {
|
||||
return true
|
||||
}
|
||||
if opts == (Options{}) {
|
||||
return true
|
||||
}
|
||||
if opts.RepoURL != "" {
|
||||
return false
|
||||
}
|
||||
if opts.Path != "" {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
package options
|
||||
+150
@@ -0,0 +1,150 @@
|
||||
package scan
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/zricethezav/gitleaks/v7/config"
|
||||
"github.com/zricethezav/gitleaks/v7/options"
|
||||
|
||||
"github.com/go-git/go-git/v5"
|
||||
fdiff "github.com/go-git/go-git/v5/plumbing/format/diff"
|
||||
"github.com/go-git/go-git/v5/plumbing/object"
|
||||
)
|
||||
|
||||
// CommitScanner is a commit scanner
|
||||
type CommitScanner struct {
|
||||
cfg config.Config
|
||||
opts options.Options
|
||||
repo *git.Repository
|
||||
repoName string
|
||||
commit *object.Commit
|
||||
}
|
||||
|
||||
// NewCommitScanner creates and returns a commit scanner
|
||||
func NewCommitScanner(opts options.Options, cfg config.Config, repo *git.Repository, commit *object.Commit) *CommitScanner {
|
||||
cs := &CommitScanner{
|
||||
cfg: cfg,
|
||||
opts: opts,
|
||||
repo: repo,
|
||||
commit: commit,
|
||||
repoName: getRepoName(opts),
|
||||
}
|
||||
return cs
|
||||
}
|
||||
|
||||
// SetRepoName sets the repo name of the scanner.
|
||||
func (cs *CommitScanner) SetRepoName(repoName string) {
|
||||
cs.repoName = repoName
|
||||
}
|
||||
|
||||
// Scan kicks off a CommitScanner Scan
|
||||
func (cs *CommitScanner) Scan() (Report, error) {
|
||||
var scannerReport Report
|
||||
|
||||
if cs.cfg.Allowlist.CommitAllowed(cs.commit.Hash.String()) {
|
||||
return scannerReport, nil
|
||||
}
|
||||
|
||||
if len(cs.commit.ParentHashes) == 0 {
|
||||
facScanner := NewFilesAtCommitScanner(cs.opts, cs.cfg, cs.repo, cs.commit)
|
||||
return facScanner.Scan()
|
||||
}
|
||||
|
||||
parent, err := cs.commit.Parent(0)
|
||||
if err != nil {
|
||||
return scannerReport, err
|
||||
}
|
||||
|
||||
if parent == nil {
|
||||
return scannerReport, nil
|
||||
}
|
||||
|
||||
patch, err := parent.Patch(cs.commit)
|
||||
if err != nil {
|
||||
return scannerReport, fmt.Errorf("could not generate Patch")
|
||||
}
|
||||
|
||||
patchContent := patch.String()
|
||||
|
||||
for _, f := range patch.FilePatches() {
|
||||
if f.IsBinary() {
|
||||
continue
|
||||
}
|
||||
for _, chunk := range f.Chunks() {
|
||||
if chunk.Type() == fdiff.Add {
|
||||
_, to := f.Files()
|
||||
if cs.cfg.Allowlist.FileAllowed(filepath.Base(to.Path())) ||
|
||||
cs.cfg.Allowlist.PathAllowed(to.Path()) {
|
||||
continue
|
||||
}
|
||||
|
||||
// Check individual file path ONLY rules
|
||||
for _, rule := range cs.cfg.Rules {
|
||||
if rule.CommitAllowed(cs.commit.Hash.String()) {
|
||||
continue
|
||||
}
|
||||
|
||||
if rule.HasFileOrPathLeakOnly(to.Path()) {
|
||||
leak := NewLeak("", "Filename or path offender: "+to.Path(), defaultLineNumber).WithCommit(cs.commit)
|
||||
leak.Repo = cs.repoName
|
||||
leak.File = to.Path()
|
||||
leak.RepoURL = cs.opts.RepoURL
|
||||
leak.LeakURL = leak.URL()
|
||||
leak.Rule = rule.Description
|
||||
leak.Tags = strings.Join(rule.Tags, ", ")
|
||||
|
||||
leak.Log(cs.opts)
|
||||
|
||||
scannerReport.Leaks = append(scannerReport.Leaks, leak)
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
lineLookup := make(map[string]bool)
|
||||
|
||||
// Check the actual content
|
||||
for _, line := range strings.Split(chunk.Content(), "\n") {
|
||||
for _, rule := range cs.cfg.Rules {
|
||||
if rule.AllowList.FileAllowed(filepath.Base(to.Path())) ||
|
||||
rule.AllowList.PathAllowed(to.Path()) ||
|
||||
rule.AllowList.CommitAllowed(cs.commit.Hash.String()) {
|
||||
continue
|
||||
}
|
||||
offender := rule.Inspect(line)
|
||||
if offender == "" {
|
||||
continue
|
||||
}
|
||||
|
||||
if cs.cfg.Allowlist.RegexAllowed(line) {
|
||||
continue
|
||||
}
|
||||
|
||||
if rule.File.String() != "" && !rule.HasFileLeak(filepath.Base(to.Path())) {
|
||||
continue
|
||||
}
|
||||
if rule.Path.String() != "" && !rule.HasFilePathLeak(to.Path()) {
|
||||
continue
|
||||
}
|
||||
|
||||
leak := NewLeak(line, offender, defaultLineNumber).WithCommit(cs.commit)
|
||||
leak.File = to.Path()
|
||||
leak.LineNumber = extractLine(patchContent, leak, lineLookup)
|
||||
leak.RepoURL = cs.opts.RepoURL
|
||||
leak.Repo = cs.repoName
|
||||
leak.LeakURL = leak.URL()
|
||||
leak.Rule = rule.Description
|
||||
leak.Tags = strings.Join(rule.Tags, ", ")
|
||||
|
||||
leak.Log(cs.opts)
|
||||
|
||||
scannerReport.Leaks = append(scannerReport.Leaks, leak)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
scannerReport.Commits = 1
|
||||
return scannerReport, nil
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
package scan
|
||||
|
||||
import (
|
||||
"github.com/go-git/go-git/v5"
|
||||
"github.com/zricethezav/gitleaks/v7/config"
|
||||
"github.com/zricethezav/gitleaks/v7/options"
|
||||
)
|
||||
|
||||
// CommitsScanner is a commit scanner
|
||||
type CommitsScanner struct {
|
||||
opts options.Options
|
||||
cfg config.Config
|
||||
|
||||
repo *git.Repository
|
||||
repoName string
|
||||
commits []string
|
||||
}
|
||||
|
||||
// NewCommitsScanner creates and returns a commits scanner, notice the 's' in commits
|
||||
func NewCommitsScanner(opts options.Options, cfg config.Config, repo *git.Repository, commits []string) *CommitsScanner {
|
||||
return &CommitsScanner{
|
||||
opts: opts,
|
||||
cfg: cfg,
|
||||
repo: repo,
|
||||
commits: commits,
|
||||
repoName: getRepoName(opts),
|
||||
}
|
||||
}
|
||||
|
||||
// Scan kicks off a CommitsScanner Scan
|
||||
func (css *CommitsScanner) Scan() (Report, error) {
|
||||
var scannerReport Report
|
||||
for _, c := range css.commits {
|
||||
c, err := obtainCommit(css.repo, c)
|
||||
if err != nil {
|
||||
return scannerReport, nil
|
||||
}
|
||||
cs := NewCommitScanner(css.opts, css.cfg, css.repo, c)
|
||||
commitReport, err := cs.Scan()
|
||||
if err != nil {
|
||||
return scannerReport, err
|
||||
}
|
||||
scannerReport.Leaks = append(scannerReport.Leaks, commitReport.Leaks...)
|
||||
scannerReport.Commits++
|
||||
}
|
||||
return scannerReport, nil
|
||||
}
|
||||
@@ -0,0 +1,136 @@
|
||||
package scan
|
||||
|
||||
import (
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/zricethezav/gitleaks/v7/config"
|
||||
"github.com/zricethezav/gitleaks/v7/options"
|
||||
|
||||
"github.com/go-git/go-git/v5"
|
||||
"github.com/go-git/go-git/v5/plumbing/object"
|
||||
)
|
||||
|
||||
// FilesAtCommitScanner is a files at commit scanner. This differs from CommitScanner
|
||||
// as CommitScanner generates patches that are scanned. FilesAtCommitScanner instead looks at
|
||||
// files available at a commit's worktree and scans the entire content of said files.
|
||||
// Apologies for the awful struct name...
|
||||
type FilesAtCommitScanner struct {
|
||||
opts options.Options
|
||||
cfg config.Config
|
||||
repo *git.Repository
|
||||
commit *object.Commit
|
||||
repoName string
|
||||
}
|
||||
|
||||
// NewFilesAtCommitScanner creates and returns a files at commit scanner
|
||||
func NewFilesAtCommitScanner(opts options.Options, cfg config.Config, repo *git.Repository, commit *object.Commit) *FilesAtCommitScanner {
|
||||
fs := &FilesAtCommitScanner{
|
||||
opts: opts,
|
||||
cfg: cfg,
|
||||
repo: repo,
|
||||
commit: commit,
|
||||
repoName: getRepoName(opts),
|
||||
}
|
||||
return fs
|
||||
}
|
||||
|
||||
// Scan kicks off a FilesAtCommitScanner Scan
|
||||
func (fs *FilesAtCommitScanner) Scan() (Report, error) {
|
||||
var scannerReport Report
|
||||
|
||||
if fs.cfg.Allowlist.CommitAllowed(fs.commit.Hash.String()) {
|
||||
return scannerReport, nil
|
||||
}
|
||||
|
||||
fIter, err := fs.commit.Files()
|
||||
if err != nil {
|
||||
return scannerReport, err
|
||||
}
|
||||
|
||||
err = fIter.ForEach(func(f *object.File) error {
|
||||
bin, err := f.IsBinary()
|
||||
if bin {
|
||||
return nil
|
||||
} else if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if fs.cfg.Allowlist.FileAllowed(filepath.Base(f.Name)) ||
|
||||
fs.cfg.Allowlist.PathAllowed(f.Name) {
|
||||
return nil
|
||||
}
|
||||
|
||||
content, err := f.Contents()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Check individual file path ONLY rules
|
||||
for _, rule := range fs.cfg.Rules {
|
||||
if rule.CommitAllowed(fs.commit.Hash.String()) {
|
||||
continue
|
||||
}
|
||||
|
||||
if rule.HasFileOrPathLeakOnly(f.Name) {
|
||||
leak := NewLeak("", "Filename or path offender: "+f.Name, defaultLineNumber).WithCommit(fs.commit)
|
||||
leak.Repo = fs.repoName
|
||||
leak.File = f.Name
|
||||
leak.RepoURL = fs.opts.RepoURL
|
||||
leak.LeakURL = leak.URL()
|
||||
leak.Rule = rule.Description
|
||||
leak.Tags = strings.Join(rule.Tags, ", ")
|
||||
|
||||
leak.Log(fs.opts)
|
||||
|
||||
scannerReport.Leaks = append(scannerReport.Leaks, leak)
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
for i, line := range strings.Split(content, "\n") {
|
||||
for _, rule := range fs.cfg.Rules {
|
||||
if rule.AllowList.FileAllowed(filepath.Base(f.Name)) ||
|
||||
rule.AllowList.PathAllowed(f.Name) ||
|
||||
rule.AllowList.CommitAllowed(fs.commit.Hash.String()) {
|
||||
continue
|
||||
}
|
||||
|
||||
offender := rule.Inspect(line)
|
||||
|
||||
if offender == "" {
|
||||
continue
|
||||
}
|
||||
|
||||
if fs.cfg.Allowlist.RegexAllowed(line) {
|
||||
continue
|
||||
}
|
||||
|
||||
if rule.File.String() != "" && !rule.HasFileLeak(filepath.Base(f.Name)) {
|
||||
continue
|
||||
}
|
||||
if rule.Path.String() != "" && !rule.HasFilePathLeak(f.Name) {
|
||||
continue
|
||||
}
|
||||
|
||||
leak := NewLeak(line, offender, defaultLineNumber).WithCommit(fs.commit)
|
||||
leak.File = f.Name
|
||||
leak.LineNumber = i + 1
|
||||
leak.RepoURL = fs.opts.RepoURL
|
||||
leak.Repo = fs.repoName
|
||||
leak.LeakURL = leak.URL()
|
||||
leak.Rule = rule.Description
|
||||
leak.Tags = strings.Join(rule.Tags, ", ")
|
||||
|
||||
leak.Log(fs.opts)
|
||||
|
||||
scannerReport.Leaks = append(scannerReport.Leaks, leak)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
})
|
||||
|
||||
scannerReport.Commits = 1
|
||||
return scannerReport, err
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
package scan
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/zricethezav/gitleaks/v7/options"
|
||||
|
||||
"github.com/go-git/go-git/v5/plumbing/object"
|
||||
)
|
||||
|
||||
// Leak is a struct that contains information about some line of code that contains
|
||||
// sensitive information as determined by the rules set in a gitleaks config
|
||||
type Leak struct {
|
||||
Line string `json:"line"`
|
||||
LineNumber int `json:"lineNumber"`
|
||||
Offender string `json:"offender"`
|
||||
Commit string `json:"commit"`
|
||||
Repo string `json:"repo"`
|
||||
RepoURL string `json:"repoURL"`
|
||||
LeakURL string `json:"leakURL"`
|
||||
Rule string `json:"rule"`
|
||||
Message string `json:"commitMessage"`
|
||||
Author string `json:"author"`
|
||||
Email string `json:"email"`
|
||||
File string `json:"file"`
|
||||
Date time.Time `json:"date"`
|
||||
Tags string `json:"tags"`
|
||||
}
|
||||
|
||||
// RedactLeak will replace the offending string with "REDACTED" in both
|
||||
// the offender and line field of the leak which.
|
||||
func RedactLeak(leak Leak) Leak {
|
||||
leak.Line = strings.Replace(leak.Line, leak.Offender, "REDACTED", -1)
|
||||
leak.Offender = "REDACTED"
|
||||
return leak
|
||||
}
|
||||
|
||||
// NewLeak creates a new leak from common data all leaks must have, line, offender, linenumber
|
||||
func NewLeak(line string, offender string, lineNumber int) Leak {
|
||||
return Leak{
|
||||
Line: line,
|
||||
Offender: offender,
|
||||
LineNumber: lineNumber,
|
||||
}
|
||||
}
|
||||
|
||||
// WithCommit adds commit data to the leak
|
||||
func (leak Leak) WithCommit(commit *object.Commit) Leak {
|
||||
leak.Commit = commit.Hash.String()
|
||||
leak.Author = commit.Author.Name
|
||||
leak.Email = commit.Author.Email
|
||||
leak.Message = commit.Message
|
||||
leak.Date = commit.Author.When
|
||||
return leak
|
||||
}
|
||||
|
||||
// Log logs a leak and redacts if necessary
|
||||
func (leak Leak) Log(opts options.Options) {
|
||||
if !opts.Quiet && !opts.Verbose {
|
||||
return
|
||||
}
|
||||
if opts.Redact {
|
||||
leak = RedactLeak(leak)
|
||||
}
|
||||
if opts.Quiet {
|
||||
var b []byte
|
||||
b, _ = json.Marshal(leak)
|
||||
fmt.Println(string(b))
|
||||
} else {
|
||||
var b []byte
|
||||
b, _ = json.MarshalIndent(leak, "", " ")
|
||||
fmt.Println(string(b))
|
||||
}
|
||||
}
|
||||
|
||||
// URL generates a url to the leak if leak.RepoURL is set
|
||||
func (leak Leak) URL() string {
|
||||
if leak.RepoURL != "" {
|
||||
return fmt.Sprintf("%s/blob/%s/%s#L%d", leak.RepoURL, leak.Commit, leak.File, leak.LineNumber)
|
||||
}
|
||||
return ""
|
||||
}
|
||||
+154
@@ -0,0 +1,154 @@
|
||||
package scan
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"context"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
|
||||
"github.com/zricethezav/gitleaks/v7/config"
|
||||
"github.com/zricethezav/gitleaks/v7/options"
|
||||
|
||||
"golang.org/x/sync/errgroup"
|
||||
)
|
||||
|
||||
// NoGitScanner is a scanner that absolutely despises git
|
||||
type NoGitScanner struct {
|
||||
opts options.Options
|
||||
cfg config.Config
|
||||
}
|
||||
|
||||
// NewNoGitScanner creates and returns a nogit scanner. This is used for scanning files and directories
|
||||
func NewNoGitScanner(opts options.Options, cfg config.Config) *NoGitScanner {
|
||||
ngs := &NoGitScanner{
|
||||
opts: opts,
|
||||
cfg: cfg,
|
||||
}
|
||||
|
||||
// no-git scans should ignore .git folders by default
|
||||
// issue: https://github.com/zricethezav/gitleaks/issues/474
|
||||
// ngs.cfg.Allowlist
|
||||
err := ngs.cfg.Allowlist.IgnoreDotGit()
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
return nil
|
||||
}
|
||||
return ngs
|
||||
}
|
||||
|
||||
// Scan kicks off a NoGitScanner Scan
|
||||
func (ngs *NoGitScanner) Scan() (Report, error) {
|
||||
var scannerReport Report
|
||||
|
||||
g, _ := errgroup.WithContext(context.Background())
|
||||
paths := make(chan string, 100)
|
||||
|
||||
g.Go(func() error {
|
||||
defer close(paths)
|
||||
return filepath.Walk(ngs.opts.Path,
|
||||
func(path string, fInfo os.FileInfo, err error) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if fInfo.Mode().IsRegular() {
|
||||
paths <- path
|
||||
}
|
||||
return nil
|
||||
})
|
||||
})
|
||||
|
||||
leaks := make(chan Leak, 100)
|
||||
|
||||
for path := range paths {
|
||||
p := path
|
||||
g.Go(func() error {
|
||||
if ngs.cfg.Allowlist.FileAllowed(filepath.Base(p)) ||
|
||||
ngs.cfg.Allowlist.PathAllowed(p) {
|
||||
return nil
|
||||
}
|
||||
|
||||
for _, rule := range ngs.cfg.Rules {
|
||||
if rule.HasFileOrPathLeakOnly(p) {
|
||||
leak := NewLeak("", "Filename or path offender: "+p, defaultLineNumber)
|
||||
relPath, err := filepath.Rel(ngs.opts.Path, p)
|
||||
if err != nil {
|
||||
leak.File = p
|
||||
} else {
|
||||
leak.File = relPath
|
||||
}
|
||||
leak.Rule = rule.Description
|
||||
leak.Tags = strings.Join(rule.Tags, ", ")
|
||||
|
||||
leak.Log(ngs.opts)
|
||||
|
||||
leaks <- leak
|
||||
}
|
||||
}
|
||||
|
||||
f, err := os.Open(p) // #nosec
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
scanner := bufio.NewScanner(f)
|
||||
lineNumber := 0
|
||||
for scanner.Scan() {
|
||||
lineNumber++
|
||||
for _, rule := range ngs.cfg.Rules {
|
||||
line := scanner.Text()
|
||||
|
||||
if rule.AllowList.FileAllowed(filepath.Base(p)) ||
|
||||
rule.AllowList.PathAllowed(p) {
|
||||
continue
|
||||
}
|
||||
|
||||
offender := rule.Inspect(line)
|
||||
if offender == "" {
|
||||
continue
|
||||
}
|
||||
if ngs.cfg.Allowlist.RegexAllowed(line) {
|
||||
continue
|
||||
}
|
||||
|
||||
if rule.File.String() != "" && !rule.HasFileLeak(filepath.Base(p)) {
|
||||
continue
|
||||
}
|
||||
if rule.Path.String() != "" && !rule.HasFilePathLeak(p) {
|
||||
continue
|
||||
}
|
||||
|
||||
leak := NewLeak(line, offender, defaultLineNumber)
|
||||
relPath, err := filepath.Rel(ngs.opts.Path, p)
|
||||
if err != nil {
|
||||
leak.File = p
|
||||
} else {
|
||||
leak.File = relPath
|
||||
}
|
||||
leak.LineNumber = lineNumber
|
||||
leak.Rule = rule.Description
|
||||
leak.Tags = strings.Join(rule.Tags, ", ")
|
||||
|
||||
leak.Log(ngs.opts)
|
||||
|
||||
leaks <- leak
|
||||
}
|
||||
}
|
||||
return f.Close()
|
||||
})
|
||||
}
|
||||
|
||||
go func() {
|
||||
if err := g.Wait(); err != nil {
|
||||
log.Error(err)
|
||||
}
|
||||
close(leaks)
|
||||
}()
|
||||
|
||||
for leak := range leaks {
|
||||
scannerReport.Leaks = append(scannerReport.Leaks, leak)
|
||||
}
|
||||
|
||||
return scannerReport, g.Wait()
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
package scan
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/zricethezav/gitleaks/v7/options"
|
||||
|
||||
"github.com/zricethezav/gitleaks/v7/config"
|
||||
|
||||
"github.com/go-git/go-git/v5"
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
// ParentScanner is a parent directory scanner
|
||||
type ParentScanner struct {
|
||||
cfg config.Config
|
||||
opts options.Options
|
||||
}
|
||||
|
||||
// NewParentScanner creates and returns a directory scanner
|
||||
func NewParentScanner(opts options.Options, cfg config.Config) *ParentScanner {
|
||||
ds := &ParentScanner{
|
||||
opts: opts,
|
||||
cfg: cfg,
|
||||
}
|
||||
return ds
|
||||
}
|
||||
|
||||
// Scan kicks off a ParentScanner scan. This uses the directory from --path to discovery repos
|
||||
func (ds *ParentScanner) Scan() (Report, error) {
|
||||
var scannerReport Report
|
||||
log.Debugf("scanning repos in %s\n", ds.opts.Path)
|
||||
|
||||
files, err := ioutil.ReadDir(ds.opts.Path)
|
||||
if err != nil {
|
||||
return scannerReport, err
|
||||
}
|
||||
for _, f := range files {
|
||||
if !f.IsDir() {
|
||||
continue
|
||||
}
|
||||
|
||||
repo, err := git.PlainOpen(filepath.Join(ds.opts.Path, f.Name()))
|
||||
if err != nil {
|
||||
if err.Error() == "repository does not exist" {
|
||||
log.Debugf("%s is not a git repository", f.Name())
|
||||
continue
|
||||
}
|
||||
return scannerReport, err
|
||||
}
|
||||
if ds.cfg.Allowlist.RepoAllowed(f.Name()) {
|
||||
continue
|
||||
}
|
||||
|
||||
if ds.opts.RepoConfigPath != "" {
|
||||
cfg, err := config.LoadRepoConfig(repo, ds.opts.RepoConfigPath)
|
||||
if err != nil {
|
||||
log.Warn(err)
|
||||
} else {
|
||||
ds.cfg = cfg
|
||||
}
|
||||
}
|
||||
|
||||
rs := NewRepoScanner(ds.opts, ds.cfg, repo)
|
||||
rs.repoName = f.Name()
|
||||
repoReport, err := rs.Scan()
|
||||
if err != nil {
|
||||
return scannerReport, err
|
||||
}
|
||||
scannerReport.Leaks = append(scannerReport.Leaks, repoReport.Leaks...)
|
||||
scannerReport.Commits += repoReport.Commits
|
||||
}
|
||||
return scannerReport, nil
|
||||
}
|
||||
+118
@@ -0,0 +1,118 @@
|
||||
package scan
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"golang.org/x/sync/errgroup"
|
||||
|
||||
"github.com/zricethezav/gitleaks/v7/config"
|
||||
"github.com/zricethezav/gitleaks/v7/options"
|
||||
|
||||
"github.com/go-git/go-git/v5"
|
||||
"github.com/go-git/go-git/v5/plumbing/object"
|
||||
"github.com/go-git/go-git/v5/plumbing/storer"
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
// RepoScanner is a repo scanner
|
||||
type RepoScanner struct {
|
||||
opts options.Options
|
||||
cfg config.Config
|
||||
repo *git.Repository
|
||||
throttle *Throttle
|
||||
repoName string
|
||||
}
|
||||
|
||||
// NewRepoScanner returns a new repo scanner (go figure). This function also
|
||||
// sets up the leak listener for multi-threaded awesomeness.
|
||||
func NewRepoScanner(opts options.Options, cfg config.Config, repo *git.Repository) *RepoScanner {
|
||||
rs := &RepoScanner{
|
||||
opts: opts,
|
||||
cfg: cfg,
|
||||
repo: repo,
|
||||
throttle: NewThrottle(opts),
|
||||
repoName: getRepoName(opts),
|
||||
}
|
||||
|
||||
return rs
|
||||
}
|
||||
|
||||
// Scan kicks of a repo scan
|
||||
func (rs *RepoScanner) Scan() (Report, error) {
|
||||
var (
|
||||
scannerReport Report
|
||||
commits chan *object.Commit
|
||||
)
|
||||
logOpts, err := logOptions(rs.repo, rs.opts)
|
||||
if err != nil {
|
||||
return scannerReport, err
|
||||
}
|
||||
cIter, err := rs.repo.Log(logOpts)
|
||||
if err != nil {
|
||||
return scannerReport, err
|
||||
}
|
||||
|
||||
g, _ := errgroup.WithContext(context.Background())
|
||||
commits = make(chan *object.Commit)
|
||||
leaks := make(chan Leak)
|
||||
|
||||
commitNum := 0
|
||||
g.Go(func() error {
|
||||
defer close(commits)
|
||||
err = cIter.ForEach(func(c *object.Commit) error {
|
||||
if c == nil || depthReached(commitNum, rs.opts) {
|
||||
return storer.ErrStop
|
||||
}
|
||||
|
||||
if rs.cfg.Allowlist.CommitAllowed(c.Hash.String()) {
|
||||
return nil
|
||||
}
|
||||
commitNum++
|
||||
commits <- c
|
||||
if c.Hash.String() == rs.opts.CommitTo {
|
||||
return storer.ErrStop
|
||||
}
|
||||
|
||||
return err
|
||||
})
|
||||
cIter.Close()
|
||||
return nil
|
||||
})
|
||||
|
||||
for commit := range commits {
|
||||
c := commit
|
||||
rs.throttle.Limit()
|
||||
g.Go(func() error {
|
||||
commitScanner := NewCommitScanner(rs.opts, rs.cfg, rs.repo, c)
|
||||
commitScanner.SetRepoName(rs.repoName)
|
||||
report, err := commitScanner.Scan()
|
||||
rs.throttle.Release()
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
}
|
||||
for _, leak := range report.Leaks {
|
||||
leaks <- leak
|
||||
}
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
go func() {
|
||||
if err := g.Wait(); err != nil {
|
||||
log.Error(err)
|
||||
}
|
||||
close(leaks)
|
||||
}()
|
||||
|
||||
for leak := range leaks {
|
||||
scannerReport.Leaks = append(scannerReport.Leaks, leak)
|
||||
}
|
||||
|
||||
scannerReport.Commits = commitNum
|
||||
return scannerReport, g.Wait()
|
||||
}
|
||||
|
||||
// SetRepoName sets the repo name
|
||||
func (rs *RepoScanner) SetRepoName(repoName string) {
|
||||
rs.repoName = repoName
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
package scan
|
||||
|
||||
import (
|
||||
"encoding/csv"
|
||||
"encoding/json"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"github.com/sirupsen/logrus"
|
||||
"github.com/zricethezav/gitleaks/v7/config"
|
||||
"github.com/zricethezav/gitleaks/v7/options"
|
||||
"github.com/zricethezav/gitleaks/v7/version"
|
||||
)
|
||||
|
||||
// Report is a container for leaks and number of commits scanned
|
||||
type Report struct {
|
||||
Leaks []Leak
|
||||
Commits int
|
||||
}
|
||||
|
||||
// WriteReport accepts a report and options and will write a report if --report has been set
|
||||
func WriteReport(report Report, opts options.Options, cfg config.Config) error {
|
||||
if !(opts.NoGit || opts.CheckUncommitted()) {
|
||||
logrus.Info("commits scanned: ", report.Commits)
|
||||
}
|
||||
if len(report.Leaks) != 0 {
|
||||
logrus.Warn("leaks found: ", len(report.Leaks))
|
||||
} else {
|
||||
logrus.Info("No leaks found")
|
||||
}
|
||||
|
||||
if opts.Report == "" {
|
||||
return nil
|
||||
}
|
||||
|
||||
if opts.Redact {
|
||||
var redactedLeaks []Leak
|
||||
for _, leak := range report.Leaks {
|
||||
redactedLeaks = append(redactedLeaks, RedactLeak(leak))
|
||||
}
|
||||
report.Leaks = redactedLeaks
|
||||
}
|
||||
|
||||
file, err := os.Create(opts.Report)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer rable(file.Close)
|
||||
|
||||
if opts.Report != "" {
|
||||
switch opts.ReportFormat {
|
||||
case "json":
|
||||
encoder := json.NewEncoder(file)
|
||||
encoder.SetIndent("", " ")
|
||||
err = encoder.Encode(report.Leaks)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
case "csv":
|
||||
w := csv.NewWriter(file)
|
||||
err = w.Write([]string{"repo", "line", "commit", "offender", "leakURL", "rule", "tags", "commitMsg", "author", "email", "file", "date"})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, leak := range report.Leaks {
|
||||
err := w.Write([]string{leak.Repo, leak.Line, leak.Commit, leak.Offender, leak.LeakURL, leak.Rule, leak.Tags, leak.Message, leak.Author, leak.Email, leak.File, leak.Date.Format(time.RFC3339)})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
w.Flush()
|
||||
case "sarif":
|
||||
s := Sarif{
|
||||
Schema: "https://schemastore.azurewebsites.net/schemas/json/sarif-2.1.0-rtm.5.json",
|
||||
Version: "2.1.0",
|
||||
Runs: []Runs{
|
||||
{
|
||||
Tool: Tool{
|
||||
Driver: Driver{
|
||||
Name: "Gitleaks",
|
||||
SemanticVersion: version.Version,
|
||||
Rules: configToRules(cfg),
|
||||
},
|
||||
},
|
||||
Results: leaksToResults(report.Leaks),
|
||||
},
|
||||
},
|
||||
}
|
||||
encoder := json.NewEncoder(file)
|
||||
encoder.SetIndent("", " ")
|
||||
err = encoder.Encode(s)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
+155
@@ -0,0 +1,155 @@
|
||||
package scan
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/zricethezav/gitleaks/v7/config"
|
||||
)
|
||||
|
||||
//Sarif ...
|
||||
type Sarif struct {
|
||||
Schema string `json:"$schema"`
|
||||
Version string `json:"version"`
|
||||
Runs []Runs `json:"runs"`
|
||||
}
|
||||
|
||||
//ShortDescription ...
|
||||
type ShortDescription struct {
|
||||
Text string `json:"text"`
|
||||
}
|
||||
|
||||
//FullDescription ...
|
||||
type FullDescription struct {
|
||||
Text string `json:"text"`
|
||||
}
|
||||
|
||||
//Rules ...
|
||||
type Rules struct {
|
||||
ID string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
}
|
||||
|
||||
//Driver ...
|
||||
type Driver struct {
|
||||
Name string `json:"name"`
|
||||
SemanticVersion string `json:"semanticVersion"`
|
||||
Rules []Rules `json:"rules"`
|
||||
}
|
||||
|
||||
//Tool ...
|
||||
type Tool struct {
|
||||
Driver Driver `json:"driver"`
|
||||
}
|
||||
|
||||
//Message ...
|
||||
type Message struct {
|
||||
Text string `json:"text"`
|
||||
}
|
||||
|
||||
//ArtifactLocation ...
|
||||
type ArtifactLocation struct {
|
||||
URI string `json:"uri"`
|
||||
}
|
||||
|
||||
//Region ...
|
||||
type Region struct {
|
||||
StartLine int `json:"startLine"`
|
||||
Snippet Snippet `json:"snippet"`
|
||||
}
|
||||
|
||||
//Snippet ...
|
||||
type Snippet struct {
|
||||
Text string `json:"text"`
|
||||
}
|
||||
|
||||
//PhysicalLocation ...
|
||||
type PhysicalLocation struct {
|
||||
ArtifactLocation ArtifactLocation `json:"artifactLocation"`
|
||||
Region Region `json:"region"`
|
||||
}
|
||||
|
||||
//Locations ...
|
||||
type Locations struct {
|
||||
PhysicalLocation PhysicalLocation `json:"physicalLocation"`
|
||||
}
|
||||
|
||||
//Results ...
|
||||
type Results struct {
|
||||
Message Message `json:"message"`
|
||||
Properties ResultProperties `json:"properties"`
|
||||
Locations []Locations `json:"locations"`
|
||||
}
|
||||
|
||||
//ResultProperties ...
|
||||
type ResultProperties struct {
|
||||
Commit string `json:"commit"`
|
||||
Offender string `json:"offender"`
|
||||
Date time.Time `json:"date"`
|
||||
Author string `json:"author"`
|
||||
Email string `json:"email"`
|
||||
CommitMessage string `json:"commitMessage"`
|
||||
Repo string `json:"repo"`
|
||||
}
|
||||
|
||||
//Runs ...
|
||||
type Runs struct {
|
||||
Tool Tool `json:"tool"`
|
||||
Results []Results `json:"results"`
|
||||
}
|
||||
|
||||
func configToRules(cfg config.Config) []Rules {
|
||||
var rules []Rules
|
||||
for _, rule := range cfg.Rules {
|
||||
rules = append(rules, Rules{
|
||||
ID: rule.Description,
|
||||
Name: rule.Description,
|
||||
})
|
||||
}
|
||||
return rules
|
||||
}
|
||||
|
||||
func leaksToResults(leaks []Leak) []Results {
|
||||
var results []Results
|
||||
for _, leak := range leaks {
|
||||
results = append(results, Results{
|
||||
Message: Message{
|
||||
Text: fmt.Sprintf("%s secret detected", leak.Rule),
|
||||
},
|
||||
Properties: ResultProperties{
|
||||
Commit: leak.Commit,
|
||||
Offender: leak.Offender,
|
||||
Date: leak.Date,
|
||||
Author: leak.Author,
|
||||
Email: leak.Email,
|
||||
CommitMessage: leak.Message,
|
||||
Repo: leak.Repo,
|
||||
},
|
||||
Locations: leakToLocation(leak),
|
||||
})
|
||||
}
|
||||
|
||||
return results
|
||||
}
|
||||
|
||||
func leakToLocation(leak Leak) []Locations {
|
||||
uri := leak.File
|
||||
if leak.LeakURL != "" {
|
||||
uri = leak.LeakURL
|
||||
}
|
||||
return []Locations{
|
||||
{
|
||||
PhysicalLocation: PhysicalLocation{
|
||||
ArtifactLocation: ArtifactLocation{
|
||||
URI: uri,
|
||||
},
|
||||
Region: Region{
|
||||
StartLine: leak.LineNumber,
|
||||
Snippet: Snippet{
|
||||
Text: leak.Line,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
+143
@@ -0,0 +1,143 @@
|
||||
package scan
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/go-git/go-git/v5"
|
||||
|
||||
"github.com/zricethezav/gitleaks/v7/config"
|
||||
"github.com/zricethezav/gitleaks/v7/options"
|
||||
)
|
||||
|
||||
// Scanner abstracts unique scanner internals while exposing the Scan function which
|
||||
// returns a report.
|
||||
type Scanner interface {
|
||||
Scan() (Report, error)
|
||||
}
|
||||
|
||||
// ScannerType is the scanner type which is determined based on program arguments
|
||||
type ScannerType int
|
||||
|
||||
const (
|
||||
typeRepoScanner ScannerType = iota + 1
|
||||
typeDirScanner
|
||||
typeCommitScanner
|
||||
typeCommitsScanner
|
||||
typeUnstagedScanner
|
||||
typeFilesAtCommitScanner
|
||||
typeNoGitScanner
|
||||
typeEmpty
|
||||
)
|
||||
|
||||
// NewScanner accepts options and a config which will be used to determine and create a
|
||||
// new scanner which is then returned.
|
||||
func NewScanner(opts options.Options, cfg config.Config) (Scanner, error) {
|
||||
var (
|
||||
repo *git.Repository
|
||||
err error
|
||||
)
|
||||
|
||||
// We want to return a dir scanner immediately since if the scan type is a directory scan
|
||||
// we don't want to clone/open a repo until inside ParentScanner.Scan
|
||||
st, err := scanType(opts)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if st == typeDirScanner {
|
||||
return NewParentScanner(opts, cfg), nil
|
||||
}
|
||||
|
||||
// Clone or open a repo if we need it
|
||||
if needsRepo(st) {
|
||||
repo, err = getRepo(opts)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
// load up alternative config if possible, if not use manager's config
|
||||
if opts.RepoConfigPath != "" && !opts.NoGit {
|
||||
cfg, err = config.LoadRepoConfig(repo, opts.RepoConfigPath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
switch st {
|
||||
case typeCommitScanner:
|
||||
c, err := obtainCommit(repo, opts.Commit)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return NewCommitScanner(opts, cfg, repo, c), nil
|
||||
case typeCommitsScanner:
|
||||
commits, err := optsToCommits(opts)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return NewCommitsScanner(opts, cfg, repo, commits), nil
|
||||
case typeFilesAtCommitScanner:
|
||||
c, err := obtainCommit(repo, opts.FilesAtCommit)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return NewFilesAtCommitScanner(opts, cfg, repo, c), nil
|
||||
case typeUnstagedScanner:
|
||||
return NewUnstagedScanner(opts, cfg, repo), nil
|
||||
case typeDirScanner:
|
||||
return NewParentScanner(opts, cfg), nil
|
||||
case typeNoGitScanner:
|
||||
return NewNoGitScanner(opts, cfg), nil
|
||||
default:
|
||||
return NewRepoScanner(opts, cfg, repo), nil
|
||||
}
|
||||
}
|
||||
|
||||
func scanType(opts options.Options) (ScannerType, error) {
|
||||
if opts.Commit != "" {
|
||||
return typeCommitScanner, nil
|
||||
}
|
||||
if opts.Commits != "" || opts.CommitsFile != "" {
|
||||
return typeCommitsScanner, nil
|
||||
}
|
||||
if opts.FilesAtCommit != "" {
|
||||
return typeFilesAtCommitScanner, nil
|
||||
}
|
||||
if opts.Path != "" && !opts.NoGit {
|
||||
if opts.CheckUncommitted() {
|
||||
return typeUnstagedScanner, nil
|
||||
}
|
||||
_, err := os.Stat(filepath.Join(opts.Path))
|
||||
if err != nil {
|
||||
return typeEmpty, err
|
||||
}
|
||||
// check if path/.git exists, if it does, this is a repo scan
|
||||
// if not this is a multi-repo scan
|
||||
_, err = os.Stat(filepath.Join(opts.Path, ".git"))
|
||||
if os.IsNotExist(err) {
|
||||
return typeDirScanner, nil
|
||||
}
|
||||
return typeRepoScanner, nil
|
||||
}
|
||||
if opts.Path != "" && opts.NoGit {
|
||||
_, err := os.Stat(filepath.Join(opts.Path))
|
||||
if err != nil {
|
||||
return typeEmpty, err
|
||||
}
|
||||
return typeNoGitScanner, nil
|
||||
}
|
||||
if opts.CheckUncommitted() {
|
||||
return typeUnstagedScanner, nil
|
||||
}
|
||||
|
||||
// default to the most commonly used scanner, RepoScanner
|
||||
return typeRepoScanner, nil
|
||||
}
|
||||
|
||||
func needsRepo(st ScannerType) bool {
|
||||
if !(st == typeDirScanner || st == typeNoGitScanner) {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
@@ -0,0 +1,797 @@
|
||||
package scan
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"runtime"
|
||||
"testing"
|
||||
|
||||
"github.com/zricethezav/gitleaks/v7/config"
|
||||
"github.com/zricethezav/gitleaks/v7/options"
|
||||
)
|
||||
|
||||
const testRepoBase = "../test_data/test_repos/"
|
||||
|
||||
func TestScan(t *testing.T) {
|
||||
err := moveDotGit("dotGit", ".git")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer moveDotGit(".git", "dotGit")
|
||||
tests := []struct {
|
||||
description string
|
||||
opts options.Options
|
||||
wantPath string
|
||||
wantErr error
|
||||
wantScanErr error
|
||||
emptyRepo bool
|
||||
wantEmpty bool
|
||||
}{
|
||||
{
|
||||
description: "test local repo one aws leak",
|
||||
opts: options.Options{
|
||||
Path: "../test_data/test_repos/test_repo_1",
|
||||
Report: "../test_data/test_local_repo_one_aws_leak.json.got",
|
||||
ReportFormat: "json",
|
||||
Threads: runtime.GOMAXPROCS(0),
|
||||
},
|
||||
wantPath: "../test_data/test_local_repo_one_aws_leak.json",
|
||||
},
|
||||
{
|
||||
description: "test local repo one aws leak threaded",
|
||||
opts: options.Options{
|
||||
Threads: runtime.GOMAXPROCS(0),
|
||||
Path: "../test_data/test_repos/test_repo_1",
|
||||
Report: "../test_data/test_local_repo_one_aws_leak.json.got",
|
||||
ReportFormat: "json",
|
||||
},
|
||||
wantPath: "../test_data/test_local_repo_one_aws_leak.json",
|
||||
},
|
||||
{
|
||||
description: "test non existent repo",
|
||||
opts: options.Options{
|
||||
Path: "../test_data/test_repos/no_repo_here",
|
||||
ReportFormat: "json",
|
||||
},
|
||||
wantErr: fmt.Errorf("stat ../test_data/test_repos/no_repo_here: no such file or directory"),
|
||||
emptyRepo: true,
|
||||
},
|
||||
{
|
||||
description: "test local repo one aws leak allowlisted",
|
||||
opts: options.Options{
|
||||
Path: "../test_data/test_repos/test_repo_1",
|
||||
ReportFormat: "json",
|
||||
ConfigPath: "../test_data/test_configs/aws_key_allowlist_python_files.toml",
|
||||
},
|
||||
wantEmpty: true,
|
||||
},
|
||||
{
|
||||
description: "test local repo two leaks",
|
||||
opts: options.Options{
|
||||
Path: "../test_data/test_repos/test_repo_2",
|
||||
Report: "../test_data/test_local_repo_two_leaks.json.got",
|
||||
ReportFormat: "json",
|
||||
},
|
||||
wantPath: "../test_data/test_local_repo_two_leaks.json",
|
||||
},
|
||||
{
|
||||
description: "test local repo two leaks from Commit",
|
||||
opts: options.Options{
|
||||
Path: "../test_data/test_repos/test_repo_2",
|
||||
Report: "../test_data/test_local_repo_two_leaks_commit_from.json.got",
|
||||
ReportFormat: "json",
|
||||
CommitFrom: "996865bb912f3bc45898a370a13aadb315014b55",
|
||||
},
|
||||
wantPath: "../test_data/test_local_repo_two_leaks_commit_from.json",
|
||||
},
|
||||
{
|
||||
description: "test local repo two leaks to Commit",
|
||||
opts: options.Options{
|
||||
Path: "../test_data/test_repos/test_repo_2",
|
||||
Report: "../test_data/test_local_repo_two_leaks_commit_to.json.got",
|
||||
ReportFormat: "json",
|
||||
CommitTo: "996865bb912f3bc45898a370a13aadb315014b55",
|
||||
},
|
||||
wantPath: "../test_data/test_local_repo_two_leaks_commit_to.json",
|
||||
},
|
||||
{
|
||||
description: "test local repo two leaks to from Commit",
|
||||
opts: options.Options{
|
||||
Path: "../test_data/test_repos/test_repo_2",
|
||||
Report: "../test_data/test_local_repo_two_leaks_commit_to_from.json.got",
|
||||
ReportFormat: "json",
|
||||
CommitFrom: "d8ac0b73aeeb45843319cdc5ce506516eb49bf7a",
|
||||
CommitTo: "51f6dcf6b89b93f4075ba92c400b075631a6cc93",
|
||||
},
|
||||
wantPath: "../test_data/test_local_repo_two_leaks_commit_to_from.json",
|
||||
},
|
||||
{
|
||||
description: "test local repo two leaks list Commits",
|
||||
opts: options.Options{
|
||||
Path: "../test_data/test_repos/test_repo_2",
|
||||
Report: "../test_data/test_local_repo_two_leaks_commit_range.json.got",
|
||||
ReportFormat: "json",
|
||||
Commits: "d8ac0b73aeeb45843319cdc5ce506516eb49bf7a,996865bb912f3bc45898a370a13aadb315014b55,17471a5fda722a9e423f1a0d3f0d267ea009d41c,51f6dcf6b89b93f4075ba92c400b075631a6cc93,b10b3e2cb320a8c211fda94c4567299d37de7776",
|
||||
},
|
||||
wantPath: "../test_data/test_local_repo_two_leaks_commit_range.json",
|
||||
},
|
||||
{
|
||||
description: "test local repo two leaks file list commits",
|
||||
opts: options.Options{
|
||||
Path: "../test_data/test_repos/test_repo_2",
|
||||
Report: "../test_data/test_local_repo_two_leaks_file_commit_range.json.got",
|
||||
ReportFormat: "json",
|
||||
CommitsFile: "../test_data/test_options/test_local_repo_commits.txt",
|
||||
Threads: runtime.GOMAXPROCS(0),
|
||||
},
|
||||
wantPath: "../test_data/test_local_repo_two_leaks_file_commit_range.json",
|
||||
},
|
||||
{
|
||||
description: "test local repo two leaks globally allowlisted",
|
||||
opts: options.Options{
|
||||
Path: "../test_data/test_repos/test_repo_2",
|
||||
ConfigPath: "../test_data/test_configs/aws_key_global_allowlist_file.toml",
|
||||
ReportFormat: "json",
|
||||
},
|
||||
wantEmpty: true,
|
||||
},
|
||||
{
|
||||
description: "test local repo two leaks allowlisted",
|
||||
opts: options.Options{
|
||||
Path: "../test_data/test_repos/test_repo_2",
|
||||
ConfigPath: "../test_data/test_configs/aws_key_allowlist_files.toml",
|
||||
ReportFormat: "json",
|
||||
},
|
||||
wantEmpty: true,
|
||||
},
|
||||
{
|
||||
description: "test local repo three leaks dev branch with reportGroup set",
|
||||
opts: options.Options{
|
||||
Path: "../test_data/test_repos/test_repo_3",
|
||||
Report: "../test_data/test_local_repo_three_leaks_with_report_groups.json.got",
|
||||
ConfigPath: "../test_data/test_configs/aws_key_with_report_groups.toml",
|
||||
Branch: "dev",
|
||||
ReportFormat: "json",
|
||||
},
|
||||
wantPath: "../test_data/test_local_repo_three_leaks_with_report_groups.json",
|
||||
},
|
||||
{
|
||||
description: "test local repo three leaks dev branch",
|
||||
opts: options.Options{
|
||||
Path: "../test_data/test_repos/test_repo_3",
|
||||
Report: "../test_data/test_local_repo_three_leaks.json.got",
|
||||
ConfigPath: "../test_data/test_configs/aws_key.toml",
|
||||
Branch: "dev",
|
||||
ReportFormat: "json",
|
||||
},
|
||||
wantPath: "../test_data/test_local_repo_three_leaks.json",
|
||||
},
|
||||
{
|
||||
description: "test local repo branch does not exist",
|
||||
opts: options.Options{
|
||||
Path: "../test_data/test_repos/test_repo_3",
|
||||
Branch: "nobranch",
|
||||
ReportFormat: "json",
|
||||
},
|
||||
wantScanErr: fmt.Errorf("could not find branch nobranch"),
|
||||
},
|
||||
{
|
||||
description: "test local repo one aws leak single Commit",
|
||||
opts: options.Options{
|
||||
Path: "../test_data/test_repos/test_repo_1",
|
||||
Report: "../test_data/test_local_repo_one_aws_leak_commit.json.got",
|
||||
Commit: "6557c92612d3b35979bd426d429255b3bf9fab74",
|
||||
ReportFormat: "json",
|
||||
},
|
||||
wantPath: "../test_data/test_local_repo_one_aws_leak_commit.json",
|
||||
},
|
||||
{
|
||||
description: "test local repo one aws leak AND leak on python files",
|
||||
opts: options.Options{
|
||||
Path: "../test_data/test_repos/test_repo_1",
|
||||
Report: "../test_data/test_local_repo_one_aws_leak_and_file_leak.json.got",
|
||||
ConfigPath: "../test_data/test_configs/aws_key_file_regex.toml",
|
||||
ReportFormat: "json",
|
||||
},
|
||||
wantPath: "../test_data/test_local_repo_one_aws_leak_and_file_leak.json",
|
||||
},
|
||||
{
|
||||
description: "test owner path",
|
||||
opts: options.Options{
|
||||
Path: "../test_data/test_repos/",
|
||||
Report: "../test_data/test_local_owner_aws_leak.json.got",
|
||||
ReportFormat: "json",
|
||||
Threads: runtime.GOMAXPROCS(0),
|
||||
},
|
||||
wantPath: "../test_data/test_local_owner_aws_leak.json",
|
||||
},
|
||||
{
|
||||
description: "test owner path allowlist repo",
|
||||
opts: options.Options{
|
||||
Path: "../test_data/test_repos/",
|
||||
Report: "../test_data/test_local_owner_aws_leak_allowlist_repo.json.got",
|
||||
ReportFormat: "json",
|
||||
ConfigPath: "../test_data/test_configs/aws_key_local_owner_allowlist_repo.toml",
|
||||
},
|
||||
wantPath: "../test_data/test_local_owner_aws_leak_allowlist_repo.json",
|
||||
},
|
||||
{
|
||||
description: "test entropy and regex",
|
||||
opts: options.Options{
|
||||
Path: "../test_data/test_repos/test_repo_1",
|
||||
Report: "../test_data/test_regex_entropy.json.got",
|
||||
ConfigPath: "../test_data/test_configs/regex_entropy.toml",
|
||||
ReportFormat: "json",
|
||||
Threads: runtime.GOMAXPROCS(0),
|
||||
},
|
||||
wantPath: "../test_data/test_regex_entropy.json",
|
||||
},
|
||||
{
|
||||
description: "test local repo four entropy alternative config",
|
||||
opts: options.Options{
|
||||
Path: "../test_data/test_repos/test_repo_4",
|
||||
Report: "../test_data/test_local_repo_four_alt_config_entropy.json.got",
|
||||
RepoConfigPath: "gitleaks.toml",
|
||||
ReportFormat: "json",
|
||||
},
|
||||
wantPath: "../test_data/test_local_repo_four_alt_config_entropy.json",
|
||||
},
|
||||
{
|
||||
description: "test local repo four entropy alternative config",
|
||||
opts: options.Options{
|
||||
Path: "../test_data/test_repos/test_repo_1",
|
||||
Report: "../test_data/test_regex_allowlist.json.got",
|
||||
ConfigPath: "../test_data/test_configs/aws_key_aws_allowlisted.toml",
|
||||
ReportFormat: "json",
|
||||
},
|
||||
wantEmpty: true,
|
||||
},
|
||||
{
|
||||
description: "test owner path depth=2",
|
||||
opts: options.Options{
|
||||
Path: "../test_data/test_repos/",
|
||||
Report: "../test_data/test_local_owner_aws_leak_depth_2.json.got",
|
||||
ReportFormat: "json",
|
||||
Depth: 2,
|
||||
},
|
||||
wantPath: "../test_data/test_local_owner_aws_leak_depth_2.json",
|
||||
},
|
||||
{
|
||||
description: "test local repo five files at Commit",
|
||||
opts: options.Options{
|
||||
Path: "../test_data/test_repos/test_repo_5",
|
||||
Report: "../test_data/test_local_repo_five_files_at_commit.json.got",
|
||||
FilesAtCommit: "a4c9fb737d5552fd96fce5cc7eedb23353ba9ed0",
|
||||
ReportFormat: "json",
|
||||
},
|
||||
wantPath: "../test_data/test_local_repo_five_files_at_commit.json",
|
||||
},
|
||||
{
|
||||
description: "test local repo five files at latest Commit",
|
||||
opts: options.Options{
|
||||
Path: "../test_data/test_repos/test_repo_5",
|
||||
Report: "../test_data/test_local_repo_five_files_at_latest_commit.json.got",
|
||||
FilesAtCommit: "latest",
|
||||
ReportFormat: "json",
|
||||
},
|
||||
wantPath: "../test_data/test_local_repo_five_files_at_commit.json",
|
||||
},
|
||||
{
|
||||
description: "test local repo five at Commit",
|
||||
opts: options.Options{
|
||||
Path: "../test_data/test_repos/test_repo_5",
|
||||
Report: "../test_data/test_local_repo_five_commit.json.got",
|
||||
Commit: "a4c9fb737d5552fd96fce5cc7eedb23353ba9ed0",
|
||||
ReportFormat: "json",
|
||||
ConfigPath: "../test_data/test_configs/generic.toml",
|
||||
},
|
||||
wantPath: "../test_data/test_local_repo_five_commit.json",
|
||||
},
|
||||
{
|
||||
description: "test local repo five at latest Commit",
|
||||
opts: options.Options{
|
||||
Path: "../test_data/test_repos/test_repo_5",
|
||||
Report: "../test_data/test_local_repo_five_at_latest_commit.json.got",
|
||||
Commit: "latest",
|
||||
ReportFormat: "json",
|
||||
ConfigPath: "../test_data/test_configs/generic.toml",
|
||||
},
|
||||
wantPath: "../test_data/test_local_repo_five_at_latest_commit.json",
|
||||
},
|
||||
{
|
||||
description: "test local repo six filename",
|
||||
opts: options.Options{
|
||||
Path: "../test_data/test_repos/test_repo_6",
|
||||
Report: "../test_data/test_local_repo_six_filename.json.got",
|
||||
ConfigPath: "../test_data/test_configs/regex_filename.toml",
|
||||
ReportFormat: "json",
|
||||
},
|
||||
wantPath: "../test_data/test_local_repo_six_filename.json",
|
||||
},
|
||||
{
|
||||
description: "test local repo six filepath",
|
||||
opts: options.Options{
|
||||
Path: "../test_data/test_repos/test_repo_6",
|
||||
Report: "../test_data/test_local_repo_six_filepath.json.got",
|
||||
ConfigPath: "../test_data/test_configs/regex_filepath.toml",
|
||||
ReportFormat: "json",
|
||||
},
|
||||
wantPath: "../test_data/test_local_repo_six_filepath.json",
|
||||
},
|
||||
{
|
||||
description: "test local repo six filename and filepath",
|
||||
opts: options.Options{
|
||||
Path: "../test_data/test_repos/test_repo_6",
|
||||
Report: "../test_data/test_local_repo_six_filepath_filename.json.got",
|
||||
ConfigPath: "../test_data/test_configs/regex_filepath_filename.toml",
|
||||
ReportFormat: "json",
|
||||
},
|
||||
wantPath: "../test_data/test_local_repo_six_filepath_filename.json",
|
||||
},
|
||||
{
|
||||
description: "test local repo six path globally allowlisted",
|
||||
opts: options.Options{
|
||||
Path: "../test_data/test_repos/test_repo_6",
|
||||
Report: "../test_data/test_local_repo_six_path_globally_allowlisted.json.got",
|
||||
ConfigPath: "../test_data/test_configs/aws_key_global_allowlist_path.toml",
|
||||
ReportFormat: "json",
|
||||
},
|
||||
wantPath: "../test_data/test_local_repo_six_path_globally_allowlisted.json",
|
||||
},
|
||||
{
|
||||
description: "test local repo six leaks since date",
|
||||
opts: options.Options{
|
||||
Path: "../test_data/test_repos/test_repo_6",
|
||||
Report: "../test_data/test_local_repo_six_leaks_since_date.json.got",
|
||||
ReportFormat: "json",
|
||||
CommitSince: "2019-10-25",
|
||||
},
|
||||
wantPath: "../test_data/test_local_repo_six_leaks_since_date.json",
|
||||
},
|
||||
{
|
||||
description: "test local repo two leaks until date",
|
||||
opts: options.Options{
|
||||
Path: "../test_data/test_repos/test_repo_6",
|
||||
Report: "../test_data/test_local_repo_six_leaks_until_date.json.got",
|
||||
ReportFormat: "json",
|
||||
CommitUntil: "2019-10-25",
|
||||
},
|
||||
wantPath: "../test_data/test_local_repo_six_leaks_until_date.json",
|
||||
},
|
||||
{
|
||||
description: "test local repo four leaks timerange Commit",
|
||||
opts: options.Options{
|
||||
Path: "../test_data/test_repos/test_repo_4",
|
||||
Report: "../test_data/test_local_repo_four_leaks_commit_timerange.json.got",
|
||||
ReportFormat: "json",
|
||||
CommitSince: "2019-10-25T13:01:27-0400",
|
||||
CommitUntil: "2019-10-25T13:12:32-0400",
|
||||
},
|
||||
wantPath: "../test_data/test_local_repo_four_leaks_commit_timerange.json",
|
||||
},
|
||||
{
|
||||
description: "test local repo two allowlist Commit config",
|
||||
opts: options.Options{
|
||||
Path: "../test_data/test_repos/test_repo_2",
|
||||
Report: "../test_data/test_local_repo_two_allowlist_commits.json.got",
|
||||
ConfigPath: "../test_data/test_configs/allowlist_commit.toml",
|
||||
ReportFormat: "json",
|
||||
},
|
||||
wantPath: "../test_data/test_local_repo_two_allowlist_commits.json",
|
||||
},
|
||||
{
|
||||
description: "test local repo eight (merges)",
|
||||
opts: options.Options{
|
||||
Path: "../test_data/test_repos/test_repo_8",
|
||||
Report: "../test_data/test_local_repo_eight.json.got",
|
||||
ReportFormat: "json",
|
||||
},
|
||||
wantPath: "../test_data/test_local_repo_eight.json",
|
||||
},
|
||||
{
|
||||
description: "test local repo nine",
|
||||
opts: options.Options{
|
||||
Path: "../test_data/test_repos/test_repo_9",
|
||||
Report: "../test_data/test_local_repo_nine_aws_leak.json.got",
|
||||
ConfigPath: "../test_data/test_configs/large_with_global_allowlist_regex.toml",
|
||||
ReportFormat: "json",
|
||||
},
|
||||
wantPath: "../test_data/test_local_repo_nine_aws_leak.json",
|
||||
},
|
||||
{
|
||||
description: "test dir one no git",
|
||||
opts: options.Options{
|
||||
Path: "../test_data/test_repos/test_dir_1",
|
||||
Report: "../test_data/test_dir1_aws_leak.json.got",
|
||||
ReportFormat: "json",
|
||||
NoGit: true,
|
||||
},
|
||||
wantPath: "../test_data/test_dir1_aws_leak.json",
|
||||
},
|
||||
{
|
||||
description: "test file with leak no git",
|
||||
opts: options.Options{
|
||||
Path: "../test_data/test_repos/test_dir_1/server.test.py",
|
||||
Report: "../test_data/test_file1_aws_leak.json.got",
|
||||
ReportFormat: "json",
|
||||
NoGit: true,
|
||||
},
|
||||
wantPath: "../test_data/test_file1_aws_leak.json",
|
||||
},
|
||||
{
|
||||
description: "test only md files no git",
|
||||
opts: options.Options{
|
||||
Path: "../test_data/test_repos/",
|
||||
Report: "../test_data/test_only_files_no_git.json.got",
|
||||
ReportFormat: "json",
|
||||
ConfigPath: "../test_data/test_configs/onlyFiles.toml",
|
||||
NoGit: true,
|
||||
},
|
||||
wantPath: "../test_data/test_only_files_no_git.json",
|
||||
},
|
||||
{
|
||||
description: "test allowlist files",
|
||||
opts: options.Options{
|
||||
Path: "../test_data/test_repos/test_repo_10",
|
||||
Report: "../test_data/test_allow_list_file.json.got",
|
||||
ReportFormat: "json",
|
||||
ConfigPath: "../test_data/test_configs/allowlist_files.toml",
|
||||
},
|
||||
wantPath: "../test_data/test_allow_list_file.json",
|
||||
},
|
||||
{
|
||||
description: "test allowlist files no-git",
|
||||
opts: options.Options{
|
||||
Path: "../test_data/test_repos/test_repo_10",
|
||||
Report: "../test_data/test_allow_list_file_no_git.json.got",
|
||||
ReportFormat: "json",
|
||||
ConfigPath: "../test_data/test_configs/allowlist_files.toml",
|
||||
NoGit: true,
|
||||
},
|
||||
wantPath: "../test_data/test_allow_list_file_no_git.json",
|
||||
},
|
||||
{
|
||||
description: "test allowlist docx no-git",
|
||||
opts: options.Options{
|
||||
Path: "../test_data/test_repos/test_repo_10",
|
||||
Report: "../test_data/test_allow_list_docx_no_git.json.got",
|
||||
ReportFormat: "json",
|
||||
ConfigPath: "../test_data/test_configs/allowlist_docx.toml",
|
||||
NoGit: true,
|
||||
},
|
||||
wantPath: "../test_data/test_allow_list_docx_no_git.json",
|
||||
},
|
||||
{
|
||||
description: "test local repo two allowlist Commit config",
|
||||
opts: options.Options{
|
||||
Path: "../test_data/test_repos/test_repo_2",
|
||||
Report: "../test_data/test_local_repo_two_allowlist_commits_files_at_commit.json.got",
|
||||
ConfigPath: "../test_data/test_configs/allowlist_commit.toml",
|
||||
ReportFormat: "json",
|
||||
FilesAtCommit: "17471a5fda722a9e423f1a0d3f0d267ea009d41c",
|
||||
},
|
||||
wantPath: "../test_data/test_local_repo_two_allowlist_commits_files_at_commit.json",
|
||||
wantEmpty: true,
|
||||
},
|
||||
{
|
||||
description: "test local repo two global allowlist commit config",
|
||||
opts: options.Options{
|
||||
Path: "../test_data/test_repos/test_repo_2",
|
||||
Report: "../test_data/test_local_repo_two_global_allowlist_files_at_commit.json.got",
|
||||
ConfigPath: "../test_data/test_configs/allowlist_global_files.toml",
|
||||
ReportFormat: "json",
|
||||
FilesAtCommit: "17471a5fda722a9e423f1a0d3f0d267ea009d41c",
|
||||
},
|
||||
wantPath: "../test_data/test_local_repo_two_global_allowlist_files_at_commit.json",
|
||||
wantEmpty: true,
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
fmt.Println(test.description)
|
||||
cfg, err := config.NewConfig(test.opts)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
scanner, err := NewScanner(test.opts, cfg)
|
||||
if test.wantErr != nil {
|
||||
if err == nil {
|
||||
t.Fatalf("did not receive wantErr: %v", test.wantErr)
|
||||
}
|
||||
if err.Error() != test.wantErr.Error() {
|
||||
t.Fatalf("wantErr does not equal err received: %v", err.Error())
|
||||
}
|
||||
continue
|
||||
}
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
scannerReport, err := scanner.Scan()
|
||||
|
||||
if test.wantScanErr != nil {
|
||||
if err == nil {
|
||||
t.Fatalf("did not receive wantErr: %v", test.wantScanErr)
|
||||
}
|
||||
if err.Error() != test.wantScanErr.Error() {
|
||||
t.Fatalf("wantErr does not equal err received: %v", err.Error())
|
||||
}
|
||||
continue
|
||||
}
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
err = WriteReport(scannerReport, test.opts, cfg)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if test.wantEmpty {
|
||||
if len(scannerReport.Leaks) != 0 {
|
||||
t.Errorf("wanted no leaks but got some instead: %+v", scannerReport.Leaks)
|
||||
}
|
||||
continue
|
||||
}
|
||||
|
||||
if test.wantPath != "" {
|
||||
err := fileCheck(test.wantPath, test.opts.Report)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
func TestScanUncommited(t *testing.T) {
|
||||
moveDotGit("dotGit", ".git")
|
||||
defer moveDotGit(".git", "dotGit")
|
||||
tests := []struct {
|
||||
description string
|
||||
opts options.Options
|
||||
wantPath string
|
||||
wantErr error
|
||||
wantScanErr error
|
||||
emptyRepo bool
|
||||
wantEmpty bool
|
||||
fileToChange string
|
||||
addition string
|
||||
}{
|
||||
{
|
||||
description: "test scan local one leak",
|
||||
opts: options.Options{
|
||||
Path: "../test_data/test_repos/test_repo_1",
|
||||
Report: "../test_data/test_local_repo_one_aws_leak_uncommitted.json.got",
|
||||
Unstaged: true,
|
||||
ReportFormat: "json",
|
||||
},
|
||||
wantPath: "../test_data/test_local_repo_one_aws_leak_uncommitted.json",
|
||||
fileToChange: "server.test.py",
|
||||
addition: " aws_access_key_id='AKIAIO5FODNN7DXAMPLE'\n\n",
|
||||
},
|
||||
{
|
||||
description: "test scan local no leak",
|
||||
opts: options.Options{
|
||||
Path: "../test_data/test_repos/test_repo_1",
|
||||
Unstaged: true,
|
||||
ReportFormat: "json",
|
||||
},
|
||||
wantEmpty: true,
|
||||
fileToChange: "server.test.py",
|
||||
addition: "nothing bad",
|
||||
},
|
||||
{
|
||||
description: "test scan repo with no commits",
|
||||
opts: options.Options{
|
||||
Path: "../test_data/test_repos/test_repo_7",
|
||||
Report: "../test_data/test_local_repo_seven_aws_leak_uncommitted.json.got",
|
||||
Unstaged: true,
|
||||
ReportFormat: "json",
|
||||
},
|
||||
wantPath: "../test_data/test_local_repo_seven_aws_leak_uncommitted.json",
|
||||
},
|
||||
}
|
||||
for _, test := range tests {
|
||||
var (
|
||||
old []byte
|
||||
err error
|
||||
)
|
||||
fmt.Println(test.description)
|
||||
if test.fileToChange != "" {
|
||||
old, err = ioutil.ReadFile(fmt.Sprintf("%s/%s", test.opts.Path, test.fileToChange))
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
altered, err := os.OpenFile(fmt.Sprintf("%s/%s", test.opts.Path, test.fileToChange),
|
||||
os.O_WRONLY|os.O_APPEND, 0644)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
_, err = altered.WriteString(test.addition)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
cfg, err := config.NewConfig(test.opts)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
scanner, err := NewScanner(test.opts, cfg)
|
||||
if test.wantErr != nil {
|
||||
if err == nil {
|
||||
t.Fatalf("did not receive wantErr: %v", test.wantErr)
|
||||
}
|
||||
if err.Error() != test.wantErr.Error() {
|
||||
t.Fatalf("wantErr does not equal err received: %v", err.Error())
|
||||
}
|
||||
continue
|
||||
}
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
scannerReport, err := scanner.Scan()
|
||||
|
||||
if test.wantScanErr != nil {
|
||||
if err == nil {
|
||||
t.Fatalf("did not receive wantErr: %v", test.wantScanErr)
|
||||
}
|
||||
if err.Error() != test.wantScanErr.Error() {
|
||||
t.Fatalf("wantErr does not equal err received: %v", err.Error())
|
||||
}
|
||||
continue
|
||||
}
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
err = WriteReport(scannerReport, test.opts, cfg)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if test.fileToChange != "" {
|
||||
err = ioutil.WriteFile(fmt.Sprintf("%s/%s", test.opts.Path, test.fileToChange), old, 0)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
if test.wantEmpty {
|
||||
continue
|
||||
}
|
||||
|
||||
if test.wantPath != "" {
|
||||
err := fileCheck(test.wantPath, test.opts.Report)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func fileCheck(wantPath, gotPath string) error {
|
||||
var (
|
||||
gotLeaks []Leak
|
||||
wantLeaks []Leak
|
||||
)
|
||||
want, err := ioutil.ReadFile(wantPath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
got, err := ioutil.ReadFile(gotPath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = json.Unmarshal(got, &gotLeaks)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = json.Unmarshal(want, &wantLeaks)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if len(wantLeaks) != len(gotLeaks) {
|
||||
return fmt.Errorf("got %d leaks, want %d leaks", len(gotLeaks), len(wantLeaks))
|
||||
}
|
||||
|
||||
for _, wantLeak := range wantLeaks {
|
||||
found := false
|
||||
for _, gotLeak := range gotLeaks {
|
||||
if same(gotLeak, wantLeak) {
|
||||
found = true
|
||||
}
|
||||
}
|
||||
if !found {
|
||||
return fmt.Errorf("unable to find %+v in got leaks", wantLeak)
|
||||
}
|
||||
}
|
||||
|
||||
if err := os.Remove(gotPath); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func same(l1, l2 Leak) bool {
|
||||
if l1.Commit != l2.Commit {
|
||||
return false
|
||||
}
|
||||
|
||||
if l1.Offender != l2.Offender {
|
||||
return false
|
||||
}
|
||||
|
||||
if l1.Line != l2.Line {
|
||||
return false
|
||||
}
|
||||
|
||||
if l1.Tags != l2.Tags {
|
||||
return false
|
||||
}
|
||||
|
||||
if l1.LineNumber != l2.LineNumber {
|
||||
return false
|
||||
}
|
||||
|
||||
if l1.Author != l2.Author {
|
||||
return false
|
||||
}
|
||||
|
||||
if l1.LeakURL != l2.LeakURL {
|
||||
return false
|
||||
}
|
||||
|
||||
if l1.RepoURL != l2.RepoURL {
|
||||
return false
|
||||
}
|
||||
|
||||
if l1.Repo != l2.Repo {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
|
||||
}
|
||||
|
||||
func moveDotGit(from, to string) error {
|
||||
repoDirs, err := ioutil.ReadDir("../test_data/test_repos")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, dir := range repoDirs {
|
||||
if to == ".git" {
|
||||
_, err := os.Stat(fmt.Sprintf("%s/%s/%s", testRepoBase, dir.Name(), "dotGit"))
|
||||
if os.IsNotExist(err) {
|
||||
// dont want to delete the only copy of .git accidentally
|
||||
continue
|
||||
}
|
||||
os.RemoveAll(fmt.Sprintf("%s/%s/%s", testRepoBase, dir.Name(), ".git"))
|
||||
}
|
||||
if !dir.IsDir() {
|
||||
continue
|
||||
}
|
||||
_, err := os.Stat(fmt.Sprintf("%s/%s/%s", testRepoBase, dir.Name(), from))
|
||||
if os.IsNotExist(err) {
|
||||
continue
|
||||
}
|
||||
|
||||
err = os.Rename(fmt.Sprintf("%s/%s/%s", testRepoBase, dir.Name(), from),
|
||||
fmt.Sprintf("%s/%s/%s", testRepoBase, dir.Name(), to))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// fmt.Println("RENAMED")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package scan
|
||||
|
||||
import (
|
||||
"runtime"
|
||||
|
||||
"github.com/zricethezav/gitleaks/v7/options"
|
||||
)
|
||||
|
||||
const (
|
||||
singleThreadCommitBuffer = 1
|
||||
multiThreadCommitBufferMultiplier = 10
|
||||
)
|
||||
|
||||
// Throttle is a struct that limits the number of concurrent goroutines and sets the
|
||||
// number of threads available for gitleaks to use via GOMAXPROCS.
|
||||
type Throttle struct {
|
||||
throttle chan bool
|
||||
}
|
||||
|
||||
// NewThrottle accepts some options and returns a throttle for scanners to use
|
||||
func NewThrottle(opts options.Options) *Throttle {
|
||||
t := Throttle{}
|
||||
if opts.Threads <= 1 {
|
||||
runtime.GOMAXPROCS(1)
|
||||
t.throttle = make(chan bool, singleThreadCommitBuffer)
|
||||
return &t
|
||||
}
|
||||
|
||||
runtime.GOMAXPROCS(opts.Threads)
|
||||
t.throttle = make(chan bool, multiThreadCommitBufferMultiplier*opts.Threads)
|
||||
return &t
|
||||
|
||||
}
|
||||
|
||||
// Limit blocks new goroutines from spinning up if throttle is at capacity
|
||||
func (t *Throttle) Limit() {
|
||||
t.throttle <- true
|
||||
}
|
||||
|
||||
// Release releases the hold on the throttle, allowing more goroutines to be spun up
|
||||
func (t *Throttle) Release() {
|
||||
<-t.throttle
|
||||
}
|
||||
@@ -0,0 +1,286 @@
|
||||
package scan
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"io"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/zricethezav/gitleaks/v7/config"
|
||||
"github.com/zricethezav/gitleaks/v7/options"
|
||||
|
||||
"github.com/go-git/go-git/v5"
|
||||
"github.com/go-git/go-git/v5/plumbing"
|
||||
"github.com/sergi/go-diff/diffmatchpatch"
|
||||
)
|
||||
|
||||
// UnstagedScanner is an unstaged scanner. This is the scanner used when you don't provide program arguments
|
||||
// which will then scan your PWD. This scans unstaged changes in your repo.
|
||||
type UnstagedScanner struct {
|
||||
opts options.Options
|
||||
cfg config.Config
|
||||
repo *git.Repository
|
||||
repoName string
|
||||
}
|
||||
|
||||
// NewUnstagedScanner returns an unstaged scanner
|
||||
func NewUnstagedScanner(opts options.Options, cfg config.Config, repo *git.Repository) *UnstagedScanner {
|
||||
us := &UnstagedScanner{
|
||||
opts: opts,
|
||||
cfg: cfg,
|
||||
repo: repo,
|
||||
repoName: getRepoName(opts),
|
||||
}
|
||||
return us
|
||||
}
|
||||
|
||||
// Scan kicks off an unstaged scan. This will attempt to determine unstaged changes which are then scanned.
|
||||
func (us *UnstagedScanner) Scan() (Report, error) {
|
||||
var scannerReport Report
|
||||
r, err := us.repo.Head()
|
||||
if err == plumbing.ErrReferenceNotFound {
|
||||
wt, err := us.repo.Worktree()
|
||||
if err != nil {
|
||||
return scannerReport, err
|
||||
}
|
||||
|
||||
status, err := wt.Status()
|
||||
if err != nil {
|
||||
return scannerReport, err
|
||||
}
|
||||
for fn := range status {
|
||||
workTreeBuf := bytes.NewBuffer(nil)
|
||||
workTreeFile, err := wt.Filesystem.Open(fn)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
|
||||
// Check if file is allow listed
|
||||
if us.cfg.Allowlist.FileAllowed(filepath.Base(fn)) ||
|
||||
us.cfg.Allowlist.PathAllowed(fn) {
|
||||
continue
|
||||
}
|
||||
// Check individual file path ONLY rules
|
||||
for _, rule := range us.cfg.Rules {
|
||||
if rule.HasFileOrPathLeakOnly(fn) {
|
||||
leak := NewLeak("", "Filename or path offender: "+ fn, defaultLineNumber)
|
||||
leak.Repo = us.repoName
|
||||
leak.File = fn
|
||||
leak.RepoURL = us.opts.RepoURL
|
||||
leak.LeakURL = leak.URL()
|
||||
leak.Rule = rule.Description
|
||||
leak.Tags = strings.Join(rule.Tags, ", ")
|
||||
leak.Log(us.opts)
|
||||
scannerReport.Leaks = append(scannerReport.Leaks, leak)
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
if _, err := io.Copy(workTreeBuf, workTreeFile); err != nil {
|
||||
return scannerReport, err
|
||||
}
|
||||
lineNumber := 0
|
||||
for _, line := range strings.Split(workTreeBuf.String(), "\n") {
|
||||
lineNumber++
|
||||
for _, rule := range us.cfg.Rules {
|
||||
offender := rule.Inspect(line)
|
||||
if offender == "" {
|
||||
continue
|
||||
}
|
||||
if us.cfg.Allowlist.RegexAllowed(line) ||
|
||||
rule.AllowList.FileAllowed(filepath.Base(workTreeFile.Name())) ||
|
||||
rule.AllowList.PathAllowed(workTreeFile.Name()) {
|
||||
continue
|
||||
}
|
||||
if rule.File.String() != "" && !rule.HasFileLeak(filepath.Base(workTreeFile.Name())) {
|
||||
continue
|
||||
}
|
||||
if rule.Path.String() != "" && !rule.HasFilePathLeak(filepath.Base(workTreeFile.Name())) {
|
||||
continue
|
||||
}
|
||||
leak := NewLeak(line, offender, defaultLineNumber).WithCommit(emptyCommit())
|
||||
leak.File = workTreeFile.Name()
|
||||
leak.LineNumber = lineNumber
|
||||
leak.Repo = us.repoName
|
||||
leak.Rule = rule.Description
|
||||
leak.Tags = strings.Join(rule.Tags, ", ")
|
||||
if us.opts.Verbose {
|
||||
leak.Log(us.opts)
|
||||
}
|
||||
scannerReport.Leaks = append(scannerReport.Leaks, leak)
|
||||
}
|
||||
}
|
||||
}
|
||||
return scannerReport, nil
|
||||
} else if err != nil {
|
||||
return scannerReport, err
|
||||
}
|
||||
|
||||
c, err := us.repo.CommitObject(r.Hash())
|
||||
if err != nil {
|
||||
return scannerReport, err
|
||||
}
|
||||
|
||||
// Staged change so the Commit details do not yet exist. Insert empty defaults.
|
||||
c.Hash = plumbing.Hash{}
|
||||
c.Message = ""
|
||||
c.Author.Name = ""
|
||||
c.Author.Email = ""
|
||||
c.Author.When = time.Unix(0, 0).UTC()
|
||||
|
||||
prevTree, err := c.Tree()
|
||||
if err != nil {
|
||||
return scannerReport, err
|
||||
}
|
||||
wt, err := us.repo.Worktree()
|
||||
if err != nil {
|
||||
return scannerReport, err
|
||||
}
|
||||
|
||||
status, err := gitStatus(wt)
|
||||
if err != nil {
|
||||
return scannerReport, err
|
||||
}
|
||||
for fn, state := range status {
|
||||
var (
|
||||
prevFileContents string
|
||||
currFileContents string
|
||||
filename string
|
||||
)
|
||||
|
||||
if state.Staging != git.Untracked {
|
||||
if state.Staging == git.Deleted {
|
||||
// file in staging has been deleted, aka it is not on the filesystem
|
||||
// so the contents of the file are ""
|
||||
currFileContents = ""
|
||||
} else {
|
||||
workTreeBuf := bytes.NewBuffer(nil)
|
||||
workTreeFile, err := wt.Filesystem.Open(fn)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
if _, err := io.Copy(workTreeBuf, workTreeFile); err != nil {
|
||||
return scannerReport, err
|
||||
}
|
||||
currFileContents = workTreeBuf.String()
|
||||
filename = workTreeFile.Name()
|
||||
}
|
||||
|
||||
// get files at HEAD state
|
||||
prevFile, err := prevTree.File(fn)
|
||||
if err != nil {
|
||||
prevFileContents = ""
|
||||
|
||||
} else {
|
||||
prevFileContents, err = prevFile.Contents()
|
||||
if err != nil {
|
||||
return scannerReport, err
|
||||
}
|
||||
if filename == "" {
|
||||
filename = prevFile.Name
|
||||
}
|
||||
}
|
||||
|
||||
dmp := diffmatchpatch.New()
|
||||
diffs := dmp.DiffMain(prevFileContents, currFileContents, false)
|
||||
prettyDiff := diffPrettyText(diffs)
|
||||
|
||||
var diffContents string
|
||||
for _, d := range diffs {
|
||||
if d.Type == diffmatchpatch.DiffInsert {
|
||||
diffContents += fmt.Sprintf("%s\n", d.Text)
|
||||
}
|
||||
}
|
||||
|
||||
lineLookup := make(map[string]bool)
|
||||
|
||||
for _, line := range strings.Split(diffContents, "\n") {
|
||||
for _, rule := range us.cfg.Rules {
|
||||
offender := rule.Inspect(line)
|
||||
if offender == "" {
|
||||
continue
|
||||
}
|
||||
if us.cfg.Allowlist.RegexAllowed(line) ||
|
||||
rule.AllowList.FileAllowed(filepath.Base(filename)) ||
|
||||
rule.AllowList.PathAllowed(filename) {
|
||||
continue
|
||||
}
|
||||
if rule.File.String() != "" && !rule.HasFileLeak(filepath.Base(filename)) {
|
||||
continue
|
||||
}
|
||||
if rule.Path.String() != "" && !rule.HasFilePathLeak(filepath.Base(filename)) {
|
||||
continue
|
||||
}
|
||||
leak := NewLeak(line, offender, defaultLineNumber).WithCommit(emptyCommit())
|
||||
leak.File = filename
|
||||
leak.LineNumber = extractLine(prettyDiff, leak, lineLookup) + 1
|
||||
leak.Repo = us.repoName
|
||||
leak.Rule = rule.Description
|
||||
leak.Tags = strings.Join(rule.Tags, ", ")
|
||||
|
||||
leak.Log(us.opts)
|
||||
|
||||
scannerReport.Leaks = append(scannerReport.Leaks, leak)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return scannerReport, err
|
||||
}
|
||||
|
||||
// DiffPrettyText converts a []Diff into a colored text report.
|
||||
// TODO open PR for this
|
||||
func diffPrettyText(diffs []diffmatchpatch.Diff) string {
|
||||
var buff bytes.Buffer
|
||||
for _, diff := range diffs {
|
||||
text := diff.Text
|
||||
|
||||
switch diff.Type {
|
||||
case diffmatchpatch.DiffInsert:
|
||||
_, _ = buff.WriteString("+")
|
||||
_, _ = buff.WriteString(text)
|
||||
case diffmatchpatch.DiffDelete:
|
||||
_, _ = buff.WriteString("-")
|
||||
_, _ = buff.WriteString(text)
|
||||
case diffmatchpatch.DiffEqual:
|
||||
_, _ = buff.WriteString(" ")
|
||||
_, _ = buff.WriteString(text)
|
||||
}
|
||||
}
|
||||
return buff.String()
|
||||
}
|
||||
|
||||
// gitStatus returns the status of modified files in the worktree. It will attempt to execute 'git status'
|
||||
// and will fall back to git.Worktree.Status() if that fails.
|
||||
func gitStatus(wt *git.Worktree) (git.Status, error) {
|
||||
c := exec.Command("git", "status", "--porcelain", "-z")
|
||||
c.Dir = wt.Filesystem.Root()
|
||||
output, err := c.Output()
|
||||
if err != nil {
|
||||
stat, err := wt.Status()
|
||||
return stat, err
|
||||
}
|
||||
|
||||
lines := strings.Split(string(output), "\000")
|
||||
stat := make(map[string]*git.FileStatus, len(lines))
|
||||
for _, line := range lines {
|
||||
if len(line) == 0 {
|
||||
continue
|
||||
}
|
||||
|
||||
// For copy/rename the output looks like
|
||||
// R destination\000source
|
||||
// Which means we can split on space and ignore anything with only one result
|
||||
parts := strings.SplitN(strings.TrimLeft(line, " "), " ", 2)
|
||||
if len(parts) == 2 {
|
||||
stat[strings.Trim(parts[1], " ")] = &git.FileStatus{
|
||||
Staging: git.StatusCode([]byte(parts[0])[0]),
|
||||
}
|
||||
}
|
||||
}
|
||||
return stat, err
|
||||
}
|
||||
+227
@@ -0,0 +1,227 @@
|
||||
package scan
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/zricethezav/gitleaks/v7/options"
|
||||
|
||||
"github.com/go-git/go-git/v5"
|
||||
"github.com/go-git/go-git/v5/plumbing"
|
||||
"github.com/go-git/go-git/v5/plumbing/object"
|
||||
"github.com/go-git/go-git/v5/storage/memory"
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
const (
|
||||
diffAddPrefix = "+"
|
||||
diffDelPrefix = "-"
|
||||
diffLineSignature = " @@"
|
||||
defaultLineNumber = 1
|
||||
)
|
||||
|
||||
func obtainCommit(repo *git.Repository, commitSha string) (*object.Commit, error) {
|
||||
if commitSha == "latest" {
|
||||
ref, err := repo.Head()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
commitSha = ref.Hash().String()
|
||||
}
|
||||
return repo.CommitObject(plumbing.NewHash(commitSha))
|
||||
}
|
||||
|
||||
func getRepoName(opts options.Options) string {
|
||||
if opts.RepoURL != "" {
|
||||
return filepath.Base(opts.RepoURL)
|
||||
}
|
||||
if opts.Path != "" {
|
||||
return filepath.Base(opts.Path)
|
||||
}
|
||||
if opts.CheckUncommitted() {
|
||||
dir, _ := os.Getwd()
|
||||
return filepath.Base(dir)
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func getRepo(opts options.Options) (*git.Repository, error) {
|
||||
if opts.OpenLocal() {
|
||||
if opts.Path != "" {
|
||||
log.Infof("opening %s\n", opts.Path)
|
||||
} else {
|
||||
log.Info("opening .")
|
||||
}
|
||||
return git.PlainOpen(opts.Path)
|
||||
}
|
||||
if opts.CheckUncommitted() {
|
||||
// open git repo from PWD
|
||||
dir, err := os.Getwd()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
log.Debugf("opening %s as a repo\n", dir)
|
||||
return git.PlainOpen(dir)
|
||||
}
|
||||
return cloneRepo(opts)
|
||||
}
|
||||
|
||||
func cloneRepo(opts options.Options) (*git.Repository, error) {
|
||||
cloneOpts, err := opts.CloneOptions()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if opts.ClonePath != "" {
|
||||
log.Infof("cloning... %s to %s", cloneOpts.URL, opts.ClonePath)
|
||||
return git.PlainClone(opts.ClonePath, false, cloneOpts)
|
||||
}
|
||||
log.Infof("cloning... %s", cloneOpts.URL)
|
||||
return git.Clone(memory.NewStorage(), nil, cloneOpts)
|
||||
}
|
||||
|
||||
// depthReached checks if i meets the depth (--depth=) if set
|
||||
func depthReached(i int, opts options.Options) bool {
|
||||
if opts.Depth != 0 && opts.Depth == i {
|
||||
log.Warnf("Exceeded depth limit (%d)", i)
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// emptyCommit generates an empty commit used for scanning uncommitted changes
|
||||
func emptyCommit() *object.Commit {
|
||||
return &object.Commit{
|
||||
Hash: plumbing.Hash{},
|
||||
Message: "",
|
||||
Author: object.Signature{
|
||||
Name: "",
|
||||
Email: "",
|
||||
When: time.Unix(0, 0).UTC(),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// howManyThreads will return a number 1-GOMAXPROCS which is the number
|
||||
// of goroutines that will spawn during gitleaks execution
|
||||
func howManyThreads(threads int) int {
|
||||
maxThreads := runtime.GOMAXPROCS(0)
|
||||
if threads == 0 {
|
||||
return 1
|
||||
} else if threads > maxThreads {
|
||||
log.Warnf("%d threads set too high, setting to system max, %d", threads, maxThreads)
|
||||
return maxThreads
|
||||
}
|
||||
return threads
|
||||
}
|
||||
|
||||
// getLogOptions determines what log options are used when iterating through commits.
|
||||
// It is similar to `git log {branch}`. Default behavior is to log ALL branches so
|
||||
// gitleaks gets the full git history.
|
||||
func logOptions(repo *git.Repository, opts options.Options) (*git.LogOptions, error) {
|
||||
var logOpts git.LogOptions
|
||||
const dateformat string = "2006-01-02"
|
||||
const timeformat string = "2006-01-02T15:04:05-0700"
|
||||
if opts.CommitFrom != "" {
|
||||
logOpts.From = plumbing.NewHash(opts.CommitFrom)
|
||||
}
|
||||
if opts.CommitSince != "" {
|
||||
if t, err := time.Parse(timeformat, opts.CommitSince); err == nil {
|
||||
logOpts.Since = &t
|
||||
} else if t, err := time.Parse(dateformat, opts.CommitSince); err == nil {
|
||||
logOpts.Since = &t
|
||||
} else {
|
||||
return nil, err
|
||||
}
|
||||
logOpts.All = true
|
||||
}
|
||||
if opts.CommitUntil != "" {
|
||||
if t, err := time.Parse(timeformat, opts.CommitUntil); err == nil {
|
||||
logOpts.Until = &t
|
||||
} else if t, err := time.Parse(dateformat, opts.CommitUntil); err == nil {
|
||||
logOpts.Until = &t
|
||||
} else {
|
||||
return nil, err
|
||||
}
|
||||
logOpts.All = true
|
||||
}
|
||||
if opts.Branch != "" {
|
||||
ref, err := repo.Storer.Reference(plumbing.NewBranchReferenceName(opts.Branch))
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("could not find branch %s", opts.Branch)
|
||||
}
|
||||
logOpts = git.LogOptions{
|
||||
From: ref.Hash(),
|
||||
}
|
||||
|
||||
if logOpts.From.IsZero() {
|
||||
return nil, fmt.Errorf("could not find branch %s", opts.Branch)
|
||||
}
|
||||
return &logOpts, nil
|
||||
}
|
||||
if !logOpts.From.IsZero() || logOpts.Since != nil || logOpts.Until != nil {
|
||||
return &logOpts, nil
|
||||
}
|
||||
return &git.LogOptions{All: true}, nil
|
||||
}
|
||||
|
||||
func optsToCommits(opts options.Options) ([]string, error) {
|
||||
if opts.Commits != "" {
|
||||
return strings.Split(opts.Commits, ","), nil
|
||||
}
|
||||
file, err := os.Open(opts.CommitsFile)
|
||||
if err != nil {
|
||||
return []string{}, err
|
||||
}
|
||||
defer rable(file.Close)
|
||||
|
||||
scanner := bufio.NewScanner(file)
|
||||
var commits []string
|
||||
for scanner.Scan() {
|
||||
commits = append(commits, scanner.Text())
|
||||
}
|
||||
return commits, nil
|
||||
}
|
||||
|
||||
func extractLine(patchContent string, leak Leak, lineLookup map[string]bool) int {
|
||||
i := strings.Index(patchContent, fmt.Sprintf("\n+++ b/%s", leak.File))
|
||||
filePatchContent := patchContent[i+1:]
|
||||
i = strings.Index(filePatchContent, "diff --git")
|
||||
if i != -1 {
|
||||
filePatchContent = filePatchContent[:i]
|
||||
}
|
||||
chunkStartLine := 0
|
||||
currLine := 0
|
||||
for _, patchLine := range strings.Split(filePatchContent, "\n") {
|
||||
if strings.HasPrefix(patchLine, "@@") {
|
||||
i := strings.Index(patchLine, diffAddPrefix)
|
||||
pairs := strings.Split(strings.Split(patchLine[i+1:], diffLineSignature)[0], ",")
|
||||
chunkStartLine, _ = strconv.Atoi(pairs[0])
|
||||
currLine = -1
|
||||
}
|
||||
if strings.HasPrefix(patchLine, diffDelPrefix) {
|
||||
currLine--
|
||||
}
|
||||
if strings.HasPrefix(patchLine, diffAddPrefix) && strings.Contains(patchLine, leak.Line) {
|
||||
lineNumber := chunkStartLine + currLine
|
||||
if _, ok := lineLookup[fmt.Sprintf("%s%s%d%s", leak.Offender, leak.Line, lineNumber, leak.File)]; !ok {
|
||||
lineLookup[fmt.Sprintf("%s%s%d%s", leak.Offender, leak.Line, lineNumber, leak.File)] = true
|
||||
return lineNumber
|
||||
}
|
||||
}
|
||||
currLine++
|
||||
}
|
||||
return defaultLineNumber
|
||||
}
|
||||
|
||||
// rable is the second half of deferrable... mainly used for defer file.Close()
|
||||
func rable(f func() error) {
|
||||
if err := f(); err != nil {
|
||||
log.Error(err)
|
||||
}
|
||||
}
|
||||
-234
@@ -1,234 +0,0 @@
|
||||
package gitleaks
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"os/user"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/BurntSushi/toml"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"gopkg.in/src-d/go-git.v4/plumbing/transport/ssh"
|
||||
)
|
||||
|
||||
type entropyRange struct {
|
||||
v1 float64
|
||||
v2 float64
|
||||
}
|
||||
|
||||
// Rule instructs how gitleaks should audit each line of code
|
||||
type Rule struct {
|
||||
description string
|
||||
regex *regexp.Regexp
|
||||
severity string
|
||||
tags []string
|
||||
entropies []*entropyRange
|
||||
entropyROI string
|
||||
fileTypes []*regexp.Regexp
|
||||
}
|
||||
|
||||
// TomlConfig is used for loading gitleaks configs from a toml file
|
||||
type TomlConfig struct {
|
||||
Rules []struct {
|
||||
Description string
|
||||
Regex string
|
||||
Entropies []string
|
||||
Tags []string
|
||||
Severity string
|
||||
EntropyROI string
|
||||
FileTypes []string
|
||||
}
|
||||
Whitelist struct {
|
||||
Files []string
|
||||
Regexes []string
|
||||
Commits []string
|
||||
Repos []string
|
||||
}
|
||||
}
|
||||
|
||||
// Config contains gitleaks config
|
||||
type Config struct {
|
||||
Rules []*Rule
|
||||
WhiteList struct {
|
||||
regexes []*regexp.Regexp
|
||||
files []*regexp.Regexp
|
||||
commits map[string]bool
|
||||
repos []*regexp.Regexp
|
||||
}
|
||||
FileRules []*Rule
|
||||
sshAuth *ssh.PublicKeys
|
||||
}
|
||||
|
||||
// loadToml loads of the toml config containing regexes and whitelists.
|
||||
// This function will first look if the configPath is set and load the config
|
||||
// from that file. Otherwise will then look for the path set by the GITHLEAKS_CONIFG
|
||||
// env var. If that is not set, then gitleaks will continue with the default configs
|
||||
// specified by the const var at the top `defaultConfig`
|
||||
func newConfig() (*Config, error) {
|
||||
var (
|
||||
tomlConfig TomlConfig
|
||||
configPath string
|
||||
config Config
|
||||
)
|
||||
|
||||
if opts.ConfigPath != "" {
|
||||
configPath = opts.ConfigPath
|
||||
_, err := os.Stat(configPath)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("no gitleaks config at %s", configPath)
|
||||
}
|
||||
} else {
|
||||
configPath = os.Getenv("GITLEAKS_CONFIG")
|
||||
}
|
||||
|
||||
if configPath != "" {
|
||||
if _, err := toml.DecodeFile(configPath, &tomlConfig); err != nil {
|
||||
return nil, fmt.Errorf("problem loading config: %v", err)
|
||||
}
|
||||
} else {
|
||||
_, err := toml.Decode(defaultConfig, &tomlConfig)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("problem loading default config: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
sshAuth, err := getSSHAuth()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
config.sshAuth = sshAuth
|
||||
|
||||
err = config.update(tomlConfig)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &config, err
|
||||
}
|
||||
|
||||
// updateConfig will update a the global config values
|
||||
func (config *Config) update(tomlConfig TomlConfig) error {
|
||||
for _, rule := range tomlConfig.Rules {
|
||||
re := regexp.MustCompile(rule.Regex)
|
||||
ranges, err := getEntropyRanges(rule.Entropies)
|
||||
var fileTypes = []*regexp.Regexp{}
|
||||
for _, regex := range rule.FileTypes {
|
||||
fileTypes = append(fileTypes, regexp.MustCompile(regex))
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
log.Errorf("could not create entropy range for %s, skipping rule", rule.Description)
|
||||
continue
|
||||
}
|
||||
|
||||
r := &Rule{
|
||||
description: rule.Description,
|
||||
regex: re,
|
||||
severity: rule.Severity,
|
||||
tags: rule.Tags,
|
||||
entropies: ranges,
|
||||
entropyROI: rule.EntropyROI,
|
||||
fileTypes: fileTypes,
|
||||
}
|
||||
|
||||
if len(rule.Entropies) == 0 && rule.Regex == "" && len(fileTypes) != 0 {
|
||||
config.FileRules = append(config.FileRules, r)
|
||||
}
|
||||
config.Rules = append(config.Rules, r)
|
||||
|
||||
}
|
||||
|
||||
// set whitelists
|
||||
config.WhiteList.commits = make(map[string]bool)
|
||||
for _, commit := range tomlConfig.Whitelist.Commits {
|
||||
config.WhiteList.commits[commit] = true
|
||||
}
|
||||
for _, regex := range tomlConfig.Whitelist.Files {
|
||||
config.WhiteList.files = append(config.WhiteList.files, regexp.MustCompile(regex))
|
||||
}
|
||||
for _, regex := range tomlConfig.Whitelist.Regexes {
|
||||
config.WhiteList.regexes = append(config.WhiteList.regexes, regexp.MustCompile(regex))
|
||||
}
|
||||
for _, regex := range tomlConfig.Whitelist.Repos {
|
||||
config.WhiteList.repos = append(config.WhiteList.repos, regexp.MustCompile(regex))
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// entropyRanges hydrates entropyRanges which allows for fine tuning entropy checking
|
||||
func getEntropyRanges(entropyLimitStr []string) ([]*entropyRange, error) {
|
||||
var ranges []*entropyRange
|
||||
for _, span := range entropyLimitStr {
|
||||
split := strings.Split(span, "-")
|
||||
v1, err := strconv.ParseFloat(split[0], 64)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
v2, err := strconv.ParseFloat(split[1], 64)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if v1 > v2 {
|
||||
return nil, fmt.Errorf("entropy range must be ascending")
|
||||
}
|
||||
r := &entropyRange{
|
||||
v1: v1,
|
||||
v2: v2,
|
||||
}
|
||||
if r.v1 > 8.0 || r.v1 < 0.0 || r.v2 > 8.0 || r.v2 < 0.0 {
|
||||
return nil, fmt.Errorf("invalid entropy ranges, must be within 0.0-8.0")
|
||||
}
|
||||
ranges = append(ranges, r)
|
||||
}
|
||||
return ranges, nil
|
||||
}
|
||||
|
||||
// externalConfig will attempt to load a pinned ".gitleaks.toml" configuration file
|
||||
// from a remote or local repo. Use the --repo-config option to trigger this.
|
||||
func (config *Config) updateFromRepo(repo *Repo) error {
|
||||
var tomlConfig TomlConfig
|
||||
wt, err := repo.repository.Worktree()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
f, err := wt.Filesystem.Open(".gitleaks.toml")
|
||||
defer f.Close()
|
||||
if err != nil {
|
||||
return fmt.Errorf("problem loading config: %v", err)
|
||||
}
|
||||
if _, err := toml.DecodeReader(f, &tomlConfig); err != nil {
|
||||
return fmt.Errorf("problem loading config: %v", err)
|
||||
}
|
||||
|
||||
return config.update(tomlConfig)
|
||||
}
|
||||
|
||||
// getSSHAuth return an ssh auth use by go-git to clone repos behind authentication.
|
||||
// If --ssh-key is set then it will attempt to load the key from that path. If not,
|
||||
// gitleaks will use the default $HOME/.ssh/id_rsa key
|
||||
func getSSHAuth() (*ssh.PublicKeys, error) {
|
||||
var (
|
||||
sshKeyPath string
|
||||
)
|
||||
if opts.SSHKey != "" {
|
||||
sshKeyPath = opts.SSHKey
|
||||
} else {
|
||||
// try grabbing default
|
||||
c, err := user.Current()
|
||||
if err != nil {
|
||||
return nil, nil
|
||||
}
|
||||
sshKeyPath = fmt.Sprintf("%s/.ssh/id_rsa", c.HomeDir)
|
||||
}
|
||||
sshAuth, err := ssh.NewPublicKeysFromFile("git", sshKeyPath, "")
|
||||
if err != nil {
|
||||
if strings.HasPrefix(opts.Repo, "git") {
|
||||
// if you are attempting to clone a git repo via ssh and supply a bad ssh key,
|
||||
// the clone will fail.
|
||||
return nil, fmt.Errorf("unable to generate ssh key: %v", err)
|
||||
}
|
||||
}
|
||||
return sshAuth, nil
|
||||
}
|
||||
@@ -1,207 +0,0 @@
|
||||
package gitleaks
|
||||
|
||||
const version = "2.1.0"
|
||||
|
||||
const NoLeaks = 0
|
||||
|
||||
const defaultGithubURL = "https://api.github.com/"
|
||||
const defaultThreadNum = 1
|
||||
|
||||
// ErrExit used to signal an error during gitleaks execution
|
||||
const ErrExit = 2
|
||||
|
||||
// LeakExit used to signal leaks present in audit
|
||||
const LeakExit = 1
|
||||
|
||||
const defaultConfig = `
|
||||
# This is a sample config file for gitleaks. You can configure gitleaks what to search for and what to whitelist.
|
||||
# The output you are seeing here is the default gitleaks config. If GITLEAKS_CONFIG environment variable
|
||||
# is set, gitleaks will load configurations from that path. If option --config is set, gitleaks will load
|
||||
# configurations from that path. Gitleaks does not whitelist anything by default.
|
||||
# - https://www.ndss-symposium.org/wp-content/uploads/2019/02/ndss2019_04B-3_Meli_paper.pdf
|
||||
# - https://github.com/dxa4481/truffleHogRegexes/blob/master/truffleHogRegexes/regexes.json
|
||||
|
||||
title = "gitleaks config"
|
||||
[[rules]]
|
||||
description = "AWS Client ID"
|
||||
regex = '''(A3T[A-Z0-9]|AKIA|AGPA|AIDA|AROA|AIPA|ANPA|ANVA|ASIA)[A-Z0-9]{16}'''
|
||||
tags = ["key", "AWS"]
|
||||
|
||||
[[rules]]
|
||||
description = "AWS Secret Key"
|
||||
regex = '''(?i)aws(.{0,20})?(?-i)['\"][0-9a-zA-Z\/+]{40}['\"]'''
|
||||
tags = ["key", "AWS"]
|
||||
|
||||
[[rules]]
|
||||
description = "AWS MWS key"
|
||||
regex = '''amzn\.mws\.[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}'''
|
||||
tags = ["key", "AWS", "MWS"]
|
||||
|
||||
[[rules]]
|
||||
description = "PKCS8"
|
||||
regex = '''-----BEGIN PRIVATE KEY-----'''
|
||||
tags = ["key", "PKCS8"]
|
||||
|
||||
[[rules]]
|
||||
description = "RSA"
|
||||
regex = '''-----BEGIN RSA PRIVATE KEY-----'''
|
||||
tags = ["key", "RSA"]
|
||||
|
||||
[[rules]]
|
||||
description = "SSH"
|
||||
regex = '''-----BEGIN OPENSSH PRIVATE KEY-----'''
|
||||
tags = ["key", "SSH"]
|
||||
|
||||
[[rules]]
|
||||
description = "PGP"
|
||||
regex = '''-----BEGIN PGP PRIVATE KEY BLOCK-----'''
|
||||
tags = ["key", "PGP"]
|
||||
|
||||
[[rules]]
|
||||
description = "Facebook Secret Key"
|
||||
regex = '''(?i)(facebook|fb)(.{0,20})?(?-i)['\"][0-9a-f]{32}['\"]'''
|
||||
tags = ["key", "Facebook"]
|
||||
|
||||
[[rules]]
|
||||
description = "Facebook Client ID"
|
||||
regex = '''(?i)(facebook|fb)(.{0,20})?['\"][0-9]{13,17}['\"]'''
|
||||
tags = ["key", "Facebook"]
|
||||
|
||||
[[rules]]
|
||||
description = "Facebook access token"
|
||||
regex = '''EAACEdEose0cBA[0-9A-Za-z]+'''
|
||||
tags = ["key", "Facebook"]
|
||||
|
||||
[[rules]]
|
||||
description = "Twitter Secret Key"
|
||||
regex = '''(?i)twitter(.{0,20})?['\"][0-9a-z]{35,44}['\"]'''
|
||||
tags = ["key", "Twitter"]
|
||||
|
||||
[[rules]]
|
||||
description = "Twitter Client ID"
|
||||
regex = '''(?i)twitter(.{0,20})?['\"][0-9a-z]{18,25}['\"]'''
|
||||
tags = ["client", "Twitter"]
|
||||
|
||||
[[rules]]
|
||||
description = "Github"
|
||||
regex = '''(?i)github(.{0,20})?(?-i)['\"][0-9a-zA-Z]{35,40}['\"]'''
|
||||
tags = ["key", "Github"]
|
||||
|
||||
[[rules]]
|
||||
description = "LinkedIn Client ID"
|
||||
regex = '''(?i)linkedin(.{0,20})?(?-i)['\"][0-9a-z]{12}['\"]'''
|
||||
tags = ["client", "Twitter"]
|
||||
|
||||
[[rules]]
|
||||
description = "LinkedIn Secret Key"
|
||||
regex = '''(?i)linkedin(.{0,20})?['\"][0-9a-z]{16}['\"]'''
|
||||
tags = ["secret", "Twitter"]
|
||||
|
||||
[[rules]]
|
||||
description = "Slack"
|
||||
regex = '''xox[baprs]-([0-9a-zA-Z]{10,48})?'''
|
||||
tags = ["key", "Slack"]
|
||||
|
||||
[[rules]]
|
||||
description = "EC"
|
||||
regex = '''-----BEGIN EC PRIVATE KEY-----'''
|
||||
tags = ["key", "EC"]
|
||||
|
||||
[[rules]]
|
||||
description = "Generic API key"
|
||||
regex = '''(?i)(api_key|apikey)(.{0,20})?['|"][0-9a-zA-Z]{32,45}['|"]'''
|
||||
tags = ["key", "API", "generic"]
|
||||
|
||||
[[rules]]
|
||||
description = "Generic Secret"
|
||||
regex = '''(?i)secret(.{0,20})?['|"][0-9a-zA-Z]{32,45}['|"]'''
|
||||
tags = ["key", "Secret", "generic"]
|
||||
|
||||
[[rules]]
|
||||
description = "Google API key"
|
||||
regex = '''AIza[0-9A-Za-z\\-_]{35}'''
|
||||
tags = ["key", "Google"]
|
||||
|
||||
[[rules]]
|
||||
description = "Google Cloud Platform API key"
|
||||
regex = '''(?i)(google|gcp|youtube|drive|yt)(.{0,20})?['\"][AIza[0-9a-z\\-_]{35}]['\"]'''
|
||||
tags = ["key", "Google", "GCP"]
|
||||
|
||||
[[rules]]
|
||||
description = "Google OAuth"
|
||||
regex = '''(?i)(google|gcp|auth)(.{0,20})?['"][0-9]+-[0-9a-z_]{32}\.apps\.googleusercontent\.com['"]'''
|
||||
tags = ["key", "Google", "OAuth"]
|
||||
|
||||
[[rules]]
|
||||
description = "Google OAuth access token"
|
||||
regex = '''ya29\.[0-9A-Za-z\-_]+'''
|
||||
tags = ["key", "Google", "OAuth"]
|
||||
|
||||
[[rules]]
|
||||
description = "Heroku API key"
|
||||
regex = '''(?i)heroku(.{0,20})?['"][0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}['"]'''
|
||||
tags = ["key", "Heroku"]
|
||||
|
||||
[[rules]]
|
||||
description = "MailChimp API key"
|
||||
regex = '''(?i)(mailchimp|mc)(.{0,20})?['"][0-9a-f]{32}-us[0-9]{1,2}['"]'''
|
||||
tags = ["key", "Mailchimp"]
|
||||
|
||||
[[rules]]
|
||||
description = "Mailgun API key"
|
||||
regex = '''(?i)(mailgun|mg)(.{0,20})?['"][0-9a-z]{32}['"]'''
|
||||
tags = ["key", "Mailgun"]
|
||||
|
||||
[[rules]]
|
||||
description = "Password in URL"
|
||||
regex = '''[a-zA-Z]{3,10}:\/\/[^\/\s:@]{3,20}:[^\/\s:@]{3,20}@.{1,100}\/?.?'''
|
||||
tags = ["key", "URL", "generic"]
|
||||
|
||||
[[rules]]
|
||||
description = "PayPal Braintree access token"
|
||||
regex = '''access_token\$production\$[0-9a-z]{16}\$[0-9a-f]{32}'''
|
||||
tags = ["key", "Paypal"]
|
||||
|
||||
[[rules]]
|
||||
description = "Picatic API key"
|
||||
regex = '''sk_live_[0-9a-z]{32}'''
|
||||
tags = ["key", "Picatic"]
|
||||
|
||||
[[rules]]
|
||||
description = "Slack Webhook"
|
||||
regex = '''https://hooks.slack.com/services/T[a-zA-Z0-9_]{8}/B[a-zA-Z0-9_]{8}/[a-zA-Z0-9_]{24}'''
|
||||
tags = ["key", "slack"]
|
||||
|
||||
[[rules]]
|
||||
description = "Stripe API key"
|
||||
regex = '''(?i)stripe(.{0,20})?['\"][sk|rk]_live_[0-9a-zA-Z]{24}'''
|
||||
tags = ["key", "Stripe"]
|
||||
|
||||
[[rules]]
|
||||
description = "Square access token"
|
||||
regex = '''sq0atp-[0-9A-Za-z\-_]{22}'''
|
||||
tags = ["key", "square"]
|
||||
|
||||
[[rules]]
|
||||
description = "Square OAuth secret"
|
||||
regex = '''sq0csp-[0-9A-Za-z\\-_]{43}'''
|
||||
tags = ["key", "square"]
|
||||
|
||||
[[rules]]
|
||||
description = "Twilio API key"
|
||||
regex = '''(?i)twilio(.{0,20})?['\"][0-9a-f]{32}['\"]'''
|
||||
tags = ["key", "twilio"]
|
||||
|
||||
[whitelist]
|
||||
files = [
|
||||
"(.*?)(jpg|gif|doc|pdf|bin)$"
|
||||
]
|
||||
|
||||
#commits = [
|
||||
# "whitelisted-commit1",
|
||||
# "whitelisted-commit2",
|
||||
#]
|
||||
#repos = [
|
||||
# "whitelisted-repo"
|
||||
#]
|
||||
`
|
||||
@@ -1,123 +0,0 @@
|
||||
package gitleaks
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"path"
|
||||
)
|
||||
|
||||
const testWhitelistCommit = `
|
||||
[[rules]]
|
||||
description = "AWS"
|
||||
regex = '''AKIA[0-9A-Z]{16}'''
|
||||
|
||||
[whitelist]
|
||||
commits = [
|
||||
"eaeffdc65b4c73ccb67e75d96bd8743be2c85973",
|
||||
]
|
||||
`
|
||||
const testWhitelistFile = `
|
||||
[[rules]]
|
||||
description = "AWS"
|
||||
regex = '''AKIA[0-9A-Z]{16}'''
|
||||
|
||||
[whitelist]
|
||||
files = [
|
||||
".go",
|
||||
]
|
||||
`
|
||||
|
||||
const testWhitelistRegex = `
|
||||
[[rules]]
|
||||
description = "AWS"
|
||||
regex = '''AKIA[0-9A-Z]{16}'''
|
||||
|
||||
[whitelist]
|
||||
regexes= [
|
||||
"AKIA",
|
||||
]
|
||||
`
|
||||
|
||||
const testWhitelistRepo = `
|
||||
[[rules]]
|
||||
description = "AWS"
|
||||
regex = '''AKIA[0-9A-Z]{16}'''
|
||||
|
||||
[whitelist]
|
||||
repos = [
|
||||
"gronit",
|
||||
]
|
||||
`
|
||||
|
||||
const testEntropyRange = `
|
||||
[[rules]]
|
||||
description = "Entropy ranges"
|
||||
entropies = [
|
||||
"7.5-8.0",
|
||||
"3.2-3.4",
|
||||
]
|
||||
`
|
||||
const testBadEntropyRange = `
|
||||
[[rules]]
|
||||
description = "Bad entropy ranges"
|
||||
entropies = [
|
||||
"8.0-3.0",
|
||||
]
|
||||
`
|
||||
const testBadEntropyRange2 = `
|
||||
[[rules]]
|
||||
description = "Bad entropy ranges"
|
||||
entropies = [
|
||||
"8.0-8.9",
|
||||
]
|
||||
`
|
||||
|
||||
const testEntropyWordRegexRange = `
|
||||
[[rules]]
|
||||
description = "test entropy regex ranges"
|
||||
regex = '''(?i)key(.{0,6})?(:|=|=>|:=)'''
|
||||
entropies = [
|
||||
"4.1-4.3",
|
||||
]
|
||||
entropyROI="word"
|
||||
`
|
||||
|
||||
const testEntropyRegexRange = `
|
||||
[[rules]]
|
||||
description = "test entropy regex ranges"
|
||||
regex = '''(?i)key(.{0,6})?(:|=|=>|:=)'''
|
||||
entropies = [
|
||||
"4.1-4.3",
|
||||
]
|
||||
`
|
||||
|
||||
const testMDFileType = `
|
||||
[[rules]]
|
||||
description = "test only markdown"
|
||||
filetypes = [".md"]
|
||||
`
|
||||
|
||||
const testEntropyRegexRangeGoFilter = `
|
||||
[[rules]]
|
||||
description = "test entropy regex ranges"
|
||||
regex = '''(?i)key(.{0,6})?(:|=|=>|:=)'''
|
||||
entropies = [
|
||||
"4.1-4.3",
|
||||
]
|
||||
filetypes = [".go"]
|
||||
`
|
||||
|
||||
func testTomlLoader() string {
|
||||
tmpDir, _ := ioutil.TempDir("", "whiteListConfigs")
|
||||
ioutil.WriteFile(path.Join(tmpDir, "regex"), []byte(testWhitelistRegex), 0644)
|
||||
ioutil.WriteFile(path.Join(tmpDir, "entropyWordRegex"), []byte(testEntropyWordRegexRange), 0644)
|
||||
ioutil.WriteFile(path.Join(tmpDir, "entropyRegex"), []byte(testEntropyRegexRange), 0644)
|
||||
ioutil.WriteFile(path.Join(tmpDir, "commit"), []byte(testWhitelistCommit), 0644)
|
||||
ioutil.WriteFile(path.Join(tmpDir, "file"), []byte(testWhitelistFile), 0644)
|
||||
ioutil.WriteFile(path.Join(tmpDir, "repo"), []byte(testWhitelistRepo), 0644)
|
||||
ioutil.WriteFile(path.Join(tmpDir, "entropy"), []byte(testEntropyRange), 0644)
|
||||
ioutil.WriteFile(path.Join(tmpDir, "badEntropy"), []byte(testBadEntropyRange), 0644)
|
||||
ioutil.WriteFile(path.Join(tmpDir, "badEntropy2"), []byte(testBadEntropyRange2), 0644)
|
||||
ioutil.WriteFile(path.Join(tmpDir, "mdFiles"), []byte(testMDFileType), 0644)
|
||||
ioutil.WriteFile(path.Join(tmpDir, "entropyRegexGo"), []byte(testEntropyRegexRangeGoFilter), 0644)
|
||||
return tmpDir
|
||||
}
|
||||
-107
@@ -1,107 +0,0 @@
|
||||
package gitleaks
|
||||
|
||||
import (
|
||||
log "github.com/sirupsen/logrus"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"sync"
|
||||
)
|
||||
|
||||
var (
|
||||
opts *Options
|
||||
config *Config
|
||||
dir string
|
||||
threads int
|
||||
totalCommits int64
|
||||
mutex = &sync.Mutex{}
|
||||
)
|
||||
|
||||
func init() {
|
||||
log.SetOutput(os.Stdout)
|
||||
threads = defaultThreadNum
|
||||
}
|
||||
|
||||
// Report can be exported as a json or csv. Used for logging informationn
|
||||
// about the audit, (duration and # of commits)
|
||||
type Report struct {
|
||||
Leaks []Leak
|
||||
Duration string
|
||||
Commits int64
|
||||
}
|
||||
|
||||
// Run is the entry point for gitleaks
|
||||
func Run(optsL *Options) (int, error) {
|
||||
var (
|
||||
err error
|
||||
leaks []Leak
|
||||
)
|
||||
|
||||
opts = optsL
|
||||
config, err = newConfig()
|
||||
if err != nil {
|
||||
return NoLeaks, err
|
||||
}
|
||||
|
||||
if opts.Disk {
|
||||
// temporary directory where all the gitleaks plain clones will reside
|
||||
dir, err = ioutil.TempDir("", "gitleaks")
|
||||
defer os.RemoveAll(dir)
|
||||
if err != nil {
|
||||
return NoLeaks, err
|
||||
}
|
||||
}
|
||||
|
||||
// start audits
|
||||
if opts.Repo != "" || opts.RepoPath != "" {
|
||||
var repo *Repo
|
||||
repo, err = newRepo()
|
||||
if err != nil {
|
||||
return NoLeaks, err
|
||||
}
|
||||
err = repo.clone()
|
||||
if err != nil {
|
||||
return NoLeaks, err
|
||||
}
|
||||
err = repo.audit()
|
||||
if err != nil {
|
||||
return NoLeaks, err
|
||||
}
|
||||
repo.report()
|
||||
leaks = repo.leaks
|
||||
} else if opts.OwnerPath != "" {
|
||||
var repos []*Repo
|
||||
repos, err = discoverRepos(opts.OwnerPath)
|
||||
if err != nil {
|
||||
return NoLeaks, err
|
||||
}
|
||||
for _, repo := range repos {
|
||||
err = repo.clone()
|
||||
if err != nil {
|
||||
log.Warnf("error occurred cloning repo: %s, continuing to next repo", repo.name)
|
||||
continue
|
||||
}
|
||||
err = repo.audit()
|
||||
if err != nil {
|
||||
log.Warnf("error occurred auditing repo: %s, continuing to next repo", repo.name)
|
||||
continue
|
||||
}
|
||||
repo.report()
|
||||
leaks = append(leaks, repo.leaks...)
|
||||
}
|
||||
} else if opts.GithubOrg != "" || opts.GithubUser != "" {
|
||||
return auditGithubRepos()
|
||||
} else if opts.GitLabOrg != "" || opts.GitLabUser != "" {
|
||||
return auditGitlabRepos()
|
||||
} else if opts.GithubPR != "" {
|
||||
return auditGithubPR()
|
||||
}
|
||||
|
||||
if opts.Report != "" {
|
||||
err = writeReport(leaks)
|
||||
if err != nil {
|
||||
return NoLeaks, err
|
||||
}
|
||||
}
|
||||
|
||||
return len(leaks), nil
|
||||
}
|
||||
@@ -1,25 +0,0 @@
|
||||
package gitleaks
|
||||
|
||||
import (
|
||||
"math"
|
||||
)
|
||||
|
||||
// getShannonEntropy https://en.wiktionary.org/wiki/Shannon_entropy
|
||||
func getShannonEntropy(data string) (entropy float64) {
|
||||
if data == "" {
|
||||
return 0
|
||||
}
|
||||
|
||||
charCounts := make(map[rune]int)
|
||||
for _, char := range data {
|
||||
charCounts[char]++
|
||||
}
|
||||
|
||||
invLength := 1.0 / float64(len(data))
|
||||
for _, count := range charCounts {
|
||||
freq := float64(count) * invLength
|
||||
entropy -= freq * math.Log2(freq)
|
||||
}
|
||||
|
||||
return entropy
|
||||
}
|
||||
-285
@@ -1,285 +0,0 @@
|
||||
package gitleaks
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/google/go-github/github"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"golang.org/x/oauth2"
|
||||
"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"
|
||||
)
|
||||
|
||||
var githubPages = 100
|
||||
|
||||
// auditPR audits a single github PR
|
||||
func auditGithubPR() (int, error) {
|
||||
var leaks []Leak
|
||||
ctx := context.Background()
|
||||
githubClient := github.NewClient(githubToken())
|
||||
splits := strings.Split(opts.GithubPR, "/")
|
||||
owner := splits[len(splits)-4]
|
||||
repo := splits[len(splits)-3]
|
||||
prNum, err := strconv.Atoi(splits[len(splits)-1])
|
||||
if err != nil {
|
||||
return NoLeaks, err
|
||||
}
|
||||
|
||||
page := 1
|
||||
for {
|
||||
commits, resp, err := githubClient.PullRequests.ListCommits(ctx, owner, repo, prNum, &github.ListOptions{
|
||||
PerPage: githubPages,
|
||||
Page: page,
|
||||
})
|
||||
if err != nil {
|
||||
return NoLeaks, err
|
||||
}
|
||||
|
||||
for _, c := range commits {
|
||||
totalCommits = totalCommits + 1
|
||||
c, _, err := githubClient.Repositories.GetCommit(ctx, owner, repo, *c.SHA)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
files := c.Files
|
||||
for _, f := range files {
|
||||
skipFile := false
|
||||
if f.Patch == nil || f.Filename == nil {
|
||||
continue
|
||||
}
|
||||
for _, re := range config.WhiteList.files {
|
||||
if re.FindString(f.GetFilename()) != "" {
|
||||
log.Infof("skipping whitelisted file (matched regex '%s'): %s", re.String(), f.GetFilename())
|
||||
skipFile = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if skipFile {
|
||||
continue
|
||||
}
|
||||
|
||||
commit := &Commit{
|
||||
sha: c.GetSHA(),
|
||||
content: *f.Patch,
|
||||
filePath: *f.Filename,
|
||||
repoName: repo,
|
||||
author: c.GetCommitter().GetLogin(),
|
||||
message: *c.Commit.Message,
|
||||
date: *c.Commit.Committer.Date,
|
||||
}
|
||||
leaks = append(leaks, inspect(commit)...)
|
||||
}
|
||||
}
|
||||
page = resp.NextPage
|
||||
if resp.LastPage == 0 {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if len(leaks) != 0 {
|
||||
log.Warnf("%d leaks detected. %d commits inspected for PR: %s", len(leaks), totalCommits, opts.GithubPR)
|
||||
}
|
||||
|
||||
if opts.Report != "" {
|
||||
err = writeReport(leaks)
|
||||
if err != nil {
|
||||
return NoLeaks, err
|
||||
}
|
||||
}
|
||||
|
||||
return len(leaks), nil
|
||||
}
|
||||
|
||||
// auditGithubRepos kicks off audits if --github-user or --github-org options are set.
|
||||
// First, we gather all the github repositories from the github api (this doesnt actually clone the repo).
|
||||
// After all the repos have been pulled from github's api we proceed to audit the repos by calling auditGithubRepo.
|
||||
// If an error occurs during an audit of a repo, that error is logged but won't break the execution cycle.
|
||||
func auditGithubRepos() (int, error) {
|
||||
var (
|
||||
err error
|
||||
githubRepos []*github.Repository
|
||||
pagedGithubRepos []*github.Repository
|
||||
resp *github.Response
|
||||
githubOrgOptions *github.RepositoryListByOrgOptions
|
||||
githubOptions *github.RepositoryListOptions
|
||||
done bool
|
||||
ownerDir string
|
||||
leaks []Leak
|
||||
)
|
||||
ctx := context.Background()
|
||||
githubClient := github.NewClient(githubToken())
|
||||
|
||||
if opts.GithubOrg != "" {
|
||||
if opts.GithubURL != "" && opts.GithubURL != defaultGithubURL {
|
||||
ghURL, _ := url.Parse(opts.GithubURL)
|
||||
githubClient.BaseURL = ghURL
|
||||
}
|
||||
githubOrgOptions = &github.RepositoryListByOrgOptions{
|
||||
ListOptions: github.ListOptions{PerPage: 100},
|
||||
}
|
||||
} else if opts.GithubUser != "" {
|
||||
if opts.GithubURL != "" && opts.GithubURL != defaultGithubURL {
|
||||
ghURL, _ := url.Parse(opts.GithubURL)
|
||||
githubClient.BaseURL = ghURL
|
||||
}
|
||||
|
||||
githubOptions = &github.RepositoryListOptions{
|
||||
Affiliation: "owner",
|
||||
ListOptions: github.ListOptions{
|
||||
PerPage: 100,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
for {
|
||||
if done {
|
||||
break
|
||||
}
|
||||
if opts.GithubUser != "" {
|
||||
pagedGithubRepos, resp, err = githubClient.Repositories.List(ctx, opts.GithubUser, githubOptions)
|
||||
if err != nil {
|
||||
done = true
|
||||
}
|
||||
githubOptions.Page = resp.NextPage
|
||||
githubRepos = append(githubRepos, pagedGithubRepos...)
|
||||
if resp.NextPage == 0 {
|
||||
done = true
|
||||
}
|
||||
} else if opts.GithubOrg != "" {
|
||||
pagedGithubRepos, resp, err = githubClient.Repositories.ListByOrg(ctx, opts.GithubOrg, githubOrgOptions)
|
||||
if err != nil {
|
||||
done = true
|
||||
}
|
||||
githubOrgOptions.Page = resp.NextPage
|
||||
githubRepos = append(githubRepos, pagedGithubRepos...)
|
||||
if resp.NextPage == 0 {
|
||||
done = true
|
||||
}
|
||||
}
|
||||
if opts.Log == "Debug" || opts.Log == "debug" {
|
||||
for _, githubRepo := range pagedGithubRepos {
|
||||
log.Debugf("staging repos %s", *githubRepo.Name)
|
||||
}
|
||||
}
|
||||
}
|
||||
if opts.Disk {
|
||||
ownerDir, _ = ioutil.TempDir(dir, opts.GithubUser)
|
||||
}
|
||||
for _, githubRepo := range githubRepos {
|
||||
repo, err := cloneGithubRepo(githubRepo)
|
||||
if err != nil {
|
||||
log.Warn(err)
|
||||
continue
|
||||
}
|
||||
err = repo.audit()
|
||||
if err != nil {
|
||||
log.Warnf("error occurred during audit of repo: %s, err: %v, continuing github audit", repo.name, err)
|
||||
}
|
||||
if opts.Disk {
|
||||
os.RemoveAll(fmt.Sprintf("%s/%s", ownerDir, *githubRepo.Name))
|
||||
}
|
||||
|
||||
repo.report()
|
||||
|
||||
leaks = append(leaks, repo.leaks...)
|
||||
}
|
||||
|
||||
if opts.Report != "" {
|
||||
err = writeReport(leaks)
|
||||
if err != nil {
|
||||
return NoLeaks, err
|
||||
}
|
||||
}
|
||||
|
||||
return len(leaks), nil
|
||||
}
|
||||
|
||||
// cloneGithubRepo clones a repo from the url parsed from a github repo. The repo
|
||||
// will be cloned to disk if --disk is set.
|
||||
func cloneGithubRepo(githubRepo *github.Repository) (*Repo, error) {
|
||||
var (
|
||||
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)
|
||||
}
|
||||
for _, re := range config.WhiteList.repos {
|
||||
if re.FindString(*githubRepo.Name) != "" {
|
||||
return nil, fmt.Errorf("skipping %s, whitelisted", *githubRepo.Name)
|
||||
}
|
||||
}
|
||||
log.Infof("cloning: %s", *githubRepo.Name)
|
||||
if opts.Disk {
|
||||
ownerDir, err := ioutil.TempDir(dir, opts.GithubUser)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("unable to generater owner temp dir: %v", err)
|
||||
}
|
||||
if config.sshAuth != nil && githubToken == "" {
|
||||
repo, err = git.PlainClone(fmt.Sprintf("%s/%s", ownerDir, *githubRepo.Name), false, &git.CloneOptions{
|
||||
URL: *githubRepo.SSHURL,
|
||||
Auth: config.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 config.sshAuth != nil && githubToken == "" {
|
||||
repo, err = git.Clone(memory.NewStorage(), nil, &git.CloneOptions{
|
||||
URL: *githubRepo.SSHURL,
|
||||
Auth: config.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,
|
||||
})
|
||||
}
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &Repo{
|
||||
repository: repo,
|
||||
name: *githubRepo.Name,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// githubToken returns an oauth2 client for the github api to consume. This token is necessary
|
||||
// if you are running audits with --github-user or --github-org
|
||||
func githubToken() *http.Client {
|
||||
githubToken := os.Getenv("GITHUB_TOKEN")
|
||||
if githubToken == "" {
|
||||
return nil
|
||||
}
|
||||
ts := oauth2.StaticTokenSource(
|
||||
&oauth2.Token{AccessToken: githubToken},
|
||||
)
|
||||
return oauth2.NewClient(context.Background(), ts)
|
||||
}
|
||||
-178
@@ -1,178 +0,0 @@
|
||||
package gitleaks
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
"github.com/xanzy/go-gitlab"
|
||||
"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"
|
||||
)
|
||||
|
||||
// gitlabPages number of records per request
|
||||
const gitlabPages = 100
|
||||
|
||||
// auditGitlabRepos kicks off audits if --gitlab-user or --gitlab-org options are set.
|
||||
// Getting all repositories from the GitLab API and run audit. If an error occurs during an audit of a repo,
|
||||
// that error is logged.
|
||||
func auditGitlabRepos() (int, error) {
|
||||
var (
|
||||
ps []*gitlab.Project
|
||||
resp *gitlab.Response
|
||||
tempDir string
|
||||
err error
|
||||
leaks []Leak
|
||||
)
|
||||
|
||||
repos := make([]*gitlab.Project, 0, gitlabPages)
|
||||
page := 1
|
||||
cl := gitlab.NewClient(nil, os.Getenv("GITLAB_TOKEN"))
|
||||
|
||||
// if self hosted GitLab server
|
||||
if url := os.Getenv("GITLAB_URL"); url != "" {
|
||||
cl.SetBaseURL(url)
|
||||
}
|
||||
|
||||
for {
|
||||
if opts.GitLabOrg != "" {
|
||||
opt := &gitlab.ListGroupProjectsOptions{
|
||||
ListOptions: gitlab.ListOptions{
|
||||
PerPage: gitlabPages,
|
||||
Page: page,
|
||||
},
|
||||
}
|
||||
|
||||
ps, resp, err = cl.Groups.ListGroupProjects(opts.GitLabOrg, opt)
|
||||
} else if opts.GitLabUser != "" {
|
||||
opt := &gitlab.ListProjectsOptions{
|
||||
ListOptions: gitlab.ListOptions{
|
||||
PerPage: gitlabPages,
|
||||
Page: page,
|
||||
},
|
||||
}
|
||||
|
||||
ps, resp, err = cl.Projects.ListUserProjects(opts.GitLabUser, opt)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
// exit when can't make API call
|
||||
log.Fatal("error listing projects: ", err)
|
||||
}
|
||||
|
||||
repos = append(repos, ps...)
|
||||
|
||||
if page >= resp.TotalPages {
|
||||
// exit when we've seen all pages
|
||||
break
|
||||
}
|
||||
|
||||
page = resp.NextPage
|
||||
}
|
||||
|
||||
log.Debugf("found projects: %d", len(repos))
|
||||
|
||||
if opts.Disk {
|
||||
if tempDir, err = createGitlabTempDir(); err != nil {
|
||||
log.Fatal("error creating temp directory: ", err)
|
||||
}
|
||||
}
|
||||
|
||||
for _, p := range repos {
|
||||
repo, err := cloneGitlabRepo(tempDir, p)
|
||||
if err != nil {
|
||||
log.Warn(err)
|
||||
continue
|
||||
}
|
||||
|
||||
err = repo.audit()
|
||||
if err != nil {
|
||||
log.Warn(err)
|
||||
continue
|
||||
}
|
||||
|
||||
if opts.Disk {
|
||||
os.RemoveAll(fmt.Sprintf("%s/%d", tempDir, p.ID))
|
||||
}
|
||||
|
||||
repo.report()
|
||||
leaks = append(leaks, repo.leaks...)
|
||||
}
|
||||
|
||||
if opts.Report != "" {
|
||||
err = writeReport(leaks)
|
||||
if err != nil {
|
||||
return NoLeaks, err
|
||||
}
|
||||
}
|
||||
|
||||
return len(leaks), nil
|
||||
}
|
||||
|
||||
func createGitlabTempDir() (string, error) {
|
||||
pathName := opts.GitLabUser
|
||||
if opts.GitLabOrg != "" {
|
||||
pathName = opts.GitLabOrg
|
||||
}
|
||||
|
||||
os.RemoveAll(fmt.Sprintf("%s/%s", dir, pathName))
|
||||
|
||||
ownerDir, err := ioutil.TempDir(dir, pathName)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
return ownerDir, nil
|
||||
}
|
||||
|
||||
func cloneGitlabRepo(tempDir string, p *gitlab.Project) (*Repo, error) {
|
||||
var (
|
||||
repo *git.Repository
|
||||
err error
|
||||
)
|
||||
|
||||
gitLabToken := os.Getenv("GITLAB_TOKEN")
|
||||
|
||||
if opts.ExcludeForks && p.ForkedFromProject != nil {
|
||||
return nil, fmt.Errorf("skipping %s, excluding forks", p.Name)
|
||||
}
|
||||
|
||||
for _, re := range config.WhiteList.repos {
|
||||
if re.FindString(p.Name) != "" {
|
||||
return nil, fmt.Errorf("skipping %s, whitelisted", p.Name)
|
||||
}
|
||||
}
|
||||
|
||||
opt := &git.CloneOptions{
|
||||
URL: p.HTTPURLToRepo,
|
||||
}
|
||||
|
||||
if config.sshAuth != nil && gitLabToken == "" {
|
||||
opt.URL = p.SSHURLToRepo
|
||||
opt.Auth = config.sshAuth
|
||||
} else if gitLabToken != "" {
|
||||
opt.Auth = &gitHttp.BasicAuth{
|
||||
Username: "fakeUsername", // yes, this can be anything except an empty string
|
||||
Password: gitLabToken,
|
||||
}
|
||||
}
|
||||
|
||||
log.Infof("cloning: %s", p.Name)
|
||||
|
||||
if opts.Disk {
|
||||
repo, err = git.PlainClone(fmt.Sprintf("%s/%d", tempDir, p.ID), false, opt)
|
||||
} else {
|
||||
repo, err = git.Clone(memory.NewStorage(), nil, opt)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &Repo{
|
||||
repository: repo,
|
||||
name: p.Name,
|
||||
}, nil
|
||||
}
|
||||
@@ -1,791 +0,0 @@
|
||||
package gitleaks
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path"
|
||||
"regexp"
|
||||
"runtime"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/franela/goblin"
|
||||
log "github.com/sirupsen/logrus"
|
||||
git "gopkg.in/src-d/go-git.v4"
|
||||
"gopkg.in/src-d/go-git.v4/storage/memory"
|
||||
)
|
||||
|
||||
func TestGetRepo(t *testing.T) {
|
||||
var err error
|
||||
dir, err = ioutil.TempDir("", "gitleaksTestRepo")
|
||||
defer os.RemoveAll(dir)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
_, err = git.PlainClone(dir, false, &git.CloneOptions{
|
||||
URL: "https://github.com/gitleakstest/gronit",
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
var tests = []struct {
|
||||
testOpts *Options
|
||||
description string
|
||||
expectedErrMsg string
|
||||
}{
|
||||
{
|
||||
testOpts: &Options{
|
||||
Repo: "https://github.com/gitleakstest/gronit",
|
||||
},
|
||||
description: "test plain clone remote repo",
|
||||
expectedErrMsg: "",
|
||||
},
|
||||
{
|
||||
testOpts: &Options{
|
||||
Repo: "https://github.com/gitleakstest/gronit",
|
||||
Disk: true,
|
||||
},
|
||||
description: "test on disk clone remote repo",
|
||||
expectedErrMsg: "",
|
||||
},
|
||||
{
|
||||
testOpts: &Options{
|
||||
RepoPath: dir,
|
||||
},
|
||||
description: "test local clone repo",
|
||||
expectedErrMsg: "",
|
||||
},
|
||||
{
|
||||
testOpts: &Options{
|
||||
Repo: "https://github.com/gitleakstest/nope",
|
||||
},
|
||||
description: "test no repo",
|
||||
expectedErrMsg: "repository not found",
|
||||
},
|
||||
{
|
||||
testOpts: &Options{
|
||||
Repo: "https://github.com/gitleakstest/private",
|
||||
},
|
||||
description: "test private repo",
|
||||
expectedErrMsg: "repository not found",
|
||||
},
|
||||
{
|
||||
testOpts: &Options{
|
||||
Repo: "https://github.com/gitleakstest/private",
|
||||
Disk: true,
|
||||
},
|
||||
description: "test private repo disk",
|
||||
expectedErrMsg: "repository not found",
|
||||
},
|
||||
}
|
||||
g := goblin.Goblin(t)
|
||||
for _, test := range tests {
|
||||
g.Describe("TestGetRepo", func() {
|
||||
g.It(test.description, func() {
|
||||
opts = test.testOpts
|
||||
config, err = newConfig()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
repo, _ := newRepo()
|
||||
err := repo.clone()
|
||||
if err != nil {
|
||||
g.Assert(err.Error()).Equal(test.expectedErrMsg)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestRun(t *testing.T) {
|
||||
var err error
|
||||
configsDir := testTomlLoader()
|
||||
|
||||
dir, err = ioutil.TempDir("", "gitleaksTestOwner")
|
||||
defer os.RemoveAll(dir)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
git.PlainClone(dir+"/gronit", false, &git.CloneOptions{
|
||||
URL: "https://github.com/gitleakstest/gronit",
|
||||
})
|
||||
git.PlainClone(dir+"/h1domains", false, &git.CloneOptions{
|
||||
URL: "https://github.com/gitleakstest/h1domains",
|
||||
})
|
||||
var tests = []struct {
|
||||
testOpts *Options
|
||||
description string
|
||||
expectedErrMsg string
|
||||
whiteListRepos []string
|
||||
whiteListFiles []*regexp.Regexp
|
||||
numLeaks int
|
||||
configPath string
|
||||
commitPerPage int
|
||||
}{
|
||||
{
|
||||
testOpts: &Options{
|
||||
Repo: "https://github.com/gitleakstest/gronit.git",
|
||||
},
|
||||
description: "test leak",
|
||||
numLeaks: 2,
|
||||
expectedErrMsg: "",
|
||||
},
|
||||
{
|
||||
testOpts: &Options{
|
||||
GitLabUser: "gitleakstest",
|
||||
},
|
||||
description: "test gitlab user",
|
||||
numLeaks: 2,
|
||||
expectedErrMsg: "",
|
||||
},
|
||||
{
|
||||
testOpts: &Options{
|
||||
GithubUser: "gitleakstest",
|
||||
},
|
||||
description: "test github user",
|
||||
numLeaks: 2,
|
||||
expectedErrMsg: "",
|
||||
},
|
||||
{
|
||||
testOpts: &Options{
|
||||
GithubUser: "gitleakstest",
|
||||
Disk: true,
|
||||
},
|
||||
description: "test github user on disk ",
|
||||
numLeaks: 2,
|
||||
expectedErrMsg: "",
|
||||
},
|
||||
{
|
||||
testOpts: &Options{
|
||||
GithubOrg: "gitleakstestorg",
|
||||
},
|
||||
description: "test github org",
|
||||
numLeaks: 2,
|
||||
expectedErrMsg: "",
|
||||
},
|
||||
{
|
||||
testOpts: &Options{
|
||||
GithubOrg: "gitleakstestorg",
|
||||
Disk: true,
|
||||
},
|
||||
description: "test org on disk",
|
||||
numLeaks: 2,
|
||||
expectedErrMsg: "",
|
||||
},
|
||||
{
|
||||
testOpts: &Options{
|
||||
OwnerPath: dir,
|
||||
},
|
||||
description: "test owner path",
|
||||
numLeaks: 2,
|
||||
expectedErrMsg: "",
|
||||
},
|
||||
{
|
||||
testOpts: &Options{
|
||||
Repo: "git@github.com:gitleakstest/gronit.git",
|
||||
SSHKey: "trash",
|
||||
},
|
||||
description: "test leak",
|
||||
numLeaks: 0,
|
||||
expectedErrMsg: fmt.Sprintf("unable to generate ssh key: open trash: %s", noSuchFileMessage()),
|
||||
},
|
||||
{
|
||||
testOpts: &Options{
|
||||
Repo: "https://github.com/gitleakstest/gronit.git",
|
||||
},
|
||||
description: "test leak",
|
||||
numLeaks: 2,
|
||||
expectedErrMsg: "",
|
||||
},
|
||||
{
|
||||
testOpts: &Options{
|
||||
Repo: "https://github.com/gitleakstest/h1domains.git",
|
||||
},
|
||||
description: "test clean",
|
||||
numLeaks: 0,
|
||||
expectedErrMsg: "",
|
||||
},
|
||||
{
|
||||
testOpts: &Options{
|
||||
Repo: "https://github.com/gitleakstest/empty.git",
|
||||
},
|
||||
description: "test empty",
|
||||
numLeaks: 0,
|
||||
expectedErrMsg: "repository not found",
|
||||
},
|
||||
{
|
||||
testOpts: &Options{
|
||||
GithubOrg: "gitleakstestorg",
|
||||
},
|
||||
description: "test github org, whitelist repo",
|
||||
numLeaks: 0,
|
||||
expectedErrMsg: "",
|
||||
configPath: path.Join(configsDir, "repo"),
|
||||
},
|
||||
{
|
||||
testOpts: &Options{
|
||||
GithubOrg: "gitleakstestorg",
|
||||
ExcludeForks: true,
|
||||
},
|
||||
description: "test github org, exclude forks",
|
||||
numLeaks: 0,
|
||||
expectedErrMsg: "",
|
||||
},
|
||||
{
|
||||
testOpts: &Options{
|
||||
GithubPR: "https://github.com/gitleakstest/gronit/pull/1",
|
||||
},
|
||||
description: "test github pr",
|
||||
numLeaks: 4,
|
||||
expectedErrMsg: "",
|
||||
},
|
||||
{
|
||||
testOpts: &Options{
|
||||
GithubPR: "https://github.com/gitleakstest/gronit/pull/1",
|
||||
},
|
||||
description: "test github pr",
|
||||
numLeaks: 4,
|
||||
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,
|
||||
configPath: path.Join(configsDir, "file"),
|
||||
},
|
||||
{
|
||||
testOpts: &Options{
|
||||
GithubPR: "https://github.com/gitleakstest/gronit/pull/2",
|
||||
},
|
||||
description: "test github pr with commits without patch info",
|
||||
numLeaks: 0,
|
||||
expectedErrMsg: "",
|
||||
commitPerPage: 1,
|
||||
},
|
||||
}
|
||||
g := goblin.Goblin(t)
|
||||
for _, test := range tests {
|
||||
g.Describe("TestRun", func() {
|
||||
g.It(test.description, func() {
|
||||
if test.configPath != "" {
|
||||
os.Setenv("GITLEAKS_CONFIG", test.configPath)
|
||||
}
|
||||
if test.commitPerPage != 0 {
|
||||
githubPages = test.commitPerPage
|
||||
}
|
||||
numLeaks, err := Run(test.testOpts)
|
||||
if err != nil {
|
||||
g.Assert(err.Error()).Equal(test.expectedErrMsg)
|
||||
} else {
|
||||
g.Assert(numLeaks).Equal(test.numLeaks)
|
||||
}
|
||||
githubPages = 100
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestWriteReport(t *testing.T) {
|
||||
tmpDir, _ := ioutil.TempDir("", "reportDir")
|
||||
reportJSON := path.Join(tmpDir, "report.json")
|
||||
reportJASON := path.Join(tmpDir, "report.jason")
|
||||
reportVOID := path.Join("thereIsNoWay", "thisReportWillGetWritten.json")
|
||||
reportCSV := path.Join(tmpDir, "report.csv")
|
||||
defer os.RemoveAll(tmpDir)
|
||||
leaks := []Leak{
|
||||
{
|
||||
Line: "eat",
|
||||
Commit: "your",
|
||||
Offender: "veggies",
|
||||
Rule: "and",
|
||||
Message: "get",
|
||||
Author: "some",
|
||||
File: "sleep",
|
||||
Date: time.Now(),
|
||||
},
|
||||
}
|
||||
|
||||
var tests = []struct {
|
||||
leaks []Leak
|
||||
reportFile string
|
||||
fileName string
|
||||
description string
|
||||
testOpts Options
|
||||
expectedErrMsg string
|
||||
}{
|
||||
{
|
||||
leaks: leaks,
|
||||
reportFile: reportJSON,
|
||||
fileName: "report.json",
|
||||
description: "can we write a json file",
|
||||
testOpts: Options{
|
||||
Report: reportJSON,
|
||||
},
|
||||
},
|
||||
{
|
||||
leaks: leaks,
|
||||
reportFile: reportCSV,
|
||||
fileName: "report.csv",
|
||||
description: "can we write a csv file",
|
||||
testOpts: Options{
|
||||
Report: reportCSV,
|
||||
},
|
||||
},
|
||||
{
|
||||
leaks: leaks,
|
||||
reportFile: reportJASON,
|
||||
fileName: "report.jason",
|
||||
description: "bad file",
|
||||
expectedErrMsg: "Report should be a .json or .csv file",
|
||||
testOpts: Options{
|
||||
Report: reportJASON,
|
||||
},
|
||||
},
|
||||
{
|
||||
leaks: leaks,
|
||||
reportFile: reportVOID,
|
||||
fileName: "report.jason",
|
||||
description: "bad dir",
|
||||
expectedErrMsg: "thereIsNoWay does not exist",
|
||||
testOpts: Options{
|
||||
Report: reportVOID,
|
||||
},
|
||||
},
|
||||
}
|
||||
g := goblin.Goblin(t)
|
||||
for _, test := range tests {
|
||||
g.Describe("TestWriteReport", func() {
|
||||
g.It(test.description, func() {
|
||||
opts = &(test.testOpts)
|
||||
err := opts.guard()
|
||||
if err != nil {
|
||||
g.Assert(err.Error()).Equal(test.expectedErrMsg)
|
||||
} else {
|
||||
writeReport(test.leaks)
|
||||
f, _ := os.Stat(test.reportFile)
|
||||
g.Assert(f.Name()).Equal(test.fileName)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestAuditRepo(t *testing.T) {
|
||||
configsDir := testTomlLoader()
|
||||
defer os.RemoveAll(configsDir)
|
||||
|
||||
leaksR, err := git.Clone(memory.NewStorage(), nil, &git.CloneOptions{
|
||||
URL: "https://github.com/gitleakstest/gronit.git",
|
||||
})
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
leaksRepo := &Repo{
|
||||
repository: leaksR,
|
||||
name: "gronit",
|
||||
}
|
||||
|
||||
cleanR, err := git.Clone(memory.NewStorage(), nil, &git.CloneOptions{
|
||||
URL: "https://github.com/gitleakstest/h1domains.git",
|
||||
})
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
cleanRepo := &Repo{
|
||||
repository: cleanR,
|
||||
name: "h1domains",
|
||||
}
|
||||
|
||||
var tests = []struct {
|
||||
testOpts *Options
|
||||
description string
|
||||
expectedErrMsg string
|
||||
numLeaks int
|
||||
repo *Repo
|
||||
whiteListFiles []*regexp.Regexp
|
||||
whiteListCommits map[string]bool
|
||||
whiteListRepos []*regexp.Regexp
|
||||
whiteListRegexes []*regexp.Regexp
|
||||
configPath string
|
||||
}{
|
||||
{
|
||||
repo: leaksRepo,
|
||||
description: "pinned config",
|
||||
numLeaks: 0,
|
||||
testOpts: &Options{
|
||||
RepoConfig: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
repo: leaksRepo,
|
||||
description: "commit depth = 1, one leak",
|
||||
numLeaks: 1,
|
||||
testOpts: &Options{
|
||||
Depth: 1,
|
||||
},
|
||||
},
|
||||
{
|
||||
repo: leaksRepo,
|
||||
description: "two leaks present",
|
||||
numLeaks: 2,
|
||||
testOpts: &Options{},
|
||||
},
|
||||
{
|
||||
repo: leaksRepo,
|
||||
description: "no leaks present on branch",
|
||||
numLeaks: 0,
|
||||
testOpts: &Options{
|
||||
Branch: "dev",
|
||||
},
|
||||
},
|
||||
{
|
||||
repo: leaksRepo,
|
||||
description: "two leaks present limit goroutines",
|
||||
numLeaks: 2,
|
||||
testOpts: &Options{
|
||||
Threads: 4,
|
||||
},
|
||||
},
|
||||
{
|
||||
repo: leaksRepo,
|
||||
description: "two leaks present whitelist AWS.. no leaks",
|
||||
testOpts: &Options{},
|
||||
configPath: path.Join(configsDir, "regex"),
|
||||
numLeaks: 0,
|
||||
},
|
||||
{
|
||||
repo: leaksRepo,
|
||||
description: "two leaks present limit goroutines",
|
||||
testOpts: &Options{
|
||||
Threads: 2,
|
||||
},
|
||||
numLeaks: 2,
|
||||
},
|
||||
{
|
||||
repo: cleanRepo,
|
||||
description: "no leaks present",
|
||||
testOpts: &Options{},
|
||||
numLeaks: 0,
|
||||
},
|
||||
{
|
||||
repo: leaksRepo,
|
||||
description: "two leaks present whitelist go files",
|
||||
testOpts: &Options{},
|
||||
configPath: path.Join(configsDir, "file"),
|
||||
numLeaks: 0,
|
||||
},
|
||||
{
|
||||
repo: leaksRepo,
|
||||
description: "two leaks present whitelist bad commit",
|
||||
configPath: path.Join(configsDir, "commit"),
|
||||
testOpts: &Options{},
|
||||
numLeaks: 1,
|
||||
},
|
||||
{
|
||||
repo: leaksRepo,
|
||||
description: "redact",
|
||||
testOpts: &Options{
|
||||
Redact: true,
|
||||
},
|
||||
numLeaks: 2,
|
||||
},
|
||||
{
|
||||
repo: leaksRepo,
|
||||
description: "Audit a specific commit",
|
||||
numLeaks: 1,
|
||||
testOpts: &Options{
|
||||
Commit: "cb5599aeed261b2c038aa4729e2d53ca050a4988",
|
||||
},
|
||||
},
|
||||
{
|
||||
repo: leaksRepo,
|
||||
description: "Audit a specific commit no leaks",
|
||||
numLeaks: 0,
|
||||
testOpts: &Options{
|
||||
Commit: "2b033e012eee364fc41b4ab7c5db1497399b8e67",
|
||||
},
|
||||
},
|
||||
{
|
||||
repo: leaksRepo,
|
||||
description: "toml whitelist regex",
|
||||
configPath: path.Join(configsDir, "regex"),
|
||||
testOpts: &Options{},
|
||||
numLeaks: 0,
|
||||
},
|
||||
{
|
||||
repo: leaksRepo,
|
||||
description: "toml whitelist file",
|
||||
configPath: path.Join(configsDir, "file"),
|
||||
testOpts: &Options{},
|
||||
numLeaks: 0,
|
||||
},
|
||||
{
|
||||
repo: leaksRepo,
|
||||
description: "toml whitelist commit",
|
||||
configPath: path.Join(configsDir, "commit"),
|
||||
testOpts: &Options{},
|
||||
numLeaks: 1,
|
||||
},
|
||||
{
|
||||
repo: leaksRepo,
|
||||
description: "audit whitelist repo",
|
||||
numLeaks: 0,
|
||||
testOpts: &Options{},
|
||||
configPath: path.Join(configsDir, "repo"),
|
||||
},
|
||||
{
|
||||
repo: leaksRepo,
|
||||
description: "toml whitelist repo",
|
||||
numLeaks: 0,
|
||||
testOpts: &Options{},
|
||||
configPath: path.Join(configsDir, "repo"),
|
||||
},
|
||||
{
|
||||
repo: leaksRepo,
|
||||
description: "Audit until specific commit",
|
||||
numLeaks: 2,
|
||||
testOpts: &Options{
|
||||
CommitStop: "f6839959b7bbdcd23008f1fb16f797f35bcd3a0c",
|
||||
},
|
||||
},
|
||||
{
|
||||
repo: leaksRepo,
|
||||
description: "commit depth = 2, two leaks",
|
||||
numLeaks: 2,
|
||||
testOpts: &Options{
|
||||
Depth: 2,
|
||||
},
|
||||
},
|
||||
{
|
||||
repo: leaksRepo,
|
||||
description: "toml entropy range from opts",
|
||||
numLeaks: 266,
|
||||
testOpts: &Options{
|
||||
ConfigPath: path.Join(configsDir, "entropy"),
|
||||
},
|
||||
},
|
||||
{
|
||||
repo: leaksRepo,
|
||||
description: "toml entropy regex word range",
|
||||
numLeaks: 0,
|
||||
testOpts: &Options{},
|
||||
configPath: path.Join(configsDir, "entropyWordRegex"),
|
||||
},
|
||||
{
|
||||
repo: leaksRepo,
|
||||
description: "toml entropy regex range",
|
||||
numLeaks: 2,
|
||||
testOpts: &Options{},
|
||||
configPath: path.Join(configsDir, "entropyRegex"),
|
||||
},
|
||||
{
|
||||
repo: leaksRepo,
|
||||
description: "toml bad entropy range",
|
||||
numLeaks: 0,
|
||||
testOpts: &Options{},
|
||||
configPath: path.Join(configsDir, "badEntropy"),
|
||||
expectedErrMsg: "entropy range must be ascending",
|
||||
},
|
||||
{
|
||||
repo: leaksRepo,
|
||||
description: "toml bad entropy2 range",
|
||||
numLeaks: 0,
|
||||
testOpts: &Options{},
|
||||
configPath: path.Join(configsDir, "badEntropy2"),
|
||||
expectedErrMsg: "invalid entropy ranges, must be within 0.0-8.0",
|
||||
},
|
||||
{
|
||||
repo: leaksRepo,
|
||||
description: "toml md files",
|
||||
numLeaks: 5,
|
||||
testOpts: &Options{},
|
||||
configPath: path.Join(configsDir, "mdFiles"),
|
||||
},
|
||||
{
|
||||
repo: leaksRepo,
|
||||
description: "toml entropys line regex go",
|
||||
numLeaks: 2,
|
||||
testOpts: &Options{},
|
||||
configPath: path.Join(configsDir, "entropyRegexGo"),
|
||||
},
|
||||
}
|
||||
g := goblin.Goblin(t)
|
||||
for _, test := range tests {
|
||||
g.Describe("TestAuditRepo", func() {
|
||||
g.It(test.description, func() {
|
||||
opts = test.testOpts
|
||||
|
||||
config, err = newConfig()
|
||||
// config paths
|
||||
if test.configPath != "" {
|
||||
os.Setenv("GITLEAKS_CONFIG", test.configPath)
|
||||
config, err = newConfig()
|
||||
if err != nil {
|
||||
g.Assert(err.Error()).Equal(test.expectedErrMsg)
|
||||
goto next
|
||||
}
|
||||
}
|
||||
err = test.repo.audit()
|
||||
if opts.Redact {
|
||||
g.Assert(test.repo.leaks[0].Offender).Equal("REDACTED")
|
||||
}
|
||||
g.Assert(len(test.repo.leaks)).Equal(test.numLeaks)
|
||||
next:
|
||||
os.Setenv("GITLEAKS_CONFIG", "")
|
||||
test.repo.leaks = []Leak{}
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestOptionGuard(t *testing.T) {
|
||||
var tests = []struct {
|
||||
testOpts *Options
|
||||
githubToken bool
|
||||
description string
|
||||
expectedErrMsg string
|
||||
expectedErrMsgFuzzy string
|
||||
}{
|
||||
{
|
||||
testOpts: &Options{},
|
||||
description: "default no opts",
|
||||
expectedErrMsg: "",
|
||||
},
|
||||
{
|
||||
testOpts: &Options{
|
||||
GithubUser: "fakeUser",
|
||||
GithubOrg: "fakeOrg",
|
||||
},
|
||||
description: "double owner",
|
||||
expectedErrMsg: "github user and organization set",
|
||||
},
|
||||
{
|
||||
testOpts: &Options{
|
||||
GithubOrg: "fakeOrg",
|
||||
OwnerPath: "/dev/null",
|
||||
},
|
||||
description: "local and remote target",
|
||||
expectedErrMsg: "github organization set and local owner path",
|
||||
},
|
||||
{
|
||||
testOpts: &Options{
|
||||
GithubUser: "fakeUser",
|
||||
OwnerPath: "/dev/null",
|
||||
},
|
||||
description: "local and remote target",
|
||||
expectedErrMsg: "github user set and local owner path",
|
||||
},
|
||||
}
|
||||
g := goblin.Goblin(t)
|
||||
for _, test := range tests {
|
||||
g.Describe("Test Option Gaurd", func() {
|
||||
g.It(test.description, func() {
|
||||
os.Clearenv()
|
||||
opts = test.testOpts
|
||||
if test.githubToken {
|
||||
os.Setenv("GITHUB_TOKEN", "fakeToken")
|
||||
}
|
||||
err := opts.guard()
|
||||
if err != nil {
|
||||
if test.expectedErrMsgFuzzy != "" {
|
||||
g.Assert(strings.Contains(err.Error(), test.expectedErrMsgFuzzy)).Equal(true)
|
||||
} else {
|
||||
g.Assert(err.Error()).Equal(test.expectedErrMsg)
|
||||
}
|
||||
} else {
|
||||
g.Assert("").Equal(test.expectedErrMsg)
|
||||
}
|
||||
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestLoadToml(t *testing.T) {
|
||||
tmpDir, _ := ioutil.TempDir("", "gitleaksTestConfigDir")
|
||||
defer os.RemoveAll(tmpDir)
|
||||
err := ioutil.WriteFile(path.Join(tmpDir, "gitleaksConfig"), []byte(defaultConfig), 0644)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
configPath := path.Join(tmpDir, "gitleaksConfig")
|
||||
noConfigPath := path.Join(tmpDir, "gitleaksConfigNope")
|
||||
|
||||
var tests = []struct {
|
||||
testOpts *Options
|
||||
description string
|
||||
configPath string
|
||||
expectedErrMsg string
|
||||
singleSearch bool
|
||||
}{
|
||||
{
|
||||
testOpts: &Options{
|
||||
ConfigPath: configPath,
|
||||
},
|
||||
description: "path to config",
|
||||
},
|
||||
{
|
||||
testOpts: &Options{},
|
||||
description: "env var path to no config",
|
||||
singleSearch: true,
|
||||
},
|
||||
{
|
||||
testOpts: &Options{
|
||||
ConfigPath: noConfigPath,
|
||||
},
|
||||
description: "no path to config",
|
||||
expectedErrMsg: fmt.Sprintf("no gitleaks config at %s", noConfigPath),
|
||||
},
|
||||
{
|
||||
testOpts: &Options{},
|
||||
description: "env var path to config",
|
||||
configPath: configPath,
|
||||
expectedErrMsg: "",
|
||||
},
|
||||
{
|
||||
testOpts: &Options{},
|
||||
description: "env var path to no config",
|
||||
configPath: noConfigPath,
|
||||
expectedErrMsg: fmt.Sprintf("problem loading config: open %s: %s", noConfigPath, noSuchFileMessage()),
|
||||
},
|
||||
}
|
||||
|
||||
g := goblin.Goblin(t)
|
||||
for _, test := range tests {
|
||||
g.Describe("TestLoadToml", func() {
|
||||
g.It(test.description, func() {
|
||||
opts = test.testOpts
|
||||
if test.configPath != "" {
|
||||
os.Setenv("GITLEAKS_CONFIG", test.configPath)
|
||||
} else {
|
||||
os.Clearenv()
|
||||
}
|
||||
_, err = newConfig()
|
||||
if err != nil {
|
||||
g.Assert(err.Error()).Equal(test.expectedErrMsg)
|
||||
} else {
|
||||
g.Assert("").Equal(test.expectedErrMsg)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func noSuchFileMessage() string {
|
||||
if runtime.GOOS == "windows" {
|
||||
// Adapt to Windws
|
||||
return "The system cannot find the file specified."
|
||||
}
|
||||
return "no such file or directory"
|
||||
}
|
||||
-161
@@ -1,161 +0,0 @@
|
||||
package gitleaks
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net"
|
||||
"net/url"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/jessevdk/go-flags"
|
||||
colorable "github.com/mattn/go-colorable"
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
// Options for gitleaks
|
||||
type Options struct {
|
||||
// remote target options
|
||||
Repo string `short:"r" long:"repo" description:"Repo url to audit"`
|
||||
GithubUser string `long:"github-user" description:"Github user to audit"`
|
||||
GithubOrg string `long:"github-org" description:"Github organization to audit"`
|
||||
GithubURL string `long:"github-url" default:"https://api.github.com/" description:"GitHub API Base URL, use for GitHub Enterprise. Example: https://github.example.com/api/v3/"`
|
||||
GithubPR string `long:"github-pr" description:"Github PR url to audit. This does not clone the repo. GITHUB_TOKEN must be set"`
|
||||
|
||||
GitLabUser string `long:"gitlab-user" description:"GitLab user ID to audit"`
|
||||
GitLabOrg string `long:"gitlab-org" description:"GitLab group ID to audit"`
|
||||
|
||||
CommitStop string `long:"commit-stop" description:"sha of commit to stop at"`
|
||||
Commit string `long:"commit" description:"sha of commit to audit"`
|
||||
Depth int64 `long:"depth" description:"maximum commit depth"`
|
||||
|
||||
// local target option
|
||||
RepoPath string `long:"repo-path" description:"Path to repo"`
|
||||
OwnerPath string `long:"owner-path" description:"Path to owner directory (repos discovered)"`
|
||||
|
||||
// Process options
|
||||
Threads int `long:"threads" description:"Maximum number of threads gitleaks spawns"`
|
||||
Disk bool `long:"disk" description:"Clones repo(s) to disk"`
|
||||
ConfigPath string `long:"config" description:"path to gitleaks config"`
|
||||
SSHKey string `long:"ssh-key" description:"path to ssh key"`
|
||||
ExcludeForks bool `long:"exclude-forks" description:"exclude forks for organization/user audits"`
|
||||
RepoConfig bool `long:"repo-config" description:"Load config from target repo. Config file must be \".gitleaks.toml\""`
|
||||
Branch string `long:"branch" description:"Branch to audit"`
|
||||
// TODO: IncludeMessages string `long:"messages" description:"include commit messages in audit"`
|
||||
|
||||
// Output options
|
||||
Log string `short:"l" long:"log" description:"log level"`
|
||||
Verbose bool `short:"v" long:"verbose" description:"Show verbose output from gitleaks audit"`
|
||||
Report string `long:"report" description:"path to write report file. Needs to be csv or json"`
|
||||
Redact bool `long:"redact" description:"redact secrets from log messages and report"`
|
||||
Version bool `long:"version" description:"version number"`
|
||||
SampleConfig bool `long:"sample-config" description:"prints a sample config file"`
|
||||
}
|
||||
|
||||
// ParseOpts parses the options
|
||||
func ParseOpts() *Options {
|
||||
var opts Options
|
||||
parser := flags.NewParser(&opts, flags.Default)
|
||||
_, err := parser.Parse()
|
||||
|
||||
if err != nil {
|
||||
if flagsErr, ok := err.(*flags.Error); ok && flagsErr.Type != flags.ErrHelp {
|
||||
parser.WriteHelp(os.Stdout)
|
||||
}
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
if len(os.Args) == 1 {
|
||||
parser.WriteHelp(os.Stdout)
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
if opts.Version {
|
||||
fmt.Println(version)
|
||||
os.Exit(0)
|
||||
}
|
||||
if opts.SampleConfig {
|
||||
fmt.Println(defaultConfig)
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
opts.setLogs()
|
||||
|
||||
err = opts.guard()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
return &opts
|
||||
}
|
||||
|
||||
// optsGuard prevents invalid options
|
||||
func (opts *Options) guard() error {
|
||||
if opts.GithubOrg != "" && opts.GithubUser != "" {
|
||||
return fmt.Errorf("github user and organization set")
|
||||
} else if opts.GithubOrg != "" && opts.OwnerPath != "" {
|
||||
return fmt.Errorf("github organization set and local owner path")
|
||||
} else if opts.GithubUser != "" && opts.OwnerPath != "" {
|
||||
return fmt.Errorf("github user set and local owner path")
|
||||
}
|
||||
|
||||
if opts.Threads > runtime.GOMAXPROCS(0) {
|
||||
return fmt.Errorf("%d available threads", runtime.GOMAXPROCS(0))
|
||||
}
|
||||
|
||||
// do the URL Parse and error checking here, so we can skip it later
|
||||
// empty string is OK, it will default to the public github URL.
|
||||
if opts.GithubURL != "" && opts.GithubURL != defaultGithubURL {
|
||||
if !strings.HasSuffix(opts.GithubURL, "/") {
|
||||
opts.GithubURL += "/"
|
||||
}
|
||||
ghURL, err := url.Parse(opts.GithubURL)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
tcpPort := "443"
|
||||
if ghURL.Scheme == "http" {
|
||||
tcpPort = "80"
|
||||
}
|
||||
timeout := time.Duration(1 * time.Second)
|
||||
_, err = net.DialTimeout("tcp", ghURL.Host+":"+tcpPort, timeout)
|
||||
if err != nil {
|
||||
return fmt.Errorf("%s unreachable, error: %s", ghURL.Host, err)
|
||||
}
|
||||
}
|
||||
|
||||
if opts.Report != "" {
|
||||
if !strings.HasSuffix(opts.Report, ".json") && !strings.HasSuffix(opts.Report, ".csv") {
|
||||
return fmt.Errorf("Report should be a .json or .csv file")
|
||||
}
|
||||
dirPath := filepath.Dir(opts.Report)
|
||||
if _, err := os.Stat(dirPath); os.IsNotExist(err) {
|
||||
return fmt.Errorf("%s does not exist", dirPath)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// setLogLevel sets log level for gitleaks. Default is Warning
|
||||
func (opts *Options) setLogs() {
|
||||
switch opts.Log {
|
||||
case "info":
|
||||
log.SetLevel(log.InfoLevel)
|
||||
case "debug":
|
||||
log.SetLevel(log.DebugLevel)
|
||||
case "warn":
|
||||
log.SetLevel(log.WarnLevel)
|
||||
default:
|
||||
log.SetLevel(log.InfoLevel)
|
||||
}
|
||||
log.SetFormatter(&log.TextFormatter{
|
||||
ForceColors: true,
|
||||
FullTimestamp: true,
|
||||
})
|
||||
// Fix colors on Windows
|
||||
if runtime.GOOS == "windows" {
|
||||
log.SetOutput(colorable.NewColorableStdout())
|
||||
}
|
||||
}
|
||||
-481
@@ -1,481 +0,0 @@
|
||||
package gitleaks
|
||||
|
||||
import (
|
||||
"crypto/md5"
|
||||
"fmt"
|
||||
"github.com/hako/durafmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
"gopkg.in/src-d/go-git.v4"
|
||||
"gopkg.in/src-d/go-git.v4/plumbing"
|
||||
diffType "gopkg.in/src-d/go-git.v4/plumbing/format/diff"
|
||||
"gopkg.in/src-d/go-git.v4/plumbing/object"
|
||||
"gopkg.in/src-d/go-git.v4/plumbing/storer"
|
||||
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/utils/merkletrie"
|
||||
)
|
||||
|
||||
// Commit represents a git commit
|
||||
type Commit struct {
|
||||
content string
|
||||
commit *object.Commit
|
||||
filePath string
|
||||
repoName string
|
||||
sha string
|
||||
message string
|
||||
author string
|
||||
email string
|
||||
date time.Time
|
||||
}
|
||||
|
||||
|
||||
// Leak represents a leaked secret or regex match.
|
||||
type Leak struct {
|
||||
Line string `json:"line"`
|
||||
Commit string `json:"commit"`
|
||||
Offender string `json:"offender"`
|
||||
Rule string `json:"rule"`
|
||||
Info string `json:"info"`
|
||||
Message string `json:"commitMsg"`
|
||||
Author string `json:"author"`
|
||||
Email string `json:"email"`
|
||||
File string `json:"file"`
|
||||
Repo string `json:"repo"`
|
||||
Date time.Time `json:"date"`
|
||||
Tags string `json:"tags"`
|
||||
Severity string `json:"severity"`
|
||||
}
|
||||
|
||||
// Repo contains a src-d git repository and other data about the repo
|
||||
type Repo struct {
|
||||
leaks []Leak
|
||||
path string
|
||||
url string
|
||||
name string
|
||||
repository *git.Repository
|
||||
err error
|
||||
auditDuration string
|
||||
numCommits int64
|
||||
}
|
||||
|
||||
func newRepo() (*Repo, error) {
|
||||
for _, re := range config.WhiteList.repos {
|
||||
if re.FindString(opts.Repo) != "" {
|
||||
return nil, fmt.Errorf("skipping %s, whitelisted", opts.Repo)
|
||||
}
|
||||
}
|
||||
return &Repo{
|
||||
path: opts.RepoPath,
|
||||
url: opts.Repo,
|
||||
name: filepath.Base(opts.Repo),
|
||||
}, nil
|
||||
}
|
||||
|
||||
// clone will clone a repo
|
||||
func (repo *Repo) clone() error {
|
||||
var (
|
||||
err error
|
||||
repository *git.Repository
|
||||
)
|
||||
|
||||
// check if cloning to disk
|
||||
if opts.Disk {
|
||||
log.Infof("cloning %s to disk", opts.Repo)
|
||||
cloneTarget := fmt.Sprintf("%s/%x", dir, md5.Sum([]byte(fmt.Sprintf("%s%s", opts.GithubUser, opts.Repo))))
|
||||
if strings.HasPrefix(opts.Repo, "git") {
|
||||
// private
|
||||
repository, err = git.PlainClone(cloneTarget, false, &git.CloneOptions{
|
||||
URL: opts.Repo,
|
||||
Progress: os.Stdout,
|
||||
Auth: config.sshAuth,
|
||||
})
|
||||
} else {
|
||||
// public
|
||||
options := &git.CloneOptions{
|
||||
URL: opts.Repo,
|
||||
Progress: os.Stdout,
|
||||
}
|
||||
if os.Getenv("GITHUB_TOKEN") != "" {
|
||||
options.Auth = &gitHttp.BasicAuth{
|
||||
Username: "fakeUsername", // yes, this can be anything except an empty string
|
||||
Password: os.Getenv("GITHUB_TOKEN"),
|
||||
}
|
||||
}
|
||||
repository, err = git.PlainClone(cloneTarget, false, options)
|
||||
}
|
||||
} else if repo.path != "" {
|
||||
log.Infof("opening %s", repo.path)
|
||||
repository, err = git.PlainOpen(repo.path)
|
||||
if err != nil {
|
||||
log.Errorf("unable to open %s", repo.path)
|
||||
}
|
||||
} else {
|
||||
// cloning to memory
|
||||
log.Infof("cloning %s", opts.Repo)
|
||||
if strings.HasPrefix(opts.Repo, "git") {
|
||||
repository, err = git.Clone(memory.NewStorage(), nil, &git.CloneOptions{
|
||||
URL: opts.Repo,
|
||||
Progress: os.Stdout,
|
||||
Auth: config.sshAuth,
|
||||
})
|
||||
} else {
|
||||
options := &git.CloneOptions{
|
||||
URL: opts.Repo,
|
||||
Progress: os.Stdout,
|
||||
}
|
||||
if os.Getenv("GITHUB_TOKEN") != "" {
|
||||
options.Auth = &gitHttp.BasicAuth{
|
||||
Username: "fakeUsername", // yes, this can be anything except an empty string
|
||||
Password: os.Getenv("GITHUB_TOKEN"),
|
||||
}
|
||||
}
|
||||
repository, err = git.Clone(memory.NewStorage(), nil, options)
|
||||
}
|
||||
}
|
||||
repo.repository = repository
|
||||
repo.err = err
|
||||
return err
|
||||
}
|
||||
|
||||
// audit performs an audit
|
||||
func (repo *Repo) audit() error {
|
||||
var (
|
||||
err error
|
||||
commitCount int64
|
||||
commitWg sync.WaitGroup
|
||||
semaphore chan bool
|
||||
logOpts git.LogOptions
|
||||
)
|
||||
for _, re := range config.WhiteList.repos {
|
||||
if re.FindString(repo.name) != "" {
|
||||
return fmt.Errorf("skipping %s, whitelisted", repo.name)
|
||||
}
|
||||
}
|
||||
|
||||
start := time.Now()
|
||||
|
||||
// check if target contains an external gitleaks toml
|
||||
if opts.RepoConfig {
|
||||
err := config.updateFromRepo(repo)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
if opts.Commit != "" {
|
||||
h := plumbing.NewHash(opts.Commit)
|
||||
c, err := repo.repository.CommitObject(h)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
totalCommits = totalCommits + 1
|
||||
repo.numCommits = 1
|
||||
return repo.auditSingleCommit(c)
|
||||
} else if opts.Branch != "" {
|
||||
refs, err := repo.repository.Storer.IterReferences()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = refs.ForEach(func(ref *plumbing.Reference) error {
|
||||
if ref.Name().IsTag() {
|
||||
return nil
|
||||
}
|
||||
// check heads first
|
||||
if ref.Name().String() == "refs/heads/"+opts.Branch {
|
||||
logOpts = git.LogOptions{
|
||||
From: ref.Hash(),
|
||||
}
|
||||
return nil
|
||||
} else if ref.Name().String() == "refs/remotes/origin/"+opts.Branch {
|
||||
logOpts = git.LogOptions{
|
||||
From: ref.Hash(),
|
||||
}
|
||||
return nil
|
||||
}
|
||||
return nil
|
||||
})
|
||||
} else {
|
||||
logOpts = git.LogOptions{
|
||||
All: true,
|
||||
}
|
||||
}
|
||||
|
||||
// iterate all through commits
|
||||
cIter, err := repo.repository.Log(&logOpts)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if opts.Threads != 0 {
|
||||
threads = opts.Threads
|
||||
}
|
||||
if opts.RepoPath != "" {
|
||||
threads = 1
|
||||
}
|
||||
semaphore = make(chan bool, threads)
|
||||
|
||||
err = cIter.ForEach(func(c *object.Commit) error {
|
||||
if c == nil || (opts.Depth != 0 && commitCount == opts.Depth) {
|
||||
return storer.ErrStop
|
||||
}
|
||||
|
||||
if config.WhiteList.commits[c.Hash.String()] {
|
||||
log.Infof("skipping commit: %s\n", c.Hash.String())
|
||||
return nil
|
||||
}
|
||||
|
||||
// commits w/o parent (root of git the git ref)
|
||||
if len(c.ParentHashes) == 0 {
|
||||
commitCount = commitCount + 1
|
||||
totalCommits = totalCommits + 1
|
||||
err := repo.auditSingleCommit(c)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
commitCount = commitCount + 1
|
||||
totalCommits = totalCommits + 1
|
||||
|
||||
// regular commit audit
|
||||
err = c.Parents().ForEach(func(parent *object.Commit) error {
|
||||
commitWg.Add(1)
|
||||
semaphore <- true
|
||||
go func(c *object.Commit, parent *object.Commit) {
|
||||
var (
|
||||
filePath string
|
||||
skipFile bool
|
||||
)
|
||||
defer func() {
|
||||
commitWg.Done()
|
||||
<-semaphore
|
||||
if r := recover(); r != nil {
|
||||
log.Warnf("recovering from panic on commit %s, likely large diff causing panic", c.Hash.String())
|
||||
}
|
||||
}()
|
||||
patch, err := c.Patch(parent)
|
||||
if err != nil {
|
||||
log.Warnf("problem generating patch for commit: %s\n", c.Hash.String())
|
||||
return
|
||||
}
|
||||
for _, f := range patch.FilePatches() {
|
||||
if f.IsBinary() {
|
||||
continue
|
||||
}
|
||||
skipFile = false
|
||||
from, to := f.Files()
|
||||
filePath = "???"
|
||||
if from != nil {
|
||||
filePath = from.Path()
|
||||
} else if to != nil {
|
||||
filePath = to.Path()
|
||||
}
|
||||
|
||||
for _, fr := range config.FileRules {
|
||||
for _, r := range fr.fileTypes {
|
||||
if r.FindString(filePath) != "" {
|
||||
commitInfo := &Commit{
|
||||
repoName: repo.name,
|
||||
filePath: filePath,
|
||||
sha: c.Hash.String(),
|
||||
author: c.Author.Name,
|
||||
email: c.Author.Email,
|
||||
message: strings.Replace(c.Message, "\n", " ", -1),
|
||||
date: c.Author.When,
|
||||
}
|
||||
leak := *newLeak("N/A", fmt.Sprintf("filetype %s found", r.String()), r.String(), fr, commitInfo)
|
||||
mutex.Lock()
|
||||
repo.leaks = append(repo.leaks, leak)
|
||||
mutex.Unlock()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for _, re := range config.WhiteList.files {
|
||||
if re.FindString(filePath) != "" {
|
||||
log.Debugf("skipping whitelisted file (matched regex '%s'): %s", re.String(), filePath)
|
||||
skipFile = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if skipFile {
|
||||
continue
|
||||
}
|
||||
chunks := f.Chunks()
|
||||
for _, chunk := range chunks {
|
||||
if chunk.Type() == diffType.Add || chunk.Type() == diffType.Delete {
|
||||
diff := &Commit{
|
||||
repoName: repo.name,
|
||||
filePath: filePath,
|
||||
content: chunk.Content(),
|
||||
sha: c.Hash.String(),
|
||||
author: c.Author.Name,
|
||||
email: c.Author.Email,
|
||||
message: strings.Replace(c.Message, "\n", " ", -1),
|
||||
date: c.Author.When,
|
||||
}
|
||||
chunkLeaks := inspect(diff)
|
||||
for _, leak := range chunkLeaks {
|
||||
mutex.Lock()
|
||||
repo.leaks = append(repo.leaks, leak)
|
||||
mutex.Unlock()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}(c, parent)
|
||||
|
||||
return nil
|
||||
})
|
||||
|
||||
return nil
|
||||
})
|
||||
|
||||
commitWg.Wait()
|
||||
repo.numCommits = commitCount
|
||||
repo.auditDuration = durafmt.Parse(time.Now().Sub(start)).String()
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (repo *Repo) auditSingleCommit(c *object.Commit) error {
|
||||
fIter, err := c.Files()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// If current commit has parents then search for leaks in tree change,
|
||||
// that means scan in changed/modified files from one commit to another.
|
||||
if len(c.ParentHashes) > 0 {
|
||||
prevCommitObject, err := c.Parents().Next()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return repo.auditTreeChange(prevCommitObject, c)
|
||||
}
|
||||
|
||||
// Scan for leaks in files related to current commit
|
||||
err = fIter.ForEach(func(f *object.File) error {
|
||||
bin, err := f.IsBinary()
|
||||
if bin || err != nil {
|
||||
return nil
|
||||
}
|
||||
for _, re := range config.WhiteList.files {
|
||||
if re.FindString(f.Name) != "" {
|
||||
log.Debugf("skipping whitelisted file (matched regex '%s'): %s", re.String(), f.Name)
|
||||
return nil
|
||||
}
|
||||
}
|
||||
content, err := f.Contents()
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
diff := &Commit{
|
||||
repoName: repo.name,
|
||||
filePath: f.Name,
|
||||
content: content,
|
||||
sha: c.Hash.String(),
|
||||
author: c.Author.Name,
|
||||
email: c.Author.Email,
|
||||
message: strings.Replace(c.Message, "\n", " ", -1),
|
||||
date: c.Author.When,
|
||||
}
|
||||
fileLeaks := inspect(diff)
|
||||
mutex.Lock()
|
||||
repo.leaks = append(repo.leaks, fileLeaks...)
|
||||
mutex.Unlock()
|
||||
return nil
|
||||
})
|
||||
return err
|
||||
}
|
||||
|
||||
func (repo *Repo) report() {
|
||||
if len(repo.leaks) != 0 {
|
||||
log.Warnf("%d leaks detected. %d commits inspected in %s", len(repo.leaks), repo.numCommits, repo.auditDuration)
|
||||
} else {
|
||||
log.Infof("No leaks detected. %d commits inspected in %s", repo.numCommits, repo.auditDuration)
|
||||
}
|
||||
}
|
||||
|
||||
// auditTreeChange will search for leaks in changed/modified files from one
|
||||
// commit to another
|
||||
func (repo *Repo) auditTreeChange(src, dst *object.Commit) error {
|
||||
var (
|
||||
skip bool
|
||||
)
|
||||
|
||||
// Get state of src commit
|
||||
srcState, err := src.Tree()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Get state of destination commit
|
||||
dstState, err := dst.Tree()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
changes, err := srcState.Diff(dstState)
|
||||
|
||||
// Run through each change
|
||||
for _, change := range changes {
|
||||
|
||||
// Ignore deleted files
|
||||
action, err := change.Action()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if action == merkletrie.Delete {
|
||||
continue
|
||||
}
|
||||
|
||||
// Get list of involved files
|
||||
_, to, err := change.Files()
|
||||
bin, err := to.IsBinary()
|
||||
if bin || err != nil {
|
||||
continue
|
||||
}
|
||||
|
||||
for _, re := range config.WhiteList.files {
|
||||
if re.FindString(to.Name) != "" {
|
||||
log.Debugf("skipping whitelisted file (matched regex '%s'): %s", re.String(), to.Name)
|
||||
skip = true
|
||||
}
|
||||
}
|
||||
|
||||
if skip {
|
||||
skip = false
|
||||
continue
|
||||
}
|
||||
|
||||
content, err := to.Contents()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
diff := &Commit{
|
||||
repoName: repo.name,
|
||||
filePath: to.Name,
|
||||
content: content,
|
||||
sha: dst.Hash.String(),
|
||||
author: dst.Author.Name,
|
||||
email: dst.Author.Email,
|
||||
message: strings.Replace(dst.Message, "\n", " ", -1),
|
||||
date: dst.Author.When,
|
||||
}
|
||||
fileLeaks := inspect(diff)
|
||||
mutex.Lock()
|
||||
repo.leaks = append(repo.leaks, fileLeaks...)
|
||||
mutex.Unlock()
|
||||
}
|
||||
return nil
|
||||
|
||||
}
|
||||
-226
@@ -1,226 +0,0 @@
|
||||
package gitleaks
|
||||
|
||||
import (
|
||||
"encoding/csv"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
// writeReport writes a report to a file specified in the --report= option.
|
||||
// Default format for report is JSON. You can use the --csv option to write the report as a csv
|
||||
func writeReport(leaks []Leak) error {
|
||||
if len(leaks) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
log.Infof("writing report to %s", opts.Report)
|
||||
if strings.HasSuffix(opts.Report, ".csv") {
|
||||
f, err := os.Create(opts.Report)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer f.Close()
|
||||
w := csv.NewWriter(f)
|
||||
w.Write([]string{"repo", "line", "commit", "offender", "rule", "info", "tags", "severity", "commitMsg", "author", "email", "file", "date"})
|
||||
for _, leak := range leaks {
|
||||
w.Write([]string{leak.Repo, leak.Line, leak.Commit, leak.Offender, leak.Rule, leak.Info, leak.Tags, leak.Severity, leak.Message, leak.Author, leak.Email, leak.File, leak.Date.Format(time.RFC3339)})
|
||||
}
|
||||
w.Flush()
|
||||
} else {
|
||||
f, err := os.Create(opts.Report)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer f.Close()
|
||||
encoder := json.NewEncoder(f)
|
||||
encoder.SetIndent("", "\t")
|
||||
if _, err := f.WriteString("[\n"); err != nil {
|
||||
return err
|
||||
}
|
||||
for i := 0; i < len(leaks); i++ {
|
||||
if err := encoder.Encode(leaks[i]); err != nil {
|
||||
return err
|
||||
}
|
||||
// for all but the last leak, seek back and overwrite the newline appended by Encode() with comma & newline
|
||||
if i+1 < len(leaks) {
|
||||
if _, err := f.Seek(-1, 1); err != nil {
|
||||
return err
|
||||
}
|
||||
if _, err := f.WriteString(",\n"); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
if _, err := f.WriteString("]"); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := f.Sync(); err != nil {
|
||||
log.Error(err)
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// check rule will inspect a single line and return a leak if it encounters one
|
||||
func (rule *Rule) check(line string, commit *Commit) (*Leak, error) {
|
||||
var (
|
||||
match string
|
||||
fileMatch string
|
||||
entropy float64
|
||||
entropyWord string
|
||||
)
|
||||
|
||||
for _, f := range rule.fileTypes {
|
||||
fileMatch = f.FindString(commit.filePath)
|
||||
if fileMatch != "" {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if fileMatch == "" && len(rule.fileTypes) != 0 {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
if rule.entropies != nil {
|
||||
if rule.entropyROI == "word" {
|
||||
words := strings.Fields(line)
|
||||
for _, word := range words {
|
||||
_entropy := getShannonEntropy(word)
|
||||
for _, e := range rule.entropies {
|
||||
if _entropy > e.v1 && _entropy < e.v2 {
|
||||
entropy = _entropy
|
||||
entropyWord = word
|
||||
goto postEntropy
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
_entropy := getShannonEntropy(line)
|
||||
for _, e := range rule.entropies {
|
||||
if _entropy > e.v1 && _entropy < e.v2 {
|
||||
entropy = _entropy
|
||||
entropyWord = line
|
||||
goto postEntropy
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
postEntropy:
|
||||
if rule.regex != nil {
|
||||
match = rule.regex.FindString(line)
|
||||
}
|
||||
|
||||
if match != "" && entropy != 0.0 {
|
||||
return newLeak(line, fmt.Sprintf("%s regex match and entropy met at %.2f", rule.regex.String(), entropy), entropyWord, rule, commit), nil
|
||||
} else if match != "" && rule.entropies == nil {
|
||||
return newLeak(line, fmt.Sprintf("%s regex match", rule.regex.String()), match, rule, commit), nil
|
||||
} else if entropy != 0.0 && rule.regex.String() == "" {
|
||||
return newLeak(line, fmt.Sprintf("entropy met at %.2f", entropy), entropyWord, rule, commit), nil
|
||||
}
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
// inspect will parse each line of the git diff's content against a set of regexes or
|
||||
// a set of regexes set by the config (see gitleaks.toml for example). This function
|
||||
// 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(commit *Commit) []Leak {
|
||||
var leaks []Leak
|
||||
lines := strings.Split(commit.content, "\n")
|
||||
|
||||
for _, line := range lines {
|
||||
for _, rule := range config.Rules {
|
||||
if isLineWhitelisted(line) {
|
||||
break
|
||||
}
|
||||
leak, err := rule.check(line, commit)
|
||||
if err != nil || leak == nil {
|
||||
continue
|
||||
}
|
||||
leaks = append(leaks, *leak)
|
||||
}
|
||||
}
|
||||
return leaks
|
||||
}
|
||||
|
||||
// isLineWhitelisted returns true iff the line is matched by at least one of the whiteListRegexes.
|
||||
func isLineWhitelisted(line string) bool {
|
||||
for _, wRe := range config.WhiteList.regexes {
|
||||
whitelistMatch := wRe.FindString(line)
|
||||
if whitelistMatch != "" {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func newLeak(line string, info string, offender string, rule *Rule, commit *Commit) *Leak {
|
||||
leak := &Leak{
|
||||
Line: line,
|
||||
Commit: commit.sha,
|
||||
Offender: offender,
|
||||
Rule: rule.description,
|
||||
Info: info,
|
||||
Author: commit.author,
|
||||
Email: commit.email,
|
||||
File: commit.filePath,
|
||||
Repo: commit.repoName,
|
||||
Message: commit.message,
|
||||
Date: commit.date,
|
||||
Tags: strings.Join(rule.tags, ", "),
|
||||
Severity: rule.severity,
|
||||
}
|
||||
if opts.Redact {
|
||||
leak.Offender = "REDACTED"
|
||||
leak.Line = strings.Replace(line, offender, "REDACTED", -1)
|
||||
}
|
||||
|
||||
if opts.Verbose {
|
||||
leak.log()
|
||||
}
|
||||
return leak
|
||||
}
|
||||
|
||||
// discoverRepos walks all the children of `path`. If a child directory
|
||||
// contain a .git subdirectory then that repo will be added to the list of repos returned
|
||||
func discoverRepos(ownerPath string) ([]*Repo, error) {
|
||||
var (
|
||||
err error
|
||||
repoDs []*Repo
|
||||
)
|
||||
files, err := ioutil.ReadDir(ownerPath)
|
||||
if err != nil {
|
||||
return repoDs, err
|
||||
}
|
||||
for _, f := range files {
|
||||
repoPath := path.Join(ownerPath, f.Name())
|
||||
if f.IsDir() && containsGit(repoPath) {
|
||||
repoDs = append(repoDs, &Repo{
|
||||
name: f.Name(),
|
||||
path: repoPath,
|
||||
})
|
||||
}
|
||||
}
|
||||
return repoDs, err
|
||||
}
|
||||
|
||||
func (leak Leak) log() {
|
||||
b, _ := json.MarshalIndent(leak, "", " ")
|
||||
fmt.Println(string(b))
|
||||
}
|
||||
|
||||
func containsGit(repoPath string) bool {
|
||||
if _, err := os.Stat(repoPath); os.IsNotExist(err) {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
[
|
||||
{
|
||||
"line": "",
|
||||
"lineNumber": 1,
|
||||
"offender": "Filename or path offender: ../test_data/test_repos/test_repo_10/.gitignore",
|
||||
"commit": "",
|
||||
"repo": "",
|
||||
"repoURL": "",
|
||||
"leakURL": "",
|
||||
"rule": "Block dangerous filetypes",
|
||||
"commitMessage": "",
|
||||
"author": "",
|
||||
"email": "",
|
||||
"file": "../test_data/test_repos/test_repo_10/.gitignore",
|
||||
"date": "0001-01-01T00:00:00Z",
|
||||
"tags": "key, extensions"
|
||||
},
|
||||
{
|
||||
"line": "",
|
||||
"lineNumber": 1,
|
||||
"offender": "Filename or path offender: ../test_data/test_repos/test_repo_10/bad.zip",
|
||||
"commit": "",
|
||||
"repo": "",
|
||||
"repoURL": "",
|
||||
"leakURL": "",
|
||||
"rule": "Block dangerous filetypes",
|
||||
"commitMessage": "",
|
||||
"author": "",
|
||||
"email": "",
|
||||
"file": "../test_data/test_repos/test_repo_10/bad.zip",
|
||||
"date": "0001-01-01T00:00:00Z",
|
||||
"tags": "key, extensions"
|
||||
},
|
||||
{
|
||||
"line": "",
|
||||
"lineNumber": 1,
|
||||
"offender": "Filename or path offender: ../test_data/test_repos/test_repo_10/gitfile.txt",
|
||||
"commit": "",
|
||||
"repo": "",
|
||||
"repoURL": "",
|
||||
"leakURL": "",
|
||||
"rule": "Block dangerous filetypes",
|
||||
"commitMessage": "",
|
||||
"author": "",
|
||||
"email": "",
|
||||
"file": "../test_data/test_repos/test_repo_10/gitfile.txt",
|
||||
"date": "0001-01-01T00:00:00Z",
|
||||
"tags": "key, extensions"
|
||||
},
|
||||
{
|
||||
"line": "",
|
||||
"lineNumber": 1,
|
||||
"offender": "Filename or path offender: ../test_data/test_repos/test_repo_10/creds.git",
|
||||
"commit": "",
|
||||
"repo": "",
|
||||
"repoURL": "",
|
||||
"leakURL": "",
|
||||
"rule": "Block dangerous filetypes",
|
||||
"commitMessage": "",
|
||||
"author": "",
|
||||
"email": "",
|
||||
"file": "../test_data/test_repos/test_repo_10/creds.git",
|
||||
"date": "0001-01-01T00:00:00Z",
|
||||
"tags": "key, extensions"
|
||||
},
|
||||
{
|
||||
"line": "",
|
||||
"lineNumber": 1,
|
||||
"offender": "Filename or path offender: ../test_data/test_repos/test_repo_10/somedir.git/secret.key",
|
||||
"commit": "",
|
||||
"repo": "",
|
||||
"repoURL": "",
|
||||
"leakURL": "",
|
||||
"rule": "Block dangerous filetypes",
|
||||
"commitMessage": "",
|
||||
"author": "",
|
||||
"email": "",
|
||||
"file": "../test_data/test_repos/test_repo_10/somedir.git/secret.key",
|
||||
"date": "0001-01-01T00:00:00Z",
|
||||
"tags": "key, extensions"
|
||||
}
|
||||
]
|
||||
@@ -0,0 +1,18 @@
|
||||
[
|
||||
{
|
||||
"line": "",
|
||||
"lineNumber": 1,
|
||||
"offender": "Filename or path offender: tmp/bad.docx",
|
||||
"commit": "b0f9b62dfe12e4e10de180359c6b9276472494f8",
|
||||
"repo": "test_repo_10",
|
||||
"repoURL": "",
|
||||
"leakURL": "",
|
||||
"rule": "Block dangerous filetypes",
|
||||
"commitMessage": "Create bad.docx",
|
||||
"author": "Zachary Rice",
|
||||
"email": "zricer@protonmail.com",
|
||||
"file": "tmp/bad.docx",
|
||||
"date": "2020-12-09T11:02:10-05:00",
|
||||
"tags": "key, extensions"
|
||||
}
|
||||
]
|
||||
@@ -0,0 +1,34 @@
|
||||
[
|
||||
{
|
||||
"line": "",
|
||||
"lineNumber": 1,
|
||||
"offender": "Filename or path offender: ../test_data/test_repos/test_repo_10/somedir.git/secret.key",
|
||||
"commit": "",
|
||||
"repo": "",
|
||||
"repoURL": "",
|
||||
"leakURL": "",
|
||||
"rule": "Block dangerous filetypes",
|
||||
"commitMessage": "",
|
||||
"author": "",
|
||||
"email": "",
|
||||
"file": "../test_data/test_repos/test_repo_10/somedir.git/secret.key",
|
||||
"date": "0001-01-01T00:00:00Z",
|
||||
"tags": "key, extensions"
|
||||
},
|
||||
{
|
||||
"line": "",
|
||||
"lineNumber": 1,
|
||||
"offender": "Filename or path offender: ../test_data/test_repos/test_repo_10/tmp/bad.docx",
|
||||
"commit": "",
|
||||
"repo": "",
|
||||
"repoURL": "",
|
||||
"leakURL": "",
|
||||
"rule": "Block dangerous filetypes",
|
||||
"commitMessage": "",
|
||||
"author": "",
|
||||
"email": "",
|
||||
"file": "../test_data/test_repos/test_repo_10/tmp/bad.docx",
|
||||
"date": "0001-01-01T00:00:00Z",
|
||||
"tags": "key, extensions"
|
||||
}
|
||||
]
|
||||
@@ -0,0 +1,15 @@
|
||||
[[rules]]
|
||||
description = "AWS Access Key"
|
||||
regex = '''(A3T[A-Z0-9]|AKIA|AGPA|AIDA|AROA|AIPA|ANPA|ANVA|ASIA)[A-Z0-9]{16}'''
|
||||
tags = ["key", "AWS"]
|
||||
[rules.allowlist]
|
||||
description = "if we encounter this commit for this rule, skip it"
|
||||
commits = ["b10b3e2cb320a8c211fda94c4567299d37de7776"]
|
||||
|
||||
|
||||
[allowlist]
|
||||
commits = [
|
||||
"17471a5fda722a9e423f1a0d3f0d267ea009d41c",
|
||||
"996865bb912f3bc45898a370a13aadb315014b55"
|
||||
]
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
[[rules]]
|
||||
description = "Block dangerous filetypes"
|
||||
file = '''(.*?)(creds.git|gitfile.txt|gitignore|pdf|doc|docx|zip|xls|tfplan|tfstate|tfvars|vault_pass|vagrant|pyc|key|cache)$'''
|
||||
tags = ["key", "extensions"]
|
||||
[rules.allowlist]
|
||||
paths = ['''.docx''']
|
||||
description = "ignore known locations and files"
|
||||
|
||||
#[allowlist]
|
||||
# description = "Allowlisted files"
|
||||
# paths = ['''.zip''']
|
||||
@@ -0,0 +1,11 @@
|
||||
[[rules]]
|
||||
description = "Block dangerous filetypes"
|
||||
file = '''(.*?)(pdf|doc|docx|zip|xls|tfplan|tfstate|tfvars|vault_pass|vagrant|pyc|key|cache)$'''
|
||||
tags = ["key", "extensions"]
|
||||
[rules.allowlist]
|
||||
paths = ['''.zip''']
|
||||
description = "ignore known locations and files"
|
||||
#
|
||||
#[allowlist]
|
||||
# description = "Allowlisted files"
|
||||
# paths = ['''.zip''']
|
||||
@@ -0,0 +1,9 @@
|
||||
[[rules]]
|
||||
description = "AWS Access Key"
|
||||
regex = '''(A3T[A-Z0-9]|AKIA|AGPA|AIDA|AROA|AIPA|ANPA|ANVA|ASIA)[A-Z0-9]{16}'''
|
||||
tags = ["key", "AWS"]
|
||||
|
||||
[allowlist]
|
||||
description = "Allowlisted files"
|
||||
paths = ['''.py''']
|
||||
files = ['''.md$''']
|
||||
@@ -0,0 +1,9 @@
|
||||
[[rules]]
|
||||
description = "AWS Secret Key"
|
||||
regex = '''(?i)aws(.{0,20})?(?-i)['\"][0-9a-zA-Z\/+]{40}['\"]'''
|
||||
tags = ["key", "AWS"]
|
||||
|
||||
[[rules]]
|
||||
description = "AWS Access Key"
|
||||
regex = '''(A3T[A-Z0-9]|AKIA|AGPA|AIDA|AROA|AIPA|ANPA|ANVA|ASIA)[A-Z0-9]{16}'''
|
||||
tags = ["key", "AWS"]
|
||||
@@ -0,0 +1,8 @@
|
||||
[[rules]]
|
||||
description = "AWS Access Key"
|
||||
regex = '''(A3T[A-Z0-9]|AKIA|AGPA|AIDA|AROA|AIPA|ANPA|ANVA|ASIA)[A-Z0-9]{16}'''
|
||||
tags = ["key", "AWS"]
|
||||
[rules.allowlist]
|
||||
description = "ignore sample regex md files"
|
||||
files = ['''(.*)?md$''']
|
||||
regexes = ['''ignore$''']
|
||||
@@ -0,0 +1,7 @@
|
||||
[[rules]]
|
||||
description = "AWS Access Key"
|
||||
regex = '''(A3T[A-Z0-9]|AKIA|AGPA|AIDA|AROA|AIPA|ANPA|ANVA|ASIA)[A-Z0-9]{16}'''
|
||||
tags = ["key", "AWS"]
|
||||
[rules.allowlist]
|
||||
description = "ignore python files"
|
||||
files = ['''(.*)?py$''']
|
||||
@@ -0,0 +1,7 @@
|
||||
[[rules]]
|
||||
description = "AWS Access Key"
|
||||
regex = '''(A3T[A-Z0-9]|AKIA|AGPA|AIDA|AROA|AIPA|ANPA|ANVA|ASIA)[A-Z0-9]{16}'''
|
||||
tags = ["key", "AWS"]
|
||||
[rules.allowlist]
|
||||
description = "ignore aws key"
|
||||
regexes = ['''AKIAIO5FODNN7EXAMPLE.*''']
|
||||
@@ -0,0 +1,14 @@
|
||||
[[rules]]
|
||||
description = "AWS Secret Key"
|
||||
regex = '''(?i)aws(.{0,20})?(?-i)['\"][0-9a-zA-Z\/+]{40}['\"]'''
|
||||
tags = ["key", "AWS"]
|
||||
|
||||
[[rules]]
|
||||
description = "AWS Access Key"
|
||||
regex = '''(A3T[A-Z0-9]|AKIA|AGPA|AIDA|AROA|AIPA|ANPA|ANVA|ASIA)[A-Z0-9]{16}'''
|
||||
tags = ["key", "AWS"]
|
||||
|
||||
## this is an example of a rule that won't work
|
||||
[[rules]]
|
||||
description = "Python files"
|
||||
fileRegex = "(?i)*.py"
|
||||
@@ -0,0 +1,10 @@
|
||||
[[rules]]
|
||||
description = "AWS Access Key"
|
||||
regex = '''(A3T[A-Z0-9]|AKIA|AGPA|AIDA|AROA|AIPA|ANPA|ANVA|ASIA)[A-Z0-9]{16}'''
|
||||
tags = ["key", "AWS"]
|
||||
|
||||
[allowlist]
|
||||
description = "ignore md files"
|
||||
files = [
|
||||
'''(.*)?md$'''
|
||||
]
|
||||
@@ -0,0 +1,10 @@
|
||||
[[rules]]
|
||||
description = "AWS Access Key"
|
||||
regex = '''(A3T[A-Z0-9]|AKIA|AGPA|AIDA|AROA|AIPA|ANPA|ANVA|ASIA)[A-Z0-9]{16}'''
|
||||
tags = ["key", "AWS"]
|
||||
|
||||
[allowlist]
|
||||
description = "ignore config folders"
|
||||
paths = [
|
||||
'''config(uration)?'''
|
||||
]
|
||||
@@ -0,0 +1,9 @@
|
||||
[[rules]]
|
||||
description = "AWS Access Key"
|
||||
regex = '''(A3T[A-Z0-9]|AKIA|AGPA|AIDA|AROA|AIPA|ANPA|ANVA|ASIA)[A-Z0-9]{16}'''
|
||||
tags = ["key", "AWS"]
|
||||
[allowlist]
|
||||
description = "allowlist repo"
|
||||
repos = [
|
||||
'''test_repo_1'''
|
||||
]
|
||||
@@ -0,0 +1,10 @@
|
||||
[[rules]]
|
||||
description = "AWS Secret Key"
|
||||
regex = '''(?i)aws(.{0,20})?(?-i)['\"][0-9a-zA-Z\/+]{40}['\"]'''
|
||||
tags = ["key", "AWS"]
|
||||
|
||||
[[rules]]
|
||||
description = "AWS Access Key"
|
||||
regex = '''AWS secret: ("?)((A3T[A-Z0-9]|AKIA|AGPA|AIDA|AROA|AIPA|ANPA|ANVA|ASIA)[A-Z0-9]{16})("?)'''
|
||||
tags = ["key", "AWS"]
|
||||
reportGroup = 2
|
||||
@@ -0,0 +1,9 @@
|
||||
[[rules]]
|
||||
description = "AWS Secret Key"
|
||||
regex = '''(?i)aws(.{0,20})?(?-i)['\"][0-9a-zA-Z\/+]{40}['\"]'''
|
||||
tags = ["key", "AWS"]
|
||||
|
||||
[[rules]]
|
||||
description = AWS Access Key"
|
||||
regex = '''(A3T[A-Z0-9]|AKIA|AGPA|AIDA|AROA|AIPA|ANPA|ANVA|ASIA)[A-Z0-9]{16}'''
|
||||
tags = ["key", "AWS"]
|
||||
@@ -0,0 +1,13 @@
|
||||
[[rules]]
|
||||
description = "AWS Secret Key"
|
||||
regex = '''(?i)aws(.{0,20})?(?-i)['\"][0-9a-zA-Z\/+]{40}['\"]'''
|
||||
tags = ["key", "AWS"]
|
||||
|
||||
[[rules]]
|
||||
description = "AWS Access Key"
|
||||
regex = '''(A3T[A-Z0-9]|AKIA|AGPA|AIDA|AROA|AIPA|ANPA|ANVA|ASIA)[A-Z0-9]{16}'''
|
||||
tags = ["key", "AWS"]
|
||||
|
||||
[Global]
|
||||
file = '''?????????????'''
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
[[rules]]
|
||||
description = "AWS Access Key"
|
||||
regex = '''(A3T[A-Z0-9]|AKIA|AGPA|AIDA|AROA|AIPA|ANPA|ANVA|ASIA)[A-Z0-9]{16}'''
|
||||
tags = ["key", "AWS"]
|
||||
|
||||
[allowlist]
|
||||
description = "ignore md files"
|
||||
files = ['''???????''']
|
||||
@@ -0,0 +1,8 @@
|
||||
[[rules]]
|
||||
description = "entropy"
|
||||
regex = '''['|"]([0-9a-zA-Z-._{}$\/\+=]{20,120})['|"]'''
|
||||
tags = ["entropy"]
|
||||
[[rules.Entropies]]
|
||||
Min = "4.3"
|
||||
Max = "4.1"
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
[[rules]]
|
||||
description = "entropy"
|
||||
regex = '''['|"]([0-9a-zA-Z-._{}$\/\+=]{20,120})['|"]'''
|
||||
tags = ["entropy"]
|
||||
[[rules.Entropies]]
|
||||
Min = "4.3"
|
||||
Max = "x"
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
[[rules]]
|
||||
description = "entropy"
|
||||
regex = '''['|"]([0-9a-zA-Z-._{}$\/\+=]{20,120})['|"]'''
|
||||
tags = ["entropy"]
|
||||
[[rules.Entropies]]
|
||||
Min = "x"
|
||||
Max = "4.1"
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
[[rules]]
|
||||
description = "entropy"
|
||||
regex = '''['|"]([0-9a-zA-Z-._{}$\/\+=]{20,120})['|"]'''
|
||||
tags = ["entropy"]
|
||||
[[rules.Entropies]]
|
||||
Min = "1.0"
|
||||
Max = "8"
|
||||
Group = "x"
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
[[rules]]
|
||||
description = "entropy"
|
||||
regex = '''['|"]([0-9a-zA-Z-._{}$\/\+=]{20,120})['|"]'''
|
||||
tags = ["entropy"]
|
||||
[[rules.Entropies]]
|
||||
Min = "1.0"
|
||||
Max = "8.5"
|
||||
Group = "-2"
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
[[rules]]
|
||||
description = "entropy"
|
||||
regex = '''['|"]([0-9a-zA-Z-._{}$\/\+=]{20,120})['|"]'''
|
||||
tags = ["entropy"]
|
||||
[[rules.Entropies]]
|
||||
Min = "1.0"
|
||||
Max = "8.5"
|
||||
Group = "2"
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
[[rules]]
|
||||
description = "entropy"
|
||||
regex = '''['|"]([0-9a-zA-Z-._{}$\/\+=]{20,120})['|"]'''
|
||||
tags = ["entropy"]
|
||||
[[rules.Entropies]]
|
||||
Min = "1.0"
|
||||
Max = "8.5"
|
||||
Group = "0"
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
[[rules]]
|
||||
description = "AWS Secret Key"
|
||||
regex = '''$$$???$$$??$?$?$'''
|
||||
tags = ["key", "AWS"]
|
||||
|
||||
[[rules]]
|
||||
description = "AWS Access Key"
|
||||
regex = '''(A3T[A-Z0-9]|AKIA|AGPA|AIDA|AROA|AIPA|ANPA|ANVA|ASIA)[A-Z0-9]{16}'''
|
||||
tags = ["key", "AWS"]
|
||||
@@ -0,0 +1,16 @@
|
||||
title = "gitleaks config"
|
||||
|
||||
[[rules]]
|
||||
description = "Asymmetric Private Key"
|
||||
regex = '''-----BEGIN ((EC|PGP|DSA|RSA|OPENSSH) )?PRIVATE KEY( BLOCK)?-----'''
|
||||
tags = ["key", "AsymmetricPrivateKey"]
|
||||
|
||||
[[rules]]
|
||||
description = "Passwords"
|
||||
regex = '''(?i)password=(?i)'''
|
||||
tags = ["key", "Generic"]
|
||||
|
||||
[[rules]]
|
||||
description = "secret secret.com"
|
||||
regex = '''(?i)secret\.com'''
|
||||
tags = ["key", "custom"]
|
||||
@@ -0,0 +1,11 @@
|
||||
[[rules]]
|
||||
description = "entropy"
|
||||
regex = '''['|"]([0-9a-zA-Z-._{}$\/\+=]{40,120})['|"]'''
|
||||
tags = ["entropy"]
|
||||
[[rules.Entropies]]
|
||||
Min = "4.5"
|
||||
Max = "4.7"
|
||||
[[rules.Entropies]]
|
||||
Min = "5.5"
|
||||
Max = "6.3"
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
[[rules]]
|
||||
description = "Generic Credential"
|
||||
regex = '''(?i)(api_key|apikey|secret|password|pass|pw|key)(.{0,20})?[0-9a-zA-Z]{16,45}'''
|
||||
tags = ["key", "API", "generic"]
|
||||
@@ -0,0 +1,148 @@
|
||||
title = "gitleaks config"
|
||||
|
||||
[[rules]]
|
||||
description = "AWS Secret Key"
|
||||
regex = '''(?i)aws(.{0,20})?(?-i)['\"][0-9a-zA-Z\/+]{40}['\"]'''
|
||||
tags = ["key", "AWS"]
|
||||
|
||||
[[rules]]
|
||||
description = "AWS MWS key"
|
||||
regex = '''amzn\.mws\.[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}'''
|
||||
tags = ["key", "AWS", "MWS"]
|
||||
|
||||
[[rules]]
|
||||
description = "Facebook Secret Key"
|
||||
regex = '''(?i)(facebook|fb)(.{0,20})?(?-i)['\"][0-9a-f]{32}['\"]'''
|
||||
tags = ["key", "Facebook"]
|
||||
|
||||
[[rules]]
|
||||
description = "Facebook Client ID"
|
||||
regex = '''(?i)(facebook|fb)(.{0,20})?['\"][0-9]{13,17}['\"]'''
|
||||
tags = ["key", "Facebook"]
|
||||
|
||||
[[rules]]
|
||||
description = "Twitter Secret Key"
|
||||
regex = '''(?i)twitter(.{0,20})?['\"][0-9a-z]{35,44}['\"]'''
|
||||
tags = ["key", "Twitter"]
|
||||
|
||||
[[rules]]
|
||||
description = "Twitter Client ID"
|
||||
regex = '''(?i)twitter(.{0,20})?['\"][0-9a-z]{18,25}['\"]'''
|
||||
tags = ["client", "Twitter"]
|
||||
|
||||
[[rules]]
|
||||
description = "Github"
|
||||
regex = '''(?i)github(.{0,20})?(?-i)['\"][0-9a-zA-Z]{35,40}['\"]'''
|
||||
tags = ["key", "Github"]
|
||||
|
||||
[[rules]]
|
||||
description = "LinkedIn Client ID"
|
||||
regex = '''(?i)linkedin(.{0,20})?(?-i)['\"][0-9a-z]{12}['\"]'''
|
||||
tags = ["client", "LinkedIn"]
|
||||
|
||||
[[rules]]
|
||||
description = "LinkedIn Secret Key"
|
||||
regex = '''(?i)linkedin(.{0,20})?['\"][0-9a-z]{16}['\"]'''
|
||||
tags = ["secret", "LinkedIn"]
|
||||
|
||||
[[rules]]
|
||||
description = "Slack"
|
||||
regex = '''xox[baprs]-([0-9a-zA-Z]{10,48})?'''
|
||||
tags = ["key", "Slack"]
|
||||
|
||||
[[rules]]
|
||||
description = "EC"
|
||||
regex = '''-----BEGIN EC PRIVATE KEY-----'''
|
||||
tags = ["key", "EC"]
|
||||
|
||||
[[rules]]
|
||||
description = "Generic API key"
|
||||
regex = '''(?i)(api_key|apikey)(.{0,20})?['|"][0-9a-zA-Z]{32,45}['|"]'''
|
||||
tags = ["key", "API", "generic"]
|
||||
|
||||
[[rules]]
|
||||
description = "Generic Secret"
|
||||
regex = '''(?i)secret(.{0,20})?['|"][0-9a-zA-Z]{32,45}['|"]'''
|
||||
tags = ["key", "Secret", "generic"]
|
||||
|
||||
[[rules]]
|
||||
description = "Google API key"
|
||||
regex = '''AIza[0-9A-Za-z\\-_]{35}'''
|
||||
tags = ["key", "Google"]
|
||||
|
||||
|
||||
[[rules]]
|
||||
description = "Heroku API key"
|
||||
regex = '''(?i)heroku(.{0,20})?['"][0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}['"]'''
|
||||
tags = ["key", "Heroku"]
|
||||
|
||||
[[rules]]
|
||||
description = "MailChimp API key"
|
||||
regex = '''(?i)(mailchimp|mc)(.{0,20})?['"][0-9a-f]{32}-us[0-9]{1,2}['"]'''
|
||||
tags = ["key", "Mailchimp"]
|
||||
|
||||
[[rules]]
|
||||
description = "Mailgun API key"
|
||||
regex = '''(?i)(mailgun|mg)(.{0,20})?['"][0-9a-z]{32}['"]'''
|
||||
tags = ["key", "Mailgun"]
|
||||
|
||||
[[rules]]
|
||||
description = "PayPal Braintree access token"
|
||||
regex = '''access_token\$production\$[0-9a-z]{16}\$[0-9a-f]{32}'''
|
||||
tags = ["key", "Paypal"]
|
||||
|
||||
[[rules]]
|
||||
description = "Picatic API key"
|
||||
regex = '''sk_live_[0-9a-z]{32}'''
|
||||
tags = ["key", "Picatic"]
|
||||
|
||||
[[rules]]
|
||||
description = "Slack Webhook"
|
||||
regex = '''https://hooks.slack.com/services/T[a-zA-Z0-9_]{8}/B[a-zA-Z0-9_]{8}/[a-zA-Z0-9_]{24}'''
|
||||
tags = ["key", "slack"]
|
||||
|
||||
[[rules]]
|
||||
description = "Stripe API key"
|
||||
regex = '''(?i)stripe(.{0,20})?['\"][sk|rk]_live_[0-9a-zA-Z]{24}'''
|
||||
tags = ["key", "Stripe"]
|
||||
|
||||
[[rules]]
|
||||
description = "Square access token"
|
||||
regex = '''sq0atp-[0-9A-Za-z\-_]{22}'''
|
||||
tags = ["key", "square"]
|
||||
|
||||
[[rules]]
|
||||
description = "Square OAuth secret"
|
||||
regex = '''sq0csp-[0-9A-Za-z\\-_]{43}'''
|
||||
tags = ["key", "square"]
|
||||
|
||||
[[rules]]
|
||||
description = "Twilio API key"
|
||||
regex = '''(?i)twilio(.{0,20})?['\"][0-9a-f]{32}['\"]'''
|
||||
tags = ["key", "twilio"]
|
||||
|
||||
[[rules]]
|
||||
description = "AWS Access Key"
|
||||
regex = '''(A3T[A-Z0-9]|AKIA|AGPA|AIDA|AROA|AIPA|ANPA|ANVA|ASIA)[A-Z0-9]{16}'''
|
||||
tags = ["key", "AWS"]
|
||||
[rules.allowlist]
|
||||
description = "ignore common jenkins functions"
|
||||
regexes = [
|
||||
'''allowlistme'''
|
||||
]
|
||||
files = [
|
||||
'''(.*)?Jenkinsfile$'''
|
||||
]
|
||||
|
||||
# Global rules. This instructs gitleaks to ignore all .pem files or if a message with
|
||||
[[rules]]
|
||||
description = "Files with keys and credentials"
|
||||
file = '''(.*?)(pem)'''
|
||||
|
||||
[allowlist]
|
||||
description = "File allowlists"
|
||||
files = [
|
||||
'''(.*?)(jpg|gif)$''',
|
||||
'''(.*?)(doc|pdf|bin)$'''
|
||||
]
|
||||
|
||||
@@ -0,0 +1,151 @@
|
||||
title = "gitleaks config"
|
||||
|
||||
[[rules]]
|
||||
description = "AWS Secret Key"
|
||||
regex = '''(?i)aws(.{0,20})?(?-i)['\"][0-9a-zA-Z\/+]{40}['\"]'''
|
||||
tags = ["key", "AWS"]
|
||||
|
||||
[[rules]]
|
||||
description = "AWS MWS key"
|
||||
regex = '''amzn\.mws\.[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}'''
|
||||
tags = ["key", "AWS", "MWS"]
|
||||
|
||||
[[rules]]
|
||||
description = "Facebook Secret Key"
|
||||
regex = '''(?i)(facebook|fb)(.{0,20})?(?-i)['\"][0-9a-f]{32}['\"]'''
|
||||
tags = ["key", "Facebook"]
|
||||
|
||||
[[rules]]
|
||||
description = "Facebook Client ID"
|
||||
regex = '''(?i)(facebook|fb)(.{0,20})?['\"][0-9]{13,17}['\"]'''
|
||||
tags = ["key", "Facebook"]
|
||||
|
||||
[[rules]]
|
||||
description = "Twitter Secret Key"
|
||||
regex = '''(?i)twitter(.{0,20})?['\"][0-9a-z]{35,44}['\"]'''
|
||||
tags = ["key", "Twitter"]
|
||||
|
||||
[[rules]]
|
||||
description = "Twitter Client ID"
|
||||
regex = '''(?i)twitter(.{0,20})?['\"][0-9a-z]{18,25}['\"]'''
|
||||
tags = ["client", "Twitter"]
|
||||
|
||||
[[rules]]
|
||||
description = "Github"
|
||||
regex = '''(?i)github(.{0,20})?(?-i)['\"][0-9a-zA-Z]{35,40}['\"]'''
|
||||
tags = ["key", "Github"]
|
||||
|
||||
[[rules]]
|
||||
description = "LinkedIn Client ID"
|
||||
regex = '''(?i)linkedin(.{0,20})?(?-i)['\"][0-9a-z]{12}['\"]'''
|
||||
tags = ["client", "LinkedIn"]
|
||||
|
||||
[[rules]]
|
||||
description = "LinkedIn Secret Key"
|
||||
regex = '''(?i)linkedin(.{0,20})?['\"][0-9a-z]{16}['\"]'''
|
||||
tags = ["secret", "LinkedIn"]
|
||||
|
||||
[[rules]]
|
||||
description = "Slack"
|
||||
regex = '''xox[baprs]-([0-9a-zA-Z]{10,48})?'''
|
||||
tags = ["key", "Slack"]
|
||||
|
||||
[[rules]]
|
||||
description = "EC"
|
||||
regex = '''-----BEGIN EC PRIVATE KEY-----'''
|
||||
tags = ["key", "EC"]
|
||||
|
||||
[[rules]]
|
||||
description = "Generic API key"
|
||||
regex = '''(?i)(api_key|apikey)(.{0,20})?['|"][0-9a-zA-Z]{32,45}['|"]'''
|
||||
tags = ["key", "API", "generic"]
|
||||
|
||||
[[rules]]
|
||||
description = "Generic Secret"
|
||||
regex = '''(?i)secret(.{0,20})?['|"][0-9a-zA-Z]{32,45}['|"]'''
|
||||
tags = ["key", "Secret", "generic"]
|
||||
|
||||
[[rules]]
|
||||
description = "Google API key"
|
||||
regex = '''AIza[0-9A-Za-z\\-_]{35}'''
|
||||
tags = ["key", "Google"]
|
||||
|
||||
|
||||
[[rules]]
|
||||
description = "Heroku API key"
|
||||
regex = '''(?i)heroku(.{0,20})?['"][0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}['"]'''
|
||||
tags = ["key", "Heroku"]
|
||||
|
||||
[[rules]]
|
||||
description = "MailChimp API key"
|
||||
regex = '''(?i)(mailchimp|mc)(.{0,20})?['"][0-9a-f]{32}-us[0-9]{1,2}['"]'''
|
||||
tags = ["key", "Mailchimp"]
|
||||
|
||||
[[rules]]
|
||||
description = "Mailgun API key"
|
||||
regex = '''(?i)(mailgun|mg)(.{0,20})?['"][0-9a-z]{32}['"]'''
|
||||
tags = ["key", "Mailgun"]
|
||||
|
||||
[[rules]]
|
||||
description = "PayPal Braintree access token"
|
||||
regex = '''access_token\$production\$[0-9a-z]{16}\$[0-9a-f]{32}'''
|
||||
tags = ["key", "Paypal"]
|
||||
|
||||
[[rules]]
|
||||
description = "Picatic API key"
|
||||
regex = '''sk_live_[0-9a-z]{32}'''
|
||||
tags = ["key", "Picatic"]
|
||||
|
||||
[[rules]]
|
||||
description = "Slack Webhook"
|
||||
regex = '''https://hooks.slack.com/services/T[a-zA-Z0-9_]{8}/B[a-zA-Z0-9_]{8}/[a-zA-Z0-9_]{24}'''
|
||||
tags = ["key", "slack"]
|
||||
|
||||
[[rules]]
|
||||
description = "Stripe API key"
|
||||
regex = '''(?i)stripe(.{0,20})?['\"][sk|rk]_live_[0-9a-zA-Z]{24}'''
|
||||
tags = ["key", "Stripe"]
|
||||
|
||||
[[rules]]
|
||||
description = "Square access token"
|
||||
regex = '''sq0atp-[0-9A-Za-z\-_]{22}'''
|
||||
tags = ["key", "square"]
|
||||
|
||||
[[rules]]
|
||||
description = "Square OAuth secret"
|
||||
regex = '''sq0csp-[0-9A-Za-z\\-_]{43}'''
|
||||
tags = ["key", "square"]
|
||||
|
||||
[[rules]]
|
||||
description = "Twilio API key"
|
||||
regex = '''(?i)twilio(.{0,20})?['\"][0-9a-f]{32}['\"]'''
|
||||
tags = ["key", "twilio"]
|
||||
|
||||
[[rules]]
|
||||
description = "AWS Access Key"
|
||||
regex = '''(A3T[A-Z0-9]|AKIA|AGPA|AIDA|AROA|AIPA|ANPA|ANVA|ASIA)[A-Z0-9]{16}'''
|
||||
tags = ["key", "AWS"]
|
||||
[rules.allowlist]
|
||||
description = "ignore common jenkins functions"
|
||||
regexes = [
|
||||
'''allowlistme'''
|
||||
]
|
||||
files = [
|
||||
'''(.*)?Jenkinsfile$'''
|
||||
]
|
||||
|
||||
[[rules]]
|
||||
description = "Files with keys and credentials"
|
||||
file = '''(.*?)(pem)'''
|
||||
|
||||
# Global allowlist
|
||||
[allowlist]
|
||||
description = "global allowlists"
|
||||
files = [
|
||||
'''(.*?)(jpg|gif)$''',
|
||||
'''(.*?)(doc|pdf|bin)$'''
|
||||
]
|
||||
regexes = [
|
||||
'''(.*?)gitleaks:allow'''
|
||||
]
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
[[rules]]
|
||||
description = "flag go"
|
||||
file = '''(.*?)(md)$'''
|
||||
tags = ["key", "extensions"]
|
||||
@@ -0,0 +1,14 @@
|
||||
[[rules]]
|
||||
description = "entropy and regex"
|
||||
regex = '''['|"]([0-9a-zA-Z-._{}$\/\+=]{20,120})['|"]'''
|
||||
tags = ["entropy"]
|
||||
[[rules.Entropies]]
|
||||
Min = "4.5"
|
||||
Max = "4.7"
|
||||
Group = "1"
|
||||
[[rules.Entropies]]
|
||||
Min = "5.5"
|
||||
Max = "6.3"
|
||||
Group = "1"
|
||||
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
|
||||
[[rules]]
|
||||
description = "Generic password"
|
||||
regex = '''(?i)(password|token).{0,20}?\s*[:|=]\s*?(?-i)([0-9a-zA-Z\/+]{4,40})'''
|
||||
file = '''.*\.ya?ml'''
|
||||
tags = ["key", "Yml", "Yaml"]
|
||||
@@ -0,0 +1,6 @@
|
||||
|
||||
[[rules]]
|
||||
description = "AWS Access Key"
|
||||
regex = '''(A3T[A-Z0-9]|AKIA|AGPA|AIDA|AROA|AIPA|ANPA|ANVA|ASIA)[A-Z0-9]{16}'''
|
||||
path = '''config(guration)?'''
|
||||
tags = ["key", "AWS"]
|
||||
@@ -0,0 +1,7 @@
|
||||
|
||||
[[rules]]
|
||||
description = "Generic password"
|
||||
regex = '''(?i)(password|token).{0,20}?\s*[:|=]\s*?(?-i)([0-9a-zA-Z\/+]{4,40})'''
|
||||
file = '''.*\.properties'''
|
||||
path = '''config(guration)?'''
|
||||
tags = ["key", "Yml", "Yaml"]
|
||||
@@ -0,0 +1,34 @@
|
||||
[
|
||||
{
|
||||
"line": " aws_access_key_id='AKIAIO5FODNN7EXAMPLE',",
|
||||
"lineNumber": 5,
|
||||
"offender": "AKIAIO5FODNN7EXAMPLE",
|
||||
"commit": "",
|
||||
"repo": "",
|
||||
"repoURL": "",
|
||||
"leakURL": "",
|
||||
"rule": "AWS Access Key",
|
||||
"commitMessage": "",
|
||||
"author": "",
|
||||
"email": "",
|
||||
"file": "../test_data/test_repos/test_dir_1/server.test.py",
|
||||
"date": "0001-01-01T00:00:00Z",
|
||||
"tags": "key, AWS"
|
||||
},
|
||||
{
|
||||
"line": " aws_access_key_id='AKIAIO5FODNN7EXAMPLE',",
|
||||
"lineNumber": 5,
|
||||
"offender": "AKIAIO5FODNN7EXAMPLE",
|
||||
"commit": "",
|
||||
"repo": "",
|
||||
"repoURL": "",
|
||||
"leakURL": "",
|
||||
"rule": "AWS Access Key",
|
||||
"commitMessage": "",
|
||||
"author": "",
|
||||
"email": "",
|
||||
"file": "../test_data/test_repos/test_dir_1/server.test2.py",
|
||||
"date": "0001-01-01T00:00:00Z",
|
||||
"tags": "key, AWS"
|
||||
}
|
||||
]
|
||||
@@ -0,0 +1,15 @@
|
||||
[
|
||||
{
|
||||
"line": " aws_access_key_id='AKIAIO5FODNN7EXAMPLE',",
|
||||
"offender": "Entropy range [{P1:4.5 P2:4.7} {P1:5.5 P2:6.3}]",
|
||||
"commit": "6557c92612d3b35979bd426d429255b3bf9fab74",
|
||||
"repo": "test_repo_1",
|
||||
"rule": "entropy",
|
||||
"commitMessage": "commit 1 with secrets\n",
|
||||
"author": "zach rice",
|
||||
"email": "zricer@protonmail.com",
|
||||
"file": "server.test.py",
|
||||
"date": "2019-10-24T09:29:27-04:00",
|
||||
"tags": "entropy"
|
||||
}
|
||||
]
|
||||
@@ -0,0 +1,18 @@
|
||||
[
|
||||
{
|
||||
"line": " aws_access_key_id='AKIAIO5FODNN7EXAMPLE',",
|
||||
"lineNumber": 5,
|
||||
"offender": "AKIAIO5FODNN7EXAMPLE",
|
||||
"commit": "",
|
||||
"repo": "",
|
||||
"repoURL": "",
|
||||
"leakURL": "",
|
||||
"rule": "AWS Access Key",
|
||||
"commitMessage": "",
|
||||
"author": "",
|
||||
"email": "",
|
||||
"file": "../test_data/test_repos/test_dir_1/server.test.py",
|
||||
"date": "0001-01-01T00:00:00Z",
|
||||
"tags": "key, AWS"
|
||||
}
|
||||
]
|
||||
@@ -0,0 +1,370 @@
|
||||
[
|
||||
{
|
||||
"line": " aws_access_key_id='AKIAIO5FODNN7EXAMPLE',",
|
||||
"lineNumber": 5,
|
||||
"offender": "AKIAIO5FODNN7EXAMPLE",
|
||||
"commit": "6557c92612d3b35979bd426d429255b3bf9fab74",
|
||||
"repo": "test_repos",
|
||||
"repoURL": "",
|
||||
"leakURL": "",
|
||||
"rule": "AWS Access Key",
|
||||
"commitMessage": "commit 1 with secrets\n",
|
||||
"author": "zach rice",
|
||||
"email": "zricer@protonmail.com",
|
||||
"file": "server.test.py",
|
||||
"date": "2019-10-24T09:29:27-04:00",
|
||||
"tags": "key, AWS"
|
||||
},
|
||||
{
|
||||
"line": "Here's an AWS secret: \"AKIALALEMEL33243OLIAE\"",
|
||||
"lineNumber": 3,
|
||||
"offender": "AKIALALEMEL33243OLIA",
|
||||
"commit": "17471a5fda722a9e423f1a0d3f0d267ea009d41c",
|
||||
"repo": "test_repo_2",
|
||||
"repoURL": "",
|
||||
"leakURL": "",
|
||||
"rule": "AWS Access Key",
|
||||
"commitMessage": "wait this is actually adding an aws secret\n",
|
||||
"author": "zach rice",
|
||||
"email": "zricer@protonmail.com",
|
||||
"file": "secrets.md",
|
||||
"date": "2019-10-25T13:01:27-04:00",
|
||||
"tags": "key, AWS"
|
||||
},
|
||||
{
|
||||
"line": " const AWSKEY = \"AKIALALEMEL33243OLIBE\"",
|
||||
"lineNumber": 4,
|
||||
"offender": "AKIALALEMEL33243OLIB",
|
||||
"commit": "b2eb34a61c988afd9b4aaa9dd58c8dd7d5f14dba",
|
||||
"repo": "test_repo_2",
|
||||
"repoURL": "",
|
||||
"leakURL": "",
|
||||
"rule": "AWS Access Key",
|
||||
"commitMessage": "adding another one\n",
|
||||
"author": "zach rice",
|
||||
"email": "zricer@protonmail.com",
|
||||
"file": "secrets.md",
|
||||
"date": "2019-10-25T13:12:08-04:00",
|
||||
"tags": "key, AWS"
|
||||
},
|
||||
{
|
||||
"line": "Here's an AWS secret: AKIALALEMEL33243OLIAE",
|
||||
"lineNumber": 3,
|
||||
"offender": "AKIALALEMEL33243OLIA",
|
||||
"commit": "b10b3e2cb320a8c211fda94c4567299d37de7776",
|
||||
"repo": "test_repo_2",
|
||||
"repoURL": "",
|
||||
"leakURL": "",
|
||||
"rule": "AWS Access Key",
|
||||
"commitMessage": "adding aws key\n",
|
||||
"author": "zach rice",
|
||||
"email": "zricer@protonmail.com",
|
||||
"file": "secrets.md",
|
||||
"date": "2019-10-25T12:58:39-04:00",
|
||||
"tags": "key, AWS"
|
||||
},
|
||||
{
|
||||
"line": "AWS secret: \"AKIALALEMEL33243OLIAE\"",
|
||||
"lineNumber": 5,
|
||||
"offender": "AKIALALEMEL33243OLIA",
|
||||
"commit": "deea550dd6c7acaf0e59432600593533984a2125",
|
||||
"repo": "test_repo_3",
|
||||
"repoURL": "",
|
||||
"leakURL": "",
|
||||
"rule": "AWS Access Key",
|
||||
"commitMessage": "dev branch\n",
|
||||
"author": "zach rice",
|
||||
"email": "zricer@protonmail.com",
|
||||
"file": "secrets.md",
|
||||
"date": "2019-10-25T13:35:03-04:00",
|
||||
"tags": "key, AWS"
|
||||
},
|
||||
{
|
||||
"line": "const AWSKEY = \"AKIALALEMEL33243OLIAE\"",
|
||||
"lineNumber": 3,
|
||||
"offender": "AKIALALEMEL33243OLIA",
|
||||
"commit": "84ac4e80d4dbf2c968b64e9d4005f5079795bb81",
|
||||
"repo": "test_repo_3",
|
||||
"repoURL": "",
|
||||
"leakURL": "",
|
||||
"rule": "AWS Access Key",
|
||||
"commitMessage": "more secrets\n",
|
||||
"author": "zach rice",
|
||||
"email": "zricer@protonmail.com",
|
||||
"file": "secrets.md",
|
||||
"date": "2019-10-25T13:54:08-04:00",
|
||||
"tags": "key, AWS"
|
||||
},
|
||||
{
|
||||
"line": "Here's an AWS secret: \"AKIALALEMEL33243OLIAE\"",
|
||||
"lineNumber": 3,
|
||||
"offender": "AKIALALEMEL33243OLIA",
|
||||
"commit": "17471a5fda722a9e423f1a0d3f0d267ea009d41c",
|
||||
"repo": "test_repo_3",
|
||||
"repoURL": "",
|
||||
"leakURL": "",
|
||||
"rule": "AWS Access Key",
|
||||
"commitMessage": "wait this is actually adding an aws secret\n",
|
||||
"author": "zach rice",
|
||||
"email": "zricer@protonmail.com",
|
||||
"file": "secrets.md",
|
||||
"date": "2019-10-25T13:01:27-04:00",
|
||||
"tags": "key, AWS"
|
||||
},
|
||||
{
|
||||
"line": "Here's an AWS secret: AKIALALEMEL33243OLIAE",
|
||||
"lineNumber": 3,
|
||||
"offender": "AKIALALEMEL33243OLIA",
|
||||
"commit": "b10b3e2cb320a8c211fda94c4567299d37de7776",
|
||||
"repo": "test_repo_3",
|
||||
"repoURL": "",
|
||||
"leakURL": "",
|
||||
"rule": "AWS Access Key",
|
||||
"commitMessage": "adding aws key\n",
|
||||
"author": "zach rice",
|
||||
"email": "zricer@protonmail.com",
|
||||
"file": "secrets.md",
|
||||
"date": "2019-10-25T12:58:39-04:00",
|
||||
"tags": "key, AWS"
|
||||
},
|
||||
{
|
||||
"line": " const AWSKEY = \"AKIALALEMEL33243OLIBE\"",
|
||||
"lineNumber": 4,
|
||||
"offender": "AKIALALEMEL33243OLIB",
|
||||
"commit": "b2eb34a61c988afd9b4aaa9dd58c8dd7d5f14dba",
|
||||
"repo": "test_repo_3",
|
||||
"repoURL": "",
|
||||
"leakURL": "",
|
||||
"rule": "AWS Access Key",
|
||||
"commitMessage": "adding another one\n",
|
||||
"author": "zach rice",
|
||||
"email": "zricer@protonmail.com",
|
||||
"file": "secrets.md",
|
||||
"date": "2019-10-25T13:12:08-04:00",
|
||||
"tags": "key, AWS"
|
||||
},
|
||||
{
|
||||
"line": "AWS secret: \"AKIALALEMEL33243OLIAE\"",
|
||||
"lineNumber": 5,
|
||||
"offender": "AKIALALEMEL33243OLIA",
|
||||
"commit": "deea550dd6c7acaf0e59432600593533984a2125",
|
||||
"repo": "test_repo_4",
|
||||
"repoURL": "",
|
||||
"leakURL": "",
|
||||
"rule": "AWS Access Key",
|
||||
"commitMessage": "dev branch\n",
|
||||
"author": "zach rice",
|
||||
"email": "zricer@protonmail.com",
|
||||
"file": "secrets.md",
|
||||
"date": "2019-10-25T13:35:03-04:00",
|
||||
"tags": "key, AWS"
|
||||
},
|
||||
{
|
||||
"line": "const AWSKEY = \"AKIALALEMEL33243OLIAE\"",
|
||||
"lineNumber": 3,
|
||||
"offender": "AKIALALEMEL33243OLIA",
|
||||
"commit": "84ac4e80d4dbf2c968b64e9d4005f5079795bb81",
|
||||
"repo": "test_repo_4",
|
||||
"repoURL": "",
|
||||
"leakURL": "",
|
||||
"rule": "AWS Access Key",
|
||||
"commitMessage": "more secrets\n",
|
||||
"author": "zach rice",
|
||||
"email": "zricer@protonmail.com",
|
||||
"file": "secrets.md",
|
||||
"date": "2019-10-25T13:54:08-04:00",
|
||||
"tags": "key, AWS"
|
||||
},
|
||||
{
|
||||
"line": "Here's an AWS secret: AKIALALEMEL33243OLIAE",
|
||||
"lineNumber": 3,
|
||||
"offender": "AKIALALEMEL33243OLIA",
|
||||
"commit": "b10b3e2cb320a8c211fda94c4567299d37de7776",
|
||||
"repo": "test_repo_4",
|
||||
"repoURL": "",
|
||||
"leakURL": "",
|
||||
"rule": "AWS Access Key",
|
||||
"commitMessage": "adding aws key\n",
|
||||
"author": "zach rice",
|
||||
"email": "zricer@protonmail.com",
|
||||
"file": "secrets.md",
|
||||
"date": "2019-10-25T12:58:39-04:00",
|
||||
"tags": "key, AWS"
|
||||
},
|
||||
{
|
||||
"line": " const AWSKEY = \"AKIALALEMEL33243OLIBE\"",
|
||||
"lineNumber": 4,
|
||||
"offender": "AKIALALEMEL33243OLIB",
|
||||
"commit": "b2eb34a61c988afd9b4aaa9dd58c8dd7d5f14dba",
|
||||
"repo": "test_repo_4",
|
||||
"repoURL": "",
|
||||
"leakURL": "",
|
||||
"rule": "AWS Access Key",
|
||||
"commitMessage": "adding another one\n",
|
||||
"author": "zach rice",
|
||||
"email": "zricer@protonmail.com",
|
||||
"file": "secrets.md",
|
||||
"date": "2019-10-25T13:12:08-04:00",
|
||||
"tags": "key, AWS"
|
||||
},
|
||||
{
|
||||
"line": "Here's an AWS secret: \"AKIALALEMEL33243OLIAE\"",
|
||||
"lineNumber": 3,
|
||||
"offender": "AKIALALEMEL33243OLIA",
|
||||
"commit": "17471a5fda722a9e423f1a0d3f0d267ea009d41c",
|
||||
"repo": "test_repo_4",
|
||||
"repoURL": "",
|
||||
"leakURL": "",
|
||||
"rule": "AWS Access Key",
|
||||
"commitMessage": "wait this is actually adding an aws secret\n",
|
||||
"author": "zach rice",
|
||||
"email": "zricer@protonmail.com",
|
||||
"file": "secrets.md",
|
||||
"date": "2019-10-25T13:01:27-04:00",
|
||||
"tags": "key, AWS"
|
||||
},
|
||||
{
|
||||
"line": "aws_access_key_id='AKIAIO5FODNN7EXAMPLE'",
|
||||
"lineNumber": 1,
|
||||
"offender": "AKIAIO5FODNN7EXAMPLE",
|
||||
"commit": "1f2a4abc47dabf991e6af6f9770867ce0ac1f360",
|
||||
"repo": "test_repo_5",
|
||||
"repoURL": "",
|
||||
"leakURL": "",
|
||||
"rule": "AWS Access Key",
|
||||
"commitMessage": "introduce secrets\n",
|
||||
"author": "Zach Rice",
|
||||
"email": "zrice@gitlab.com",
|
||||
"file": "secrets.py",
|
||||
"date": "2020-02-01T10:07:34-05:00",
|
||||
"tags": "key, AWS"
|
||||
},
|
||||
{
|
||||
"line": "aws_access_key_id='AKIAIO5FODNN7EXAMPL2'",
|
||||
"lineNumber": 4,
|
||||
"offender": "AKIAIO5FODNN7EXAMPL2",
|
||||
"commit": "ca71fcdeda15f25f0cc661d90e8785c255925c27",
|
||||
"repo": "test_repo_5",
|
||||
"repoURL": "",
|
||||
"leakURL": "",
|
||||
"rule": "AWS Access Key",
|
||||
"commitMessage": "introduce more secrets\n",
|
||||
"author": "Zach Rice",
|
||||
"email": "zrice@gitlab.com",
|
||||
"file": "secrets.py",
|
||||
"date": "2020-02-01T10:08:04-05:00",
|
||||
"tags": "key, AWS"
|
||||
},
|
||||
{
|
||||
"line": " aws_access_key_id='AKIAIO5FODNN7EXAMPLE',",
|
||||
"lineNumber": 5,
|
||||
"offender": "AKIAIO5FODNN7EXAMPLE",
|
||||
"commit": "6557c92612d3b35979bd426d429255b3bf9fab74",
|
||||
"repo": "test_repos",
|
||||
"repoURL": "",
|
||||
"leakURL": "",
|
||||
"rule": "AWS Access Key",
|
||||
"commitMessage": "commit 1 with secrets\n",
|
||||
"author": "zach rice",
|
||||
"email": "zricer@protonmail.com",
|
||||
"file": "server.test.py",
|
||||
"date": "2019-10-24T09:29:27-04:00",
|
||||
"tags": "key, AWS"
|
||||
},
|
||||
{
|
||||
"line": "aws_access_key_id=AKIAIO5FODNN7EXAMPLE",
|
||||
"lineNumber": 3,
|
||||
"offender": "AKIAIO5FODNN7EXAMPLE",
|
||||
"commit": "98b6c7cb3fb29a5993c4c95c56a2dc53050b9247",
|
||||
"repo": "test_repo_6",
|
||||
"repoURL": "",
|
||||
"leakURL": "",
|
||||
"rule": "AWS Access Key",
|
||||
"commitMessage": "Adding some secrets in config folder\n\n",
|
||||
"author": "Noel Algora",
|
||||
"email": "noealgigu@gmail.com",
|
||||
"file": "config/application.properties",
|
||||
"date": "2020-02-24T14:13:15-05:00",
|
||||
"tags": "key, AWS"
|
||||
},
|
||||
{
|
||||
"line": "aws_access_key_id='AKIAIO5FODNN7EXAMPLE',",
|
||||
"lineNumber": 2,
|
||||
"offender": "AKIAIO5FODNN7EXAMPLE",
|
||||
"commit": "ce7e8177bbf8a172c06b6a1e370a374d5c19f660",
|
||||
"repo": "test_repo_8",
|
||||
"repoURL": "",
|
||||
"leakURL": "",
|
||||
"rule": "AWS Access Key",
|
||||
"commitMessage": "dummy.txt w/ text",
|
||||
"author": "Zachary Rice",
|
||||
"email": "zricer@protonmail.com",
|
||||
"file": "dummy.txt",
|
||||
"date": "2020-07-25T14:39:11-04:00",
|
||||
"tags": "key, AWS"
|
||||
},
|
||||
{
|
||||
"line": "aws_access_key_id='AKIAIO5FODNN7EXAMPLE',",
|
||||
"lineNumber": 6,
|
||||
"offender": "AKIAIO5FODNN7EXAMPLE",
|
||||
"commit": "9267bc86ec1497471cbc6f3308f3527f7ef34b9d",
|
||||
"repo": "test_repo_8",
|
||||
"repoURL": "",
|
||||
"leakURL": "",
|
||||
"rule": "AWS Access Key",
|
||||
"commitMessage": "Update dummy.txt",
|
||||
"author": "Zachary Rice",
|
||||
"email": "zricer@protonmail.com",
|
||||
"file": "dummy.txt",
|
||||
"date": "2020-07-25T14:41:11-04:00",
|
||||
"tags": "key, AWS"
|
||||
},
|
||||
{
|
||||
"line": "aws_access_key_id='AKIAIO5FODNN7EXAMPLE',",
|
||||
"lineNumber": 6,
|
||||
"offender": "AKIAIO5FODNN7EXAMPLE",
|
||||
"commit": "748f11eaf2c38c3cf0ac6a22e44208777e79fa6f",
|
||||
"repo": "test_repo_8",
|
||||
"repoURL": "",
|
||||
"leakURL": "",
|
||||
"rule": "AWS Access Key",
|
||||
"commitMessage": "Merge pull request #1 from zricethezav/additional-secret-branch\n\nUpdate dummy.txt",
|
||||
"author": "Zachary Rice",
|
||||
"email": "zricer@protonmail.com",
|
||||
"file": "dummy.txt",
|
||||
"date": "2020-07-25T14:44:48-04:00",
|
||||
"tags": "key, AWS"
|
||||
},
|
||||
{
|
||||
"line": " aws_access_key_id='AKIAIO5FODNN7EXAMPLE', #gitleaks:allow",
|
||||
"lineNumber": 5,
|
||||
"offender": "AKIAIO5FODNN7EXAMPLE",
|
||||
"commit": "8d1fb60d2d80f0590f191ed5ace1e45ef780909a",
|
||||
"repo": "test_repo_9",
|
||||
"repoURL": "",
|
||||
"leakURL": "",
|
||||
"rule": "AWS Access Key",
|
||||
"commitMessage": "gitleaks allow secret\n",
|
||||
"author": "Zach Rice",
|
||||
"email": "zrice@gitlab.com",
|
||||
"file": "server.test.py",
|
||||
"date": "2020-08-12T13:36:20-04:00",
|
||||
"tags": "key, AWS"
|
||||
},
|
||||
{
|
||||
"line": " aws_access_key_id='AKIAIO5FODNN7EXAMPLE',",
|
||||
"lineNumber": 5,
|
||||
"offender": "AKIAIO5FODNN7EXAMPLE",
|
||||
"commit": "6557c92612d3b35979bd426d429255b3bf9fab74",
|
||||
"repo": "test_repos",
|
||||
"repoURL": "",
|
||||
"leakURL": "",
|
||||
"rule": "AWS Access Key",
|
||||
"commitMessage": "commit 1 with secrets\n",
|
||||
"author": "zach rice",
|
||||
"email": "zricer@protonmail.com",
|
||||
"file": "server.test.py",
|
||||
"date": "2019-10-24T09:29:27-04:00",
|
||||
"tags": "key, AWS"
|
||||
}
|
||||
]
|
||||
@@ -0,0 +1,354 @@
|
||||
[
|
||||
{
|
||||
"line": " const AWSKEY = \"AKIALALEMEL33243OLIBE\"",
|
||||
"lineNumber": 4,
|
||||
"offender": "AKIALALEMEL33243OLIB",
|
||||
"commit": "b2eb34a61c988afd9b4aaa9dd58c8dd7d5f14dba",
|
||||
"repo": "test_repo_2",
|
||||
"repoURL": "",
|
||||
"leakURL": "",
|
||||
"rule": "AWS Access Key",
|
||||
"commitMessage": "adding another one\n",
|
||||
"author": "zach rice",
|
||||
"email": "zricer@protonmail.com",
|
||||
"file": "secrets.md",
|
||||
"date": "2019-10-25T13:12:08-04:00",
|
||||
"tags": "key, AWS"
|
||||
},
|
||||
{
|
||||
"line": "Here's an AWS secret: \"AKIALALEMEL33243OLIAE\"",
|
||||
"lineNumber": 3,
|
||||
"offender": "AKIALALEMEL33243OLIA",
|
||||
"commit": "17471a5fda722a9e423f1a0d3f0d267ea009d41c",
|
||||
"repo": "test_repo_2",
|
||||
"repoURL": "",
|
||||
"leakURL": "",
|
||||
"rule": "AWS Access Key",
|
||||
"commitMessage": "wait this is actually adding an aws secret\n",
|
||||
"author": "zach rice",
|
||||
"email": "zricer@protonmail.com",
|
||||
"file": "secrets.md",
|
||||
"date": "2019-10-25T13:01:27-04:00",
|
||||
"tags": "key, AWS"
|
||||
},
|
||||
{
|
||||
"line": "Here's an AWS secret: AKIALALEMEL33243OLIAE",
|
||||
"lineNumber": 3,
|
||||
"offender": "AKIALALEMEL33243OLIA",
|
||||
"commit": "b10b3e2cb320a8c211fda94c4567299d37de7776",
|
||||
"repo": "test_repo_2",
|
||||
"repoURL": "",
|
||||
"leakURL": "",
|
||||
"rule": "AWS Access Key",
|
||||
"commitMessage": "adding aws key\n",
|
||||
"author": "zach rice",
|
||||
"email": "zricer@protonmail.com",
|
||||
"file": "secrets.md",
|
||||
"date": "2019-10-25T12:58:39-04:00",
|
||||
"tags": "key, AWS"
|
||||
},
|
||||
{
|
||||
"line": "const AWSKEY = \"AKIALALEMEL33243OLIAE\"",
|
||||
"lineNumber": 3,
|
||||
"offender": "AKIALALEMEL33243OLIA",
|
||||
"commit": "84ac4e80d4dbf2c968b64e9d4005f5079795bb81",
|
||||
"repo": "test_repo_3",
|
||||
"repoURL": "",
|
||||
"leakURL": "",
|
||||
"rule": "AWS Access Key",
|
||||
"commitMessage": "more secrets\n",
|
||||
"author": "zach rice",
|
||||
"email": "zricer@protonmail.com",
|
||||
"file": "secrets.md",
|
||||
"date": "2019-10-25T13:54:08-04:00",
|
||||
"tags": "key, AWS"
|
||||
},
|
||||
{
|
||||
"line": "AWS secret: \"AKIALALEMEL33243OLIAE\"",
|
||||
"lineNumber": 5,
|
||||
"offender": "AKIALALEMEL33243OLIA",
|
||||
"commit": "deea550dd6c7acaf0e59432600593533984a2125",
|
||||
"repo": "test_repo_3",
|
||||
"repoURL": "",
|
||||
"leakURL": "",
|
||||
"rule": "AWS Access Key",
|
||||
"commitMessage": "dev branch\n",
|
||||
"author": "zach rice",
|
||||
"email": "zricer@protonmail.com",
|
||||
"file": "secrets.md",
|
||||
"date": "2019-10-25T13:35:03-04:00",
|
||||
"tags": "key, AWS"
|
||||
},
|
||||
{
|
||||
"line": " const AWSKEY = \"AKIALALEMEL33243OLIBE\"",
|
||||
"lineNumber": 4,
|
||||
"offender": "AKIALALEMEL33243OLIB",
|
||||
"commit": "b2eb34a61c988afd9b4aaa9dd58c8dd7d5f14dba",
|
||||
"repo": "test_repo_3",
|
||||
"repoURL": "",
|
||||
"leakURL": "",
|
||||
"rule": "AWS Access Key",
|
||||
"commitMessage": "adding another one\n",
|
||||
"author": "zach rice",
|
||||
"email": "zricer@protonmail.com",
|
||||
"file": "secrets.md",
|
||||
"date": "2019-10-25T13:12:08-04:00",
|
||||
"tags": "key, AWS"
|
||||
},
|
||||
{
|
||||
"line": "Here's an AWS secret: \"AKIALALEMEL33243OLIAE\"",
|
||||
"lineNumber": 3,
|
||||
"offender": "AKIALALEMEL33243OLIA",
|
||||
"commit": "17471a5fda722a9e423f1a0d3f0d267ea009d41c",
|
||||
"repo": "test_repo_3",
|
||||
"repoURL": "",
|
||||
"leakURL": "",
|
||||
"rule": "AWS Access Key",
|
||||
"commitMessage": "wait this is actually adding an aws secret\n",
|
||||
"author": "zach rice",
|
||||
"email": "zricer@protonmail.com",
|
||||
"file": "secrets.md",
|
||||
"date": "2019-10-25T13:01:27-04:00",
|
||||
"tags": "key, AWS"
|
||||
},
|
||||
{
|
||||
"line": "Here's an AWS secret: AKIALALEMEL33243OLIAE",
|
||||
"lineNumber": 3,
|
||||
"offender": "AKIALALEMEL33243OLIA",
|
||||
"commit": "b10b3e2cb320a8c211fda94c4567299d37de7776",
|
||||
"repo": "test_repo_3",
|
||||
"repoURL": "",
|
||||
"leakURL": "",
|
||||
"rule": "AWS Access Key",
|
||||
"commitMessage": "adding aws key\n",
|
||||
"author": "zach rice",
|
||||
"email": "zricer@protonmail.com",
|
||||
"file": "secrets.md",
|
||||
"date": "2019-10-25T12:58:39-04:00",
|
||||
"tags": "key, AWS"
|
||||
},
|
||||
{
|
||||
"line": "const AWSKEY = \"AKIALALEMEL33243OLIAE\"",
|
||||
"lineNumber": 3,
|
||||
"offender": "AKIALALEMEL33243OLIA",
|
||||
"commit": "84ac4e80d4dbf2c968b64e9d4005f5079795bb81",
|
||||
"repo": "test_repo_4",
|
||||
"repoURL": "",
|
||||
"leakURL": "",
|
||||
"rule": "AWS Access Key",
|
||||
"commitMessage": "more secrets\n",
|
||||
"author": "zach rice",
|
||||
"email": "zricer@protonmail.com",
|
||||
"file": "secrets.md",
|
||||
"date": "2019-10-25T13:54:08-04:00",
|
||||
"tags": "key, AWS"
|
||||
},
|
||||
{
|
||||
"line": "AWS secret: \"AKIALALEMEL33243OLIAE\"",
|
||||
"lineNumber": 5,
|
||||
"offender": "AKIALALEMEL33243OLIA",
|
||||
"commit": "deea550dd6c7acaf0e59432600593533984a2125",
|
||||
"repo": "test_repo_4",
|
||||
"repoURL": "",
|
||||
"leakURL": "",
|
||||
"rule": "AWS Access Key",
|
||||
"commitMessage": "dev branch\n",
|
||||
"author": "zach rice",
|
||||
"email": "zricer@protonmail.com",
|
||||
"file": "secrets.md",
|
||||
"date": "2019-10-25T13:35:03-04:00",
|
||||
"tags": "key, AWS"
|
||||
},
|
||||
{
|
||||
"line": " const AWSKEY = \"AKIALALEMEL33243OLIBE\"",
|
||||
"lineNumber": 4,
|
||||
"offender": "AKIALALEMEL33243OLIB",
|
||||
"commit": "b2eb34a61c988afd9b4aaa9dd58c8dd7d5f14dba",
|
||||
"repo": "test_repo_4",
|
||||
"repoURL": "",
|
||||
"leakURL": "",
|
||||
"rule": "AWS Access Key",
|
||||
"commitMessage": "adding another one\n",
|
||||
"author": "zach rice",
|
||||
"email": "zricer@protonmail.com",
|
||||
"file": "secrets.md",
|
||||
"date": "2019-10-25T13:12:08-04:00",
|
||||
"tags": "key, AWS"
|
||||
},
|
||||
{
|
||||
"line": "Here's an AWS secret: \"AKIALALEMEL33243OLIAE\"",
|
||||
"lineNumber": 3,
|
||||
"offender": "AKIALALEMEL33243OLIA",
|
||||
"commit": "17471a5fda722a9e423f1a0d3f0d267ea009d41c",
|
||||
"repo": "test_repo_4",
|
||||
"repoURL": "",
|
||||
"leakURL": "",
|
||||
"rule": "AWS Access Key",
|
||||
"commitMessage": "wait this is actually adding an aws secret\n",
|
||||
"author": "zach rice",
|
||||
"email": "zricer@protonmail.com",
|
||||
"file": "secrets.md",
|
||||
"date": "2019-10-25T13:01:27-04:00",
|
||||
"tags": "key, AWS"
|
||||
},
|
||||
{
|
||||
"line": "Here's an AWS secret: AKIALALEMEL33243OLIAE",
|
||||
"lineNumber": 3,
|
||||
"offender": "AKIALALEMEL33243OLIA",
|
||||
"commit": "b10b3e2cb320a8c211fda94c4567299d37de7776",
|
||||
"repo": "test_repo_4",
|
||||
"repoURL": "",
|
||||
"leakURL": "",
|
||||
"rule": "AWS Access Key",
|
||||
"commitMessage": "adding aws key\n",
|
||||
"author": "zach rice",
|
||||
"email": "zricer@protonmail.com",
|
||||
"file": "secrets.md",
|
||||
"date": "2019-10-25T12:58:39-04:00",
|
||||
"tags": "key, AWS"
|
||||
},
|
||||
{
|
||||
"line": "aws_access_key_id='AKIAIO5FODNN7EXAMPL2'",
|
||||
"lineNumber": 4,
|
||||
"offender": "AKIAIO5FODNN7EXAMPL2",
|
||||
"commit": "ca71fcdeda15f25f0cc661d90e8785c255925c27",
|
||||
"repo": "test_repo_5",
|
||||
"repoURL": "",
|
||||
"leakURL": "",
|
||||
"rule": "AWS Access Key",
|
||||
"commitMessage": "introduce more secrets\n",
|
||||
"author": "Zach Rice",
|
||||
"email": "zrice@gitlab.com",
|
||||
"file": "secrets.py",
|
||||
"date": "2020-02-01T10:08:04-05:00",
|
||||
"tags": "key, AWS"
|
||||
},
|
||||
{
|
||||
"line": "aws_access_key_id='AKIAIO5FODNN7EXAMPLE'",
|
||||
"lineNumber": 1,
|
||||
"offender": "AKIAIO5FODNN7EXAMPLE",
|
||||
"commit": "1f2a4abc47dabf991e6af6f9770867ce0ac1f360",
|
||||
"repo": "test_repo_5",
|
||||
"repoURL": "",
|
||||
"leakURL": "",
|
||||
"rule": "AWS Access Key",
|
||||
"commitMessage": "introduce secrets\n",
|
||||
"author": "Zach Rice",
|
||||
"email": "zrice@gitlab.com",
|
||||
"file": "secrets.py",
|
||||
"date": "2020-02-01T10:07:34-05:00",
|
||||
"tags": "key, AWS"
|
||||
},
|
||||
{
|
||||
"line": "aws_access_key_id=AKIAIO5FODNN7EXAMPLE",
|
||||
"lineNumber": 3,
|
||||
"offender": "AKIAIO5FODNN7EXAMPLE",
|
||||
"commit": "98b6c7cb3fb29a5993c4c95c56a2dc53050b9247",
|
||||
"repo": "test_repo_6",
|
||||
"repoURL": "",
|
||||
"leakURL": "",
|
||||
"rule": "AWS Access Key",
|
||||
"commitMessage": "Adding some secrets in config folder\n\n",
|
||||
"author": "Noel Algora",
|
||||
"email": "noealgigu@gmail.com",
|
||||
"file": "config/application.properties",
|
||||
"date": "2020-02-24T14:13:15-05:00",
|
||||
"tags": "key, AWS"
|
||||
},
|
||||
{
|
||||
"line": " aws_access_key_id='AKIAIO5FODNN7EXAMPLE',",
|
||||
"lineNumber": 5,
|
||||
"offender": "AKIAIO5FODNN7EXAMPLE",
|
||||
"commit": "6557c92612d3b35979bd426d429255b3bf9fab74",
|
||||
"repo": "test_repos",
|
||||
"repoURL": "",
|
||||
"leakURL": "",
|
||||
"rule": "AWS Access Key",
|
||||
"commitMessage": "commit 1 with secrets\n",
|
||||
"author": "zach rice",
|
||||
"email": "zricer@protonmail.com",
|
||||
"file": "server.test.py",
|
||||
"date": "2019-10-24T09:29:27-04:00",
|
||||
"tags": "key, AWS"
|
||||
},
|
||||
{
|
||||
"line": "aws_access_key_id='AKIAIO5FODNN7EXAMPLE',",
|
||||
"lineNumber": 6,
|
||||
"offender": "AKIAIO5FODNN7EXAMPLE",
|
||||
"commit": "748f11eaf2c38c3cf0ac6a22e44208777e79fa6f",
|
||||
"repo": "test_repo_8",
|
||||
"repoURL": "",
|
||||
"leakURL": "",
|
||||
"rule": "AWS Access Key",
|
||||
"commitMessage": "Merge pull request #1 from zricethezav/additional-secret-branch\n\nUpdate dummy.txt",
|
||||
"author": "Zachary Rice",
|
||||
"email": "zricer@protonmail.com",
|
||||
"file": "dummy.txt",
|
||||
"date": "2020-07-25T14:44:48-04:00",
|
||||
"tags": "key, AWS"
|
||||
},
|
||||
{
|
||||
"line": "aws_access_key_id='AKIAIO5FODNN7EXAMPLE',",
|
||||
"lineNumber": 2,
|
||||
"offender": "AKIAIO5FODNN7EXAMPLE",
|
||||
"commit": "ce7e8177bbf8a172c06b6a1e370a374d5c19f660",
|
||||
"repo": "test_repo_8",
|
||||
"repoURL": "",
|
||||
"leakURL": "",
|
||||
"rule": "AWS Access Key",
|
||||
"commitMessage": "dummy.txt w/ text",
|
||||
"author": "Zachary Rice",
|
||||
"email": "zricer@protonmail.com",
|
||||
"file": "dummy.txt",
|
||||
"date": "2020-07-25T14:39:11-04:00",
|
||||
"tags": "key, AWS"
|
||||
},
|
||||
{
|
||||
"line": "aws_access_key_id='AKIAIO5FODNN7EXAMPLE',",
|
||||
"lineNumber": 6,
|
||||
"offender": "AKIAIO5FODNN7EXAMPLE",
|
||||
"commit": "9267bc86ec1497471cbc6f3308f3527f7ef34b9d",
|
||||
"repo": "test_repo_8",
|
||||
"repoURL": "",
|
||||
"leakURL": "",
|
||||
"rule": "AWS Access Key",
|
||||
"commitMessage": "Update dummy.txt",
|
||||
"author": "Zachary Rice",
|
||||
"email": "zricer@protonmail.com",
|
||||
"file": "dummy.txt",
|
||||
"date": "2020-07-25T14:41:11-04:00",
|
||||
"tags": "key, AWS"
|
||||
},
|
||||
{
|
||||
"line": " aws_access_key_id='AKIAIO5FODNN7EXAMPLE', #gitleaks:allow",
|
||||
"lineNumber": 5,
|
||||
"offender": "AKIAIO5FODNN7EXAMPLE",
|
||||
"commit": "8d1fb60d2d80f0590f191ed5ace1e45ef780909a",
|
||||
"repo": "test_repo_9",
|
||||
"repoURL": "",
|
||||
"leakURL": "",
|
||||
"rule": "AWS Access Key",
|
||||
"commitMessage": "gitleaks allow secret\n",
|
||||
"author": "Zach Rice",
|
||||
"email": "zrice@gitlab.com",
|
||||
"file": "server.test.py",
|
||||
"date": "2020-08-12T13:36:20-04:00",
|
||||
"tags": "key, AWS"
|
||||
},
|
||||
{
|
||||
"line": " aws_access_key_id='AKIAIO5FODNN7EXAMPLE',",
|
||||
"lineNumber": 5,
|
||||
"offender": "AKIAIO5FODNN7EXAMPLE",
|
||||
"commit": "6557c92612d3b35979bd426d429255b3bf9fab74",
|
||||
"repo": "test_repos",
|
||||
"repoURL": "",
|
||||
"leakURL": "",
|
||||
"rule": "AWS Access Key",
|
||||
"commitMessage": "commit 1 with secrets\n",
|
||||
"author": "zach rice",
|
||||
"email": "zricer@protonmail.com",
|
||||
"file": "server.test.py",
|
||||
"date": "2019-10-24T09:29:27-04:00",
|
||||
"tags": "key, AWS"
|
||||
}
|
||||
]
|
||||
@@ -0,0 +1,114 @@
|
||||
[
|
||||
{
|
||||
"line": " aws_access_key_id='AKIAIO5FODNN7EXAMPLE',",
|
||||
"lineNumber": 5,
|
||||
"offender": "AKIAIO5FODNN7EXAMPLE",
|
||||
"commit": "6557c92612d3b35979bd426d429255b3bf9fab74",
|
||||
"repo": "test_repos",
|
||||
"repoURL": "",
|
||||
"leakURL": "",
|
||||
"rule": "AWS Access Key",
|
||||
"commitMessage": "commit 1 with secrets\n",
|
||||
"author": "zach rice",
|
||||
"email": "zricer@protonmail.com",
|
||||
"file": "server.test.py",
|
||||
"date": "2019-10-24T09:29:27-04:00",
|
||||
"tags": "key, AWS"
|
||||
},
|
||||
{
|
||||
"line": " const AWSKEY = \"AKIALALEMEL33243OLIBE\"",
|
||||
"lineNumber": 4,
|
||||
"offender": "AKIALALEMEL33243OLIB",
|
||||
"commit": "b2eb34a61c988afd9b4aaa9dd58c8dd7d5f14dba",
|
||||
"repo": "test_repo_2",
|
||||
"repoURL": "",
|
||||
"leakURL": "",
|
||||
"rule": "AWS Access Key",
|
||||
"commitMessage": "adding another one\n",
|
||||
"author": "zach rice",
|
||||
"email": "zricer@protonmail.com",
|
||||
"file": "secrets.md",
|
||||
"date": "2019-10-25T13:12:08-04:00",
|
||||
"tags": "key, AWS"
|
||||
},
|
||||
{
|
||||
"line": "const AWSKEY = \"AKIALALEMEL33243OLIAE\"",
|
||||
"lineNumber": 3,
|
||||
"offender": "AKIALALEMEL33243OLIA",
|
||||
"commit": "84ac4e80d4dbf2c968b64e9d4005f5079795bb81",
|
||||
"repo": "test_repo_3",
|
||||
"repoURL": "",
|
||||
"leakURL": "",
|
||||
"rule": "AWS Access Key",
|
||||
"commitMessage": "more secrets\n",
|
||||
"author": "zach rice",
|
||||
"email": "zricer@protonmail.com",
|
||||
"file": "secrets.md",
|
||||
"date": "2019-10-25T13:54:08-04:00",
|
||||
"tags": "key, AWS"
|
||||
},
|
||||
{
|
||||
"line": "aws_access_key_id='AKIAIO5FODNN7EXAMPL2'",
|
||||
"lineNumber": 4,
|
||||
"offender": "AKIAIO5FODNN7EXAMPL2",
|
||||
"commit": "ca71fcdeda15f25f0cc661d90e8785c255925c27",
|
||||
"repo": "test_repo_5",
|
||||
"repoURL": "",
|
||||
"leakURL": "",
|
||||
"rule": "AWS Access Key",
|
||||
"commitMessage": "introduce more secrets\n",
|
||||
"author": "Zach Rice",
|
||||
"email": "zrice@gitlab.com",
|
||||
"file": "secrets.py",
|
||||
"date": "2020-02-01T10:08:04-05:00",
|
||||
"tags": "key, AWS"
|
||||
},
|
||||
{
|
||||
"line": "aws_access_key_id=AKIAIO5FODNN7EXAMPLE",
|
||||
"lineNumber": 3,
|
||||
"offender": "AKIAIO5FODNN7EXAMPLE",
|
||||
"commit": "98b6c7cb3fb29a5993c4c95c56a2dc53050b9247",
|
||||
"repo": "test_repo_6",
|
||||
"repoURL": "",
|
||||
"leakURL": "",
|
||||
"rule": "AWS Access Key",
|
||||
"commitMessage": "Adding some secrets in config folder\n\n",
|
||||
"author": "Noel Algora",
|
||||
"email": "noealgigu@gmail.com",
|
||||
"file": "config/application.properties",
|
||||
"date": "2020-02-24T14:13:15-05:00",
|
||||
"tags": "key, AWS"
|
||||
},
|
||||
{
|
||||
"line": "aws_access_key_id='AKIAIO5FODNN7EXAMPLE',",
|
||||
"lineNumber": 6,
|
||||
"offender": "AKIAIO5FODNN7EXAMPLE",
|
||||
"commit": "748f11eaf2c38c3cf0ac6a22e44208777e79fa6f",
|
||||
"repo": "test_repo_8",
|
||||
"repoURL": "",
|
||||
"leakURL": "",
|
||||
"rule": "AWS Access Key",
|
||||
"commitMessage": "Merge pull request #1 from zricethezav/additional-secret-branch\n\nUpdate dummy.txt",
|
||||
"author": "Zachary Rice",
|
||||
"email": "zricer@protonmail.com",
|
||||
"file": "dummy.txt",
|
||||
"date": "2020-07-25T14:44:48-04:00",
|
||||
"tags": "key, AWS"
|
||||
},
|
||||
{
|
||||
"line": " aws_access_key_id='AKIAIO5FODNN7EXAMPLE', #gitleaks:allow",
|
||||
"lineNumber": 5,
|
||||
"offender": "AKIAIO5FODNN7EXAMPLE",
|
||||
"commit": "8d1fb60d2d80f0590f191ed5ace1e45ef780909a",
|
||||
"repo": "test_repo_9",
|
||||
"repoURL": "",
|
||||
"leakURL": "",
|
||||
"rule": "AWS Access Key",
|
||||
"commitMessage": "gitleaks allow secret\n",
|
||||
"author": "Zach Rice",
|
||||
"email": "zrice@gitlab.com",
|
||||
"file": "server.test.py",
|
||||
"date": "2020-08-12T13:36:20-04:00",
|
||||
"tags": "key, AWS"
|
||||
}
|
||||
]
|
||||
@@ -0,0 +1,50 @@
|
||||
[
|
||||
{
|
||||
"line": "aws_access_key_id='AKIAIO5FODNN7EXAMPLE',",
|
||||
"lineNumber": 6,
|
||||
"offender": "AKIAIO5FODNN7EXAMPLE",
|
||||
"commit": "748f11eaf2c38c3cf0ac6a22e44208777e79fa6f",
|
||||
"repo": "test_repo_8",
|
||||
"repoURL": "",
|
||||
"leakURL": "",
|
||||
"rule": "AWS Access Key",
|
||||
"commitMessage": "Merge pull request #1 from zricethezav/additional-secret-branch\n\nUpdate dummy.txt",
|
||||
"author": "Zachary Rice",
|
||||
"email": "zricer@protonmail.com",
|
||||
"file": "dummy.txt",
|
||||
"date": "2020-07-25T14:44:48-04:00",
|
||||
"tags": "key, AWS"
|
||||
},
|
||||
{
|
||||
"line": "aws_access_key_id='AKIAIO5FODNN7EXAMPLE',",
|
||||
"lineNumber": 2,
|
||||
"offender": "AKIAIO5FODNN7EXAMPLE",
|
||||
"commit": "ce7e8177bbf8a172c06b6a1e370a374d5c19f660",
|
||||
"repo": "test_repo_8",
|
||||
"repoURL": "",
|
||||
"leakURL": "",
|
||||
"rule": "AWS Access Key",
|
||||
"commitMessage": "dummy.txt w/ text",
|
||||
"author": "Zachary Rice",
|
||||
"email": "zricer@protonmail.com",
|
||||
"file": "dummy.txt",
|
||||
"date": "2020-07-25T14:39:11-04:00",
|
||||
"tags": "key, AWS"
|
||||
},
|
||||
{
|
||||
"line": "aws_access_key_id='AKIAIO5FODNN7EXAMPLE',",
|
||||
"lineNumber": 6,
|
||||
"offender": "AKIAIO5FODNN7EXAMPLE",
|
||||
"commit": "9267bc86ec1497471cbc6f3308f3527f7ef34b9d",
|
||||
"repo": "test_repo_8",
|
||||
"repoURL": "",
|
||||
"leakURL": "",
|
||||
"rule": "AWS Access Key",
|
||||
"commitMessage": "Update dummy.txt",
|
||||
"author": "Zachary Rice",
|
||||
"email": "zricer@protonmail.com",
|
||||
"file": "dummy.txt",
|
||||
"date": "2020-07-25T14:41:11-04:00",
|
||||
"tags": "key, AWS"
|
||||
}
|
||||
]
|
||||
@@ -0,0 +1,17 @@
|
||||
[
|
||||
{
|
||||
"line": "more_secrets = '99432bfewaf823ec3294e231'",
|
||||
"lineNumber": 7,
|
||||
"offender": "secrets = '99432bfewaf823ec3294e231",
|
||||
"commit": "a4c9fb737d5552fd96fce5cc7eedb23353ba9ed0",
|
||||
"repo": "test_repo_5",
|
||||
"rule": "Generic Credential",
|
||||
"commitMessage": "even more secrets\n",
|
||||
"author": "Zach Rice",
|
||||
"email": "zrice@gitlab.com",
|
||||
"file": "secrets.py",
|
||||
"date": "2020-02-01T10:30:22-05:00",
|
||||
"tags": "key, API, generic",
|
||||
"operation": "addition"
|
||||
}
|
||||
]
|
||||
@@ -0,0 +1,17 @@
|
||||
[
|
||||
{
|
||||
"line": "more_secrets = '99432bfewaf823ec3294e231'",
|
||||
"lineNumber": 7,
|
||||
"offender": "secrets = '99432bfewaf823ec3294e231",
|
||||
"commit": "a4c9fb737d5552fd96fce5cc7eedb23353ba9ed0",
|
||||
"repo": "test_repo_5",
|
||||
"rule": "Generic Credential",
|
||||
"commitMessage": "even more secrets\n",
|
||||
"author": "Zach Rice",
|
||||
"email": "zrice@gitlab.com",
|
||||
"file": "secrets.py",
|
||||
"date": "2020-02-01T10:30:22-05:00",
|
||||
"tags": "key, API, generic",
|
||||
"operation": "addition"
|
||||
}
|
||||
]
|
||||
Loaded 100 of 492 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user