mirror of
https://github.com/gitleaks/gitleaks.git
synced 2026-11-29 12:44:22 +01:00
Compare commits
7
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
778808a286 | ||
|
|
7a957cd36b | ||
|
|
3ca542796b | ||
|
|
53793bef90 | ||
|
|
6492389e99 | ||
|
|
7f229faf12 | ||
|
|
d0733f96f3 |
No files matched your search
@@ -2,7 +2,7 @@ name: Create and publish a Docker image
|
|||||||
|
|
||||||
on:
|
on:
|
||||||
release:
|
release:
|
||||||
types: [published]
|
types: [published, prereleased]
|
||||||
|
|
||||||
env:
|
env:
|
||||||
REGISTRY: ghcr.io
|
REGISTRY: ghcr.io
|
||||||
@@ -41,14 +41,18 @@ jobs:
|
|||||||
|
|
||||||
- name: Extract metadata (tags, labels) for Docker
|
- name: Extract metadata (tags, labels) for Docker
|
||||||
id: meta
|
id: meta
|
||||||
uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38
|
uses: docker/metadata-action@v4
|
||||||
with:
|
with:
|
||||||
images: |
|
images: |
|
||||||
zricethezav/gitleaks
|
zricethezav/gitleaks
|
||||||
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
|
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
|
||||||
|
tags: |
|
||||||
|
type=semver,pattern=v{{version}}
|
||||||
|
type=semver,pattern=v{{major}}
|
||||||
|
type=semver,pattern=v{{major}}.{{minor}}
|
||||||
|
|
||||||
- name: Build and push Docker image
|
- name: Build and push Docker image
|
||||||
uses: docker/build-push-action@e551b19e49efd4e98792db7592c17c09b89db8d8
|
uses: docker/build-push-action@v3
|
||||||
with:
|
with:
|
||||||
platforms: linux/amd64,linux/arm64
|
platforms: linux/amd64,linux/arm64
|
||||||
context: .
|
context: .
|
||||||
|
|||||||
@@ -73,6 +73,7 @@ func main() {
|
|||||||
// configRules = append(configRules, rules.GCPServiceAccount())
|
// configRules = append(configRules, rules.GCPServiceAccount())
|
||||||
configRules = append(configRules, rules.GCPAPIKey())
|
configRules = append(configRules, rules.GCPAPIKey())
|
||||||
configRules = append(configRules, rules.GitHubPat())
|
configRules = append(configRules, rules.GitHubPat())
|
||||||
|
configRules = append(configRules, rules.GitHubFineGrainedPat())
|
||||||
configRules = append(configRules, rules.GitHubOauth())
|
configRules = append(configRules, rules.GitHubOauth())
|
||||||
configRules = append(configRules, rules.GitHubApp())
|
configRules = append(configRules, rules.GitHubApp())
|
||||||
configRules = append(configRules, rules.GitHubRefresh())
|
configRules = append(configRules, rules.GitHubRefresh())
|
||||||
|
|||||||
@@ -23,6 +23,22 @@ func GitHubPat() *config.Rule {
|
|||||||
return validate(r, tps, nil)
|
return validate(r, tps, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GitHubFineGrainedPat() *config.Rule {
|
||||||
|
// define rule
|
||||||
|
r := config.Rule{
|
||||||
|
Description: "GitHub Fine-Grained Personal Access Token",
|
||||||
|
RuleID: "github-fine-grained-pat",
|
||||||
|
Regex: regexp.MustCompile(`github_pat_[0-9a-zA-Z_]{82}`),
|
||||||
|
Keywords: []string{"github_pat_"},
|
||||||
|
}
|
||||||
|
|
||||||
|
// validate
|
||||||
|
tps := []string{
|
||||||
|
generateSampleSecret("github", "github_pat_"+secrets.NewSecret(alphaNumeric("82"))),
|
||||||
|
}
|
||||||
|
return validate(r, tps, nil)
|
||||||
|
}
|
||||||
|
|
||||||
func GitHubOauth() *config.Rule {
|
func GitHubOauth() *config.Rule {
|
||||||
// define rule
|
// define rule
|
||||||
r := config.Rule{
|
r := config.Rule{
|
||||||
|
|||||||
@@ -1976,6 +1976,14 @@ keywords = [
|
|||||||
"ghu_","ghs_",
|
"ghu_","ghs_",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[rules]]
|
||||||
|
description = "GitHub Fine-Grained Personal Access Token"
|
||||||
|
id = "github-fine-grained-pat"
|
||||||
|
regex = '''github_pat_[0-9a-zA-Z_]{82}'''
|
||||||
|
keywords = [
|
||||||
|
"github_pat_",
|
||||||
|
]
|
||||||
|
|
||||||
[[rules]]
|
[[rules]]
|
||||||
description = "GitHub OAuth Access Token"
|
description = "GitHub OAuth Access Token"
|
||||||
id = "github-oauth"
|
id = "github-oauth"
|
||||||
|
|||||||
+21
-16
@@ -18,8 +18,13 @@ const repoBasePath = "../testdata/repos/"
|
|||||||
|
|
||||||
func TestDetect(t *testing.T) {
|
func TestDetect(t *testing.T) {
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
cfgName string
|
cfgName string
|
||||||
fragment Fragment
|
fragment Fragment
|
||||||
|
// NOTE: for expected findings, all line numbers will be 0
|
||||||
|
// because line deltas are added _after_ the finding is created.
|
||||||
|
// I.e, if the finding is from a --no-git file, the line number will be
|
||||||
|
// increase by 1 in DetectFromFiles(). If the finding is from git,
|
||||||
|
// the line number will be increased by the patch delta.
|
||||||
expectedFindings []report.Finding
|
expectedFindings []report.Finding
|
||||||
wantError error
|
wantError error
|
||||||
}{
|
}{
|
||||||
@@ -85,8 +90,8 @@ func TestDetect(t *testing.T) {
|
|||||||
File: "tmp.go",
|
File: "tmp.go",
|
||||||
RuleID: "pypi-upload-token",
|
RuleID: "pypi-upload-token",
|
||||||
Tags: []string{"key", "pypi"},
|
Tags: []string{"key", "pypi"},
|
||||||
StartLine: 1,
|
StartLine: 0,
|
||||||
EndLine: 1,
|
EndLine: 0,
|
||||||
StartColumn: 1,
|
StartColumn: 1,
|
||||||
EndColumn: 86,
|
EndColumn: 86,
|
||||||
Entropy: 1.9606875,
|
Entropy: 1.9606875,
|
||||||
@@ -108,8 +113,8 @@ func TestDetect(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,
|
StartLine: 0,
|
||||||
EndLine: 1,
|
EndLine: 0,
|
||||||
StartColumn: 15,
|
StartColumn: 15,
|
||||||
EndColumn: 34,
|
EndColumn: 34,
|
||||||
Entropy: 3.0841837,
|
Entropy: 3.0841837,
|
||||||
@@ -132,8 +137,8 @@ func TestDetect(t *testing.T) {
|
|||||||
RuleID: "sidekiq-secret",
|
RuleID: "sidekiq-secret",
|
||||||
Tags: []string{},
|
Tags: []string{},
|
||||||
Entropy: 2.6098502,
|
Entropy: 2.6098502,
|
||||||
StartLine: 1,
|
StartLine: 0,
|
||||||
EndLine: 1,
|
EndLine: 0,
|
||||||
StartColumn: 8,
|
StartColumn: 8,
|
||||||
EndColumn: 60,
|
EndColumn: 60,
|
||||||
},
|
},
|
||||||
@@ -155,8 +160,8 @@ func TestDetect(t *testing.T) {
|
|||||||
RuleID: "sidekiq-secret",
|
RuleID: "sidekiq-secret",
|
||||||
Tags: []string{},
|
Tags: []string{},
|
||||||
Entropy: 2.6098502,
|
Entropy: 2.6098502,
|
||||||
StartLine: 1,
|
StartLine: 0,
|
||||||
EndLine: 1,
|
EndLine: 0,
|
||||||
StartColumn: 21,
|
StartColumn: 21,
|
||||||
EndColumn: 74,
|
EndColumn: 74,
|
||||||
},
|
},
|
||||||
@@ -178,8 +183,8 @@ func TestDetect(t *testing.T) {
|
|||||||
RuleID: "sidekiq-sensitive-url",
|
RuleID: "sidekiq-sensitive-url",
|
||||||
Tags: []string{},
|
Tags: []string{},
|
||||||
Entropy: 2.984234,
|
Entropy: 2.984234,
|
||||||
StartLine: 1,
|
StartLine: 0,
|
||||||
EndLine: 1,
|
EndLine: 0,
|
||||||
StartColumn: 8,
|
StartColumn: 8,
|
||||||
EndColumn: 58,
|
EndColumn: 58,
|
||||||
},
|
},
|
||||||
@@ -226,8 +231,8 @@ func TestDetect(t *testing.T) {
|
|||||||
RuleID: "discord-api-key",
|
RuleID: "discord-api-key",
|
||||||
Tags: []string{},
|
Tags: []string{},
|
||||||
Entropy: 3.7906237,
|
Entropy: 3.7906237,
|
||||||
StartLine: 1,
|
StartLine: 0,
|
||||||
EndLine: 1,
|
EndLine: 0,
|
||||||
StartColumn: 7,
|
StartColumn: 7,
|
||||||
EndColumn: 93,
|
EndColumn: 93,
|
||||||
},
|
},
|
||||||
@@ -257,8 +262,8 @@ func TestDetect(t *testing.T) {
|
|||||||
RuleID: "generic-api-key",
|
RuleID: "generic-api-key",
|
||||||
Tags: []string{},
|
Tags: []string{},
|
||||||
Entropy: 3.7906237,
|
Entropy: 3.7906237,
|
||||||
StartLine: 1,
|
StartLine: 0,
|
||||||
EndLine: 1,
|
EndLine: 0,
|
||||||
StartColumn: 22,
|
StartColumn: 22,
|
||||||
EndColumn: 93,
|
EndColumn: 93,
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -24,6 +24,16 @@ func location(fragment Fragment, matchIndex []int) Location {
|
|||||||
// default startLineIndex to 0
|
// default startLineIndex to 0
|
||||||
location.startLineIndex = 0
|
location.startLineIndex = 0
|
||||||
|
|
||||||
|
// Fixes: https://github.com/zricethezav/gitleaks/issues/1037
|
||||||
|
// When a fragment does NOT have any newlines, a default "newline"
|
||||||
|
// will be counted to make the subsequent location calculation logic work
|
||||||
|
// for fragments will no newlines.
|
||||||
|
if len(fragment.newlineIndices) == 0 {
|
||||||
|
fragment.newlineIndices = [][]int{
|
||||||
|
{len(fragment.Raw), len(fragment.Raw) + 1},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for lineNum, pair := range fragment.newlineIndices {
|
for lineNum, pair := range fragment.newlineIndices {
|
||||||
_lineNum = lineNum
|
_lineNum = lineNum
|
||||||
newLineByteIndex := pair[0]
|
newLineByteIndex := pair[0]
|
||||||
|
|||||||
Reference in new issue
Block a user