From 722ce8213aae1fcc9163c751872eb5dbec9f9543 Mon Sep 17 00:00:00 2001 From: Tilo Brueckner Date: Wed, 4 Jun 2025 14:15:06 +0000 Subject: [PATCH 1/5] Add Platform Gitea (#1884) --- cmd/scm/scm.go | 4 ++++ detect/utils.go | 16 ++++++++++++++++ detect/utils_test.go | 41 +++++++++++++++++++++++++++++++++++++++++ sources/git.go | 2 ++ 4 files changed, 63 insertions(+) diff --git a/cmd/scm/scm.go b/cmd/scm/scm.go index a89136af..8e021e64 100644 --- a/cmd/scm/scm.go +++ b/cmd/scm/scm.go @@ -13,6 +13,7 @@ const ( GitHubPlatform GitLabPlatform AzureDevOpsPlatform + GiteaPlatform // TODO: Add others. ) @@ -23,6 +24,7 @@ func (p Platform) String() string { "github", "gitlab", "azuredevops", + "gitea", }[p] } @@ -38,6 +40,8 @@ func PlatformFromString(s string) (Platform, error) { return GitLabPlatform, nil case "azuredevops": return AzureDevOpsPlatform, nil + case "gitea": + return GiteaPlatform, nil default: return UnknownPlatform, fmt.Errorf("invalid scm platform value: %s", s) } diff --git a/detect/utils.go b/detect/utils.go index 14be6419..cecbcc92 100644 --- a/detect/utils.go +++ b/detect/utils.go @@ -75,6 +75,22 @@ func createScmLink(remote *sources.RemoteInfo, finding report.Finding) string { // This is a bit dirty, but Azure DevOps does not highlight the line when the lineStartColumn and lineEndColumn are not provided link += "&lineStartColumn=1&lineEndColumn=10000000&type=2&lineStyle=plain&_a=files" return link + case scm.GiteaPlatform: + link := fmt.Sprintf("%s/src/commit/%s/%s", remote.Url, finding.Commit, filePath) + if hasInnerPath { + return link + } + ext := strings.ToLower(filepath.Ext(filePath)) + if ext == ".ipynb" || ext == ".md" { + link += "?display=source" + } + if finding.StartLine != 0 { + link += fmt.Sprintf("#L%d", finding.StartLine) + } + if finding.EndLine != finding.StartLine { + link += fmt.Sprintf("-L%d", finding.EndLine) + } + return link default: // This should never happen. return "" diff --git a/detect/utils_test.go b/detect/utils_test.go index cfebbfdb..0b655b55 100644 --- a/detect/utils_test.go +++ b/detect/utils_test.go @@ -136,6 +136,47 @@ func Test_createScmLink(t *testing.T) { }, want: "https://dev.azure.com/exampleorganisation/exampleproject/_git/exampleRepository/commit/20553ad96a4a080c94a54d677db97eed8ce2560d?path=/examplefile.json&line=25&lineEnd=30&lineStartColumn=1&lineEndColumn=10000000&type=2&lineStyle=plain&_a=files", }, + + // Gitea + "gitea - single line": { + remote: &sources.RemoteInfo{ + Platform: scm.GiteaPlatform, + Url: "https://gitea.com/exampleorganisation/exampleproject", + }, + finding: report.Finding{ + Commit: "20553ad96a4a080c94a54d677db97eed8ce2560d", + File: "examplefile.json", + StartLine: 25, + EndLine: 25, + }, + want: "https://gitea.com/exampleorganisation/exampleproject/src/commit/20553ad96a4a080c94a54d677db97eed8ce2560d/examplefile.json#L25", + }, + "gitea- multi line": { + remote: &sources.RemoteInfo{ + Platform: scm.GiteaPlatform, + Url: "https://gitea.com/exampleorganisation/exampleproject", + }, + finding: report.Finding{ + Commit: "20553ad96a4a080c94a54d677db97eed8ce2560d", + File: "examplefile.json", + StartLine: 25, + EndLine: 30, + }, + want: "https://gitea.com/exampleorganisation/exampleproject/src/commit/20553ad96a4a080c94a54d677db97eed8ce2560d/examplefile.json#L25-L30", + }, + "gitea - markdown": { + remote: &sources.RemoteInfo{ + Platform: scm.GiteaPlatform, + Url: "https://gitea.com/exampleorganisation/exampleproject", + }, + finding: report.Finding{ + Commit: "20553ad96a4a080c94a54d677db97eed8ce2560d", + File: "Readme.md", + StartLine: 34, + EndLine: 34, + }, + want: "https://gitea.com/exampleorganisation/exampleproject/src/commit/20553ad96a4a080c94a54d677db97eed8ce2560d/Readme.md?display=source#L34", + }, } for name, tt := range tests { t.Run(name, func(t *testing.T) { diff --git a/sources/git.go b/sources/git.go index 16a51879..7490ef38 100644 --- a/sources/git.go +++ b/sources/git.go @@ -482,6 +482,8 @@ func platformFromHost(u *url.URL) scm.Platform { return scm.GitLabPlatform case "dev.azure.com", "visualstudio.com": return scm.AzureDevOpsPlatform + case "gitea.com", "code.forgejo.org", "codeberg.org": + return scm.GiteaPlatform default: return scm.UnknownPlatform } From 20f9a1d4eb32c81d4ee8798090a2703f70f98c0b Mon Sep 17 00:00:00 2001 From: Tilo Brueckner Date: Thu, 5 Jun 2025 00:46:01 +0000 Subject: [PATCH 2/5] Add Platform Bitbucket (#1886) --- cmd/scm/scm.go | 4 ++++ detect/utils.go | 12 ++++++++++++ detect/utils_test.go | 27 +++++++++++++++++++++++++++ sources/git.go | 2 ++ 4 files changed, 45 insertions(+) diff --git a/cmd/scm/scm.go b/cmd/scm/scm.go index 8e021e64..23022a9d 100644 --- a/cmd/scm/scm.go +++ b/cmd/scm/scm.go @@ -14,6 +14,7 @@ const ( GitLabPlatform AzureDevOpsPlatform GiteaPlatform + BitbucketPlatform // TODO: Add others. ) @@ -25,6 +26,7 @@ func (p Platform) String() string { "gitlab", "azuredevops", "gitea", + "bitbucket", }[p] } @@ -42,6 +44,8 @@ func PlatformFromString(s string) (Platform, error) { return AzureDevOpsPlatform, nil case "gitea": return GiteaPlatform, nil + case "bitbucket": + return BitbucketPlatform, nil default: return UnknownPlatform, fmt.Errorf("invalid scm platform value: %s", s) } diff --git a/detect/utils.go b/detect/utils.go index cecbcc92..0bf9ed75 100644 --- a/detect/utils.go +++ b/detect/utils.go @@ -91,6 +91,18 @@ func createScmLink(remote *sources.RemoteInfo, finding report.Finding) string { link += fmt.Sprintf("-L%d", finding.EndLine) } return link + case scm.BitbucketPlatform: + link := fmt.Sprintf("%s/src/%s/%s", remote.Url, finding.Commit, filePath) + if hasInnerPath { + return link + } + if finding.StartLine != 0 { + link += fmt.Sprintf("#lines-%d", finding.StartLine) + } + if finding.EndLine != finding.StartLine { + link += fmt.Sprintf(":%d", finding.EndLine) + } + return link default: // This should never happen. return "" diff --git a/detect/utils_test.go b/detect/utils_test.go index 0b655b55..03a6e32e 100644 --- a/detect/utils_test.go +++ b/detect/utils_test.go @@ -177,6 +177,33 @@ func Test_createScmLink(t *testing.T) { }, want: "https://gitea.com/exampleorganisation/exampleproject/src/commit/20553ad96a4a080c94a54d677db97eed8ce2560d/Readme.md?display=source#L34", }, + // bitbucket + "bitbucket - single line": { + remote: &sources.RemoteInfo{ + Platform: scm.BitbucketPlatform, + Url: "https://bitbucket.org/exampleorganisation/exampleproject", + }, + finding: report.Finding{ + Commit: "20553ad96a4a080c94a54d677db97eed8ce2560d", + File: "examplefile.json", + StartLine: 25, + EndLine: 25, + }, + want: "https://bitbucket.org/exampleorganisation/exampleproject/src/20553ad96a4a080c94a54d677db97eed8ce2560d/examplefile.json#lines-25", + }, + "bitbucket- multi line": { + remote: &sources.RemoteInfo{ + Platform: scm.BitbucketPlatform, + Url: "https://bitbucket.org/exampleorganisation/exampleproject", + }, + finding: report.Finding{ + Commit: "20553ad96a4a080c94a54d677db97eed8ce2560d", + File: "examplefile.json", + StartLine: 25, + EndLine: 30, + }, + want: "https://bitbucket.org/exampleorganisation/exampleproject/src/20553ad96a4a080c94a54d677db97eed8ce2560d/examplefile.json#lines-25:30", + }, } for name, tt := range tests { t.Run(name, func(t *testing.T) { diff --git a/sources/git.go b/sources/git.go index 7490ef38..73f713f2 100644 --- a/sources/git.go +++ b/sources/git.go @@ -484,6 +484,8 @@ func platformFromHost(u *url.URL) scm.Platform { return scm.AzureDevOpsPlatform case "gitea.com", "code.forgejo.org", "codeberg.org": return scm.GiteaPlatform + case "bitbucket.org": + return scm.BitbucketPlatform default: return scm.UnknownPlatform } From 6f251eef65b76d0078d0583672385d4657ad7a87 Mon Sep 17 00:00:00 2001 From: Kashif Khan <70996046+kashifkhan0771@users.noreply.github.com> Date: Thu, 5 Jun 2025 05:47:19 +0500 Subject: [PATCH 3/5] Added Heroku API Key New Version (#1883) * Added Heroku API Key New Version * updated rule --- cmd/generate/config/main.go | 1 + cmd/generate/config/rules/heroku.go | 19 +++++++++++++++++++ config/gitleaks.toml | 7 +++++++ 3 files changed, 27 insertions(+) diff --git a/cmd/generate/config/main.go b/cmd/generate/config/main.go index 985a5945..030973ce 100644 --- a/cmd/generate/config/main.go +++ b/cmd/generate/config/main.go @@ -125,6 +125,7 @@ func main() { rules.HashiCorpTerraform(), rules.HashicorpField(), rules.Heroku(), + rules.HerokuV2(), rules.HubSpot(), rules.HuggingFaceAccessToken(), rules.HuggingFaceOrganizationApiToken(), diff --git a/cmd/generate/config/rules/heroku.go b/cmd/generate/config/rules/heroku.go index f4c80bd3..436f067e 100644 --- a/cmd/generate/config/rules/heroku.go +++ b/cmd/generate/config/rules/heroku.go @@ -24,3 +24,22 @@ func Heroku() *config.Rule { ) return utils.Validate(r, tps, nil) } + +func HerokuV2() *config.Rule { + // define rule + r := config.Rule{ + Description: "Detected a Heroku API Key, potentially compromising cloud application deployments and operational security.", + RuleID: "heroku-api-key-v2", + Regex: utils.GenerateUniqueTokenRegex(`(HRKU-AA[0-9a-zA-Z_-]{58})`, false), + Entropy: 4, + Keywords: []string{"HRKU-AA"}, + } + + // validate + tps := utils.GenerateSampleSecrets("heroku", secrets.NewSecret(`\b(HRKU-AA[0-9a-zA-Z_-]{58})\b`)) + tps = append(tps, + `const KEY = "HRKU-AAlQ1aVoHDujJ9QsDHdHlHO0hbzhoERRSO45ZQusSYHg_____w4_hLrAym_u""`, + `API_Key = "HRKU-AAy9Ppr_HD2pPuTyIiTYInO0hbzhoERRSO93ZQusSYHgaD7_WQ07FnF7L9FX"`, + ) + return utils.Validate(r, tps, nil) +} diff --git a/config/gitleaks.toml b/config/gitleaks.toml index 80f57271..2d677a51 100644 --- a/config/gitleaks.toml +++ b/config/gitleaks.toml @@ -2296,6 +2296,13 @@ description = "Detected a Heroku API Key, potentially compromising cloud applica regex = '''(?i)[\w.-]{0,50}?(?:heroku)(?:[ \t\w.-]{0,20})[\s'"]{0,3}(?:=|>|:{1,3}=|\|\||:|=>|\?=|,)[\x60'"\s=]{0,5}([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})(?:[\x60'"\s;]|\\[nr]|$)''' keywords = ["heroku"] +[[rules]] +id = "heroku-api-key-v2" +description = "Detected a Heroku API Key, potentially compromising cloud application deployments and operational security." +regex = '''\b((HRKU-AA[0-9a-zA-Z_-]{58}))(?:[\x60'"\s;]|\\[nr]|$)''' +entropy = 4 +keywords = ["hrku-aa"] + [[rules]] id = "hubspot-api-key" description = "Found a HubSpot API Token, posing a risk to CRM data integrity and unauthorized marketing operations." From 2463f11e7156aa042e0620d7171064c405764876 Mon Sep 17 00:00:00 2001 From: bplaxco Date: Thu, 5 Jun 2025 09:26:06 -0400 Subject: [PATCH 4/5] Fix log suppresion issue (#1887) The check for log suppresion enables archive scanning by default with no max depth. --- sources/file.go | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/sources/file.go b/sources/file.go index daffbfd6..4844c2a4 100644 --- a/sources/file.go +++ b/sources/file.go @@ -55,12 +55,15 @@ func (s *File) Fragments(ctx context.Context, yield FragmentsFunc) error { // and fall back on treating it like a normal file and let fileFragments // decide what to do with it. if err == nil && format != nil { - if (s.archiveDepth+1 > s.MaxArchiveDepth) && s.MaxArchiveDepth != 0 { - logging.Warn().Str( - "path", s.FullPath(), - ).Int( - "max_archive_depth", s.MaxArchiveDepth, - ).Msg("skipping archive: exceeds max archive depth") + if s.archiveDepth+1 > s.MaxArchiveDepth { + // Only warn when the feature is enabled + if s.MaxArchiveDepth != 0 { + logging.Warn().Str( + "path", s.FullPath(), + ).Int( + "max_archive_depth", s.MaxArchiveDepth, + ).Msg("skipping archive: exceeds max archive depth") + } return nil } if extractor, ok := format.(archives.Extractor); ok { From ef8223700a18832a5b3d3f9455878f715b1bc66b Mon Sep 17 00:00:00 2001 From: Richard Gomez <32133502+rgmz@users.noreply.github.com> Date: Sat, 7 Jun 2025 21:33:34 -0400 Subject: [PATCH 5/5] fix(atlassian): reduce false-positives for v1 pattern (#1892) --- cmd/generate/config/rules/atlassian.go | 17 ++++++++++------- config/gitleaks.toml | 2 +- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/cmd/generate/config/rules/atlassian.go b/cmd/generate/config/rules/atlassian.go index 5fe28eaa..ba8b4cbf 100644 --- a/cmd/generate/config/rules/atlassian.go +++ b/cmd/generate/config/rules/atlassian.go @@ -13,9 +13,9 @@ func Atlassian() *config.Rule { RuleID: "atlassian-api-token", Regex: utils.MergeRegexps( utils.GenerateSemiGenericRegex( - []string{"atlassian", "confluence", "jira"}, - `[a-zA-Z0-9]{24}`, - false, + []string{"(?-i:ATLASSIAN|[Aa]tlassian)", "(?-i:CONFLUENCE|[Cc]onfluence)", "(?-i:JIRA|[Jj]ira)"}, + `[a-z0-9]{20}[a-f0-9]{4}`, // The last 4 characters are an MD5 hash. + true, ), utils.GenerateUniqueTokenRegex(`ATATT3[A-Za-z0-9_\-=]{186}`, false), ), @@ -24,10 +24,13 @@ func Atlassian() *config.Rule { } // validate - tps := utils.GenerateSampleSecrets("atlassian", secrets.NewSecret(utils.AlphaNumeric("24"))) - tps = append(tps, utils.GenerateSampleSecrets("confluence", secrets.NewSecret(utils.AlphaNumeric("24")))...) - tps = append(tps, utils.GenerateSampleSecrets("jira", secrets.NewSecret(utils.AlphaNumeric("24")))...) + tps := utils.GenerateSampleSecrets("atlassian", secrets.NewSecret(utils.AlphaNumeric("20")+"[a-f0-9]{4}")) + tps = append(tps, utils.GenerateSampleSecrets("confluence", secrets.NewSecret(utils.AlphaNumeric("20")+"[a-f0-9]{4}"))...) + tps = append(tps, utils.GenerateSampleSecrets("jira", secrets.NewSecret(utils.AlphaNumeric("20")+"[a-f0-9]{4}"))...) + tps = append(tps, `JIRA_API_TOKEN=HXe8DGg1iJd2AopzyxkFB7F2`) tps = append(tps, utils.GenerateSampleSecrets("jira", "ATATT3xFfGF0K3irG5tKKi-6u-wwaXQFeGwZ-IHR-hQ3CulkKtMSuteRQFfLZ6jihHThzZCg_UjnDt-4Wl_gIRf4zrZJs5JqaeuBhsfJ4W5GD6yGg3W7903gbvaxZPBjxIQQ7BgFDSkPS8oPispw4KLz56mdK-G6CIvLO6hHRrZHY0Q3tvJ6JxE=C63992E6")...) - return utils.Validate(r, tps, nil) + fps := []string{"getPagesInConfluenceSpace,searchConfluenceUsingCql"} + + return utils.Validate(r, tps, fps) } diff --git a/config/gitleaks.toml b/config/gitleaks.toml index 2d677a51..ac4a820b 100644 --- a/config/gitleaks.toml +++ b/config/gitleaks.toml @@ -144,7 +144,7 @@ keywords = ["asana"] [[rules]] id = "atlassian-api-token" description = "Detected an Atlassian API token, posing a threat to project management and collaboration tool security and data confidentiality." -regex = '''[\w.-]{0,50}?(?i:[\w.-]{0,50}?(?:atlassian|confluence|jira)(?:[ \t\w.-]{0,20})[\s'"]{0,3})(?:=|>|:{1,3}=|\|\||:|=>|\?=|,)[\x60'"\s=]{0,5}([a-zA-Z0-9]{24})(?:[\x60'"\s;]|\\[nr]|$)|\b(ATATT3[A-Za-z0-9_\-=]{186})(?:[\x60'"\s;]|\\[nr]|$)''' +regex = '''(?i)[\w.-]{0,50}?(?:(?-i:ATLASSIAN|[Aa]tlassian)|(?-i:CONFLUENCE|[Cc]onfluence)|(?-i:JIRA|[Jj]ira))(?:[ \t\w.-]{0,20})[\s'"]{0,3}(?:=|>|:{1,3}=|\|\||:|=>|\?=|,)[\x60'"\s=]{0,5}([a-z0-9]{20}[a-f0-9]{4})(?:[\x60'"\s;]|\\[nr]|$)|\b(ATATT3[A-Za-z0-9_\-=]{186})(?:[\x60'"\s;]|\\[nr]|$)''' entropy = 3.5 keywords = [ "atlassian",