Compare commits

...
8 Commits
Author SHA1 Message Date
Zachary Rice 36779df3bb stricter ionic regex for less fps (#757) 2021-12-17 10:13:44 -06:00
Zachary Rice 3d3d801729 fixing eof location bug (#756) 2021-12-17 09:49:12 -06:00
Zachary Rice 0f2ffee6f9 Adding Tines sponsorship to readme 2021-12-16 10:39:45 -06:00
Andrzej Amghar f4d37a2c0d fix regexp for aws_key and slack_webhook (#754) 2021-12-16 07:48:18 -06:00
Zachary Rice be5596df1d Update README.md 2021-12-12 13:38:43 -06:00
Zachary Rice e97f26bb5f better asciinema 2021-12-12 13:36:57 -06:00
Zachary Rice ae13c96df8 Update README.md 2021-12-12 13:19:58 -06:00
Zachary Rice d15dfdc387 Update README.md 2021-12-12 13:19:06 -06:00
4 changed files with 52 additions and 26 deletions

No files matched your search

+6 -4
View File
@@ -22,11 +22,9 @@
</p> </p>
</p> </p>
Gitleaks is a SAST tool for detecting hardcoded secrets like passwords, api keys, and tokens in git repos. Gitleaks is an **easy-to-use, all-in-one solution** for detecting secrets, past or present, in your code. Gitleaks is a SAST tool for **detecting** and **preventing** hardcoded secrets like passwords, api keys, and tokens in git repos. Gitleaks is an **easy-to-use, all-in-one solution** for detecting secrets, past or present, in your code.
#### 💫⭐✨ Temporary README message 💫⭐✨ [![asciicast](https://asciinema.org/a/455683.svg)](https://asciinema.org/a/455683)
It would be so great if you could fill out this quick gitleaks [user survey](https://docs.google.com/forms/d/1poUqZfEamDY1kCp8v8hU6N3fUj8C5_lVNBD_cDe-GT4).
<3
## Getting Started ## Getting Started
Gitleaks can be installed using Homebrew, Docker, or Go. Gitleaks is also available in binary form for many popular platforms and OS types on the [releases page](https://github.com/zricethezav/gitleaks/releases). In addition, Gitleaks can be implemented as a pre-commit hook directly in your repo. Gitleaks can be installed using Homebrew, Docker, or Go. Gitleaks is also available in binary form for many popular platforms and OS types on the [releases page](https://github.com/zricethezav/gitleaks/releases). In addition, Gitleaks can be implemented as a pre-commit hook directly in your repo.
@@ -291,6 +289,10 @@ the generic rule has the string `generic` somewhere in the rule's `id`. If a sec
will be given precedence. will be given precedence.
## Sponsorships
[![Tines-Sponsorship-Badge-Purple](https://user-images.githubusercontent.com/15034943/146411864-4878f936-b4f7-49a0-b625-f9f40c704bfa.png)](https://www.tines.com/?utm_source=oss&utm_medium=sponsorship&utm_campaign=gitleaks)
## Exit Codes ## Exit Codes
You can always set the exit code when leaks are encountered with the --exit-code flag. Default exit codes below: You can always set the exit code when leaks are encountered with the --exit-code flag. Default exit codes below:
``` ```
+21 -21
View File
@@ -2,33 +2,33 @@ title = "gitleaks config"
# Gitleaks rules are defined by regular expressions and entropy ranges. # Gitleaks rules are defined by regular expressions and entropy ranges.
# Some secrets have unique signatures which make detecting those secrets easy. # Some secrets have unique signatures which make detecting those secrets easy.
# Examples of those secrets would be Gitlab Personal Access Tokens, AWS keys, and Github Access Tokens. # Examples of those secrets would be Gitlab Personal Access Tokens, AWS keys, and Github Access Tokens.
# All these examples have defined prefixes like `glpat`, `AKIA`, `ghp_`, etc. # All these examples have defined prefixes like `glpat`, `AKIA`, `ghp_`, etc.
# #
# Other secrets might just be a hash which means we need to write more complex rules to verify # Other secrets might just be a hash which means we need to write more complex rules to verify
# that what we are matching is a secret. # that what we are matching is a secret.
# #
# Here is an example of a semi-generic secret # Here is an example of a semi-generic secret
# #
# discord_client_secret = "8dyfuiRyq=vVc3RRr_edRk-fK__JItpZ" # discord_client_secret = "8dyfuiRyq=vVc3RRr_edRk-fK__JItpZ"
# #
# We can write a regular expression to capture the variable name (identifier), # We can write a regular expression to capture the variable name (identifier),
# the assignment symbol (like '=' or ':='), and finally the actual secret. # the assignment symbol (like '=' or ':='), and finally the actual secret.
# The structure of a rule to match this example secret is below: # The structure of a rule to match this example secret is below:
# #
# Beginning string # Beginning string
# quotation # quotation
# │ End string quotation # │ End string quotation
# │ │ # │ │
# ▼ ▼ # ▼ ▼
# (?i)(discord[a-z0-9_ .\-,]{0,25})(=|>|:=|\|\|:|<=|=>|:).{0,5}['\"]([a-z0-9=_\-]{32})['\"] # (?i)(discord[a-z0-9_ .\-,]{0,25})(=|>|:=|\|\|:|<=|=>|:).{0,5}['\"]([a-z0-9=_\-]{32})['\"]
# #
# ▲ ▲ ▲ # ▲ ▲ ▲
# │ │ │ # │ │ │
# │ │ │ # │ │ │
# identifier assignment symbol # identifier assignment symbol
# Secret # Secret
# #
[[rules]] [[rules]]
id = "gitlab-pat" id = "gitlab-pat"
description = "GitLab Personal Access Token" description = "GitLab Personal Access Token"
@@ -37,7 +37,7 @@ regex = '''glpat-[0-9a-zA-Z\-]{20}'''
[[rules]] [[rules]]
id = "aws-access-token" id = "aws-access-token"
description = "AWS" description = "AWS"
regex = '''AKIA[0-9A-Z]{16}''' regex = '''(A3T[A-Z0-9]|AKIA|AGPA|AIDA|AROA|AIPA|ANPA|ANVA|ASIA)[A-Z0-9]{16}'''
# Cryptographic keys # Cryptographic keys
[[rules]] [[rules]]
@@ -140,7 +140,7 @@ secretGroup = 3
[[rules]] [[rules]]
id = "slack-web-hook" id = "slack-web-hook"
description = "Slack Webhook" 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}''' regex = '''https://hooks.slack.com/services/T[a-zA-Z0-9_]{8}/B[a-zA-Z0-9_]{8,12}/[a-zA-Z0-9_]{24}'''
[[rules]] [[rules]]
id = "twilio-api-key" id = "twilio-api-key"
@@ -381,7 +381,7 @@ secretGroup = 3
[[rules]] [[rules]]
id = "ionic-api-token" id = "ionic-api-token"
description = "Ionic API token" description = "Ionic API token"
regex = '''ion_(?i)[a-z0-9]{42}''' regex = '''(?i)(ionic[a-z0-9_ .\-,]{0,25})(=|>|:=|\|\|:|<=|=>|:).{0,5}['\"](ion_[a-z0-9]{42})['\"]'''
[[rules]] [[rules]]
id = "linear-api-token" id = "linear-api-token"
+12
View File
@@ -34,6 +34,10 @@ func TestDetectFindings(t *testing.T) {
File: "tmp.go", File: "tmp.go",
RuleID: "aws-access-key", RuleID: "aws-access-key",
Tags: []string{"key", "AWS"}, Tags: []string{"key", "AWS"},
StartLine: 1,
EndLine: 1,
StartColumn: 15,
EndColumn: 34,
}, },
}, },
}, },
@@ -69,6 +73,10 @@ func TestDetectFindings(t *testing.T) {
RuleID: "discord-api-key", RuleID: "discord-api-key",
Tags: []string{}, Tags: []string{},
Entropy: 3.7906237, Entropy: 3.7906237,
StartLine: 1,
EndLine: 1,
StartColumn: 7,
EndColumn: 93,
}, },
}, },
}, },
@@ -91,6 +99,10 @@ func TestDetectFindings(t *testing.T) {
RuleID: "generic-api-key", RuleID: "generic-api-key",
Tags: []string{}, Tags: []string{},
Entropy: 3.7906237, Entropy: 3.7906237,
StartLine: 1,
EndLine: 1,
StartColumn: 22,
EndColumn: 93,
}, },
}, },
}, },
+13 -1
View File
@@ -14,11 +14,15 @@ func getLocation(linePairs [][]int, start int, end int) Location {
var ( var (
prevNewLine int prevNewLine int
location Location location Location
lineSet bool
_lineNum int
) )
for lineNum, pair := range linePairs { for lineNum, pair := range linePairs {
_lineNum = lineNum
newLineByteIndex := pair[0] newLineByteIndex := pair[0]
if prevNewLine <= start && start < newLineByteIndex { if prevNewLine <= start && start < newLineByteIndex {
lineSet = true
location.startLine = lineNum location.startLine = lineNum
location.endLine = lineNum location.endLine = lineNum
location.startColumn = (start - prevNewLine) + 1 // +1 because counting starts at 1 location.startColumn = (start - prevNewLine) + 1 // +1 because counting starts at 1
@@ -30,9 +34,17 @@ func getLocation(linePairs [][]int, start int, end int) Location {
location.endColumn = (end - prevNewLine) location.endColumn = (end - prevNewLine)
location.endLineIndex = newLineByteIndex location.endLineIndex = newLineByteIndex
} }
prevNewLine = pair[0] prevNewLine = pair[0]
} }
if !lineSet {
// if lines never get set then that means the secret is most likely
// on the last line of the diff output and the diff output does not have
// a newline
location.startColumn = (start - prevNewLine) + 1 // +1 because counting starts at 1
location.endColumn = (end - prevNewLine)
location.startLine = _lineNum + 1
location.endLine = _lineNum + 1
}
return location return location
} }