Skip to content

Commit a631af8

Browse files
authored
Fix URL regexp and remove redundant Google regex patterns (#1485)
1 parent 8968502 commit a631af8

File tree

2 files changed

+9
-33
lines changed

2 files changed

+9
-33
lines changed

rules/hardcoded_credentials.go

Lines changed: 7 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -84,49 +84,25 @@ var secretsPatterns = [...]secretPattern{
8484
regexp: regexp.MustCompile(`ghs_[a-zA-Z0-9]{36}`),
8585
},
8686
{
87-
name: "Google API Key",
88-
regexp: regexp.MustCompile(`AIza[0-9A-Za-z\-_]{35}`),
89-
},
90-
{
91-
name: "Google Cloud Platform API Key",
92-
regexp: regexp.MustCompile(`AIza[0-9A-Za-z\-_]{35}`),
93-
},
94-
{
95-
name: "Google Cloud Platform OAuth",
96-
regexp: regexp.MustCompile(`[0-9]+-[0-9A-Za-z_]{32}\.apps\.googleusercontent\.com`),
97-
},
98-
{
99-
name: "Google Drive API Key",
87+
name: "Google API Key", // Also Google Cloud Platform, Gmail, Drive, YouTube, etc.
10088
regexp: regexp.MustCompile(`AIza[0-9A-Za-z\-_]{35}`),
10189
},
90+
10291
{
103-
name: "Google Drive OAuth",
92+
name: "Google Cloud Platform OAuth", // Also Gmail, Drive, YouTube, etc.
10493
regexp: regexp.MustCompile(`[0-9]+-[0-9A-Za-z_]{32}\.apps\.googleusercontent\.com`),
10594
},
95+
10696
{
10797
name: "Google (GCP) Service-account",
10898
regexp: regexp.MustCompile(`"type": "service_account"`),
10999
},
110-
{
111-
name: "Google Gmail API Key",
112-
regexp: regexp.MustCompile(`AIza[0-9A-Za-z\-_]{35}`),
113-
},
114-
{
115-
name: "Google Gmail OAuth",
116-
regexp: regexp.MustCompile(`[0-9]+-[0-9A-Za-z_]{32}\.apps\.googleusercontent\.com`),
117-
},
100+
118101
{
119102
name: "Google OAuth Access Token",
120103
regexp: regexp.MustCompile(`ya29\.[0-9A-Za-z\-_]+`),
121104
},
122-
{
123-
name: "Google YouTube API Key",
124-
regexp: regexp.MustCompile(`AIza[0-9A-Za-z\-_]{35}`),
125-
},
126-
{
127-
name: "Google YouTube OAuth",
128-
regexp: regexp.MustCompile(`[0-9]+-[0-9A-Za-z_]{32}\.apps\.googleusercontent\.com`),
129-
},
105+
130106
{
131107
name: "Generic API Key",
132108
regexp: regexp.MustCompile(`[aA][pP][iI]_?[kK][eE][yY].*[''|"][0-9a-zA-Z]{32,45}[''|"]`),
@@ -149,7 +125,7 @@ var secretsPatterns = [...]secretPattern{
149125
},
150126
{
151127
name: "Password in URL",
152-
regexp: regexp.MustCompile(`[a-zA-Z]{3,10}://[^/\\s:@]{3,20}:[^/\\s:@]{3,20}@.{1,100}["'\\s]`),
128+
regexp: regexp.MustCompile(`[a-zA-Z]{3,10}://[a-zA-Z0-9\.\-\_\+]{1,64}:[a-zA-Z0-9\.\-\_\!\$\%\&\*\+\=\^\(\)]{1,128}@[a-zA-Z0-9\.\-\_]+(:[0-9]+)?(/[^"'\s]*)?(["'\s]|$)`),
153129
},
154130
{
155131
name: "Slack Webhook",

testutils/g101_samples.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -512,8 +512,8 @@ package main
512512
import "fmt"
513513
514514
func main() {
515-
urlSecret := "https://username:[email protected]/"
516-
fmt.Println(urlSecret)
515+
url := "https://username:[email protected]/"
516+
fmt.Println(url)
517517
}
518518
`}, 1, gosec.NewConfig()},
519519
{[]string{`

0 commit comments

Comments
 (0)