Skip to content

Find, verify, and analyze leaked credentials

fix blogger detector to use Google API prefix instead of generic hex string (#5203)

Dave Hubbard37ed218cc3b5
diff --git a/pkg/detectors/blogger/blogger.go b/pkg/detectors/blogger/blogger.go
index 35516d862..ab1274cef 100644
--- a/pkg/detectors/blogger/blogger.go
+++ b/pkg/detectors/blogger/blogger.go
@@ -22,8 +22,10 @@ var _ detectors.Detector = (*Scanner)(nil)
var (
client = common.SaneHttpClient()
- // Make sure that your group is surrounded in boundary characters such as below to reduce false positives.
- keyPat = regexp.MustCompile(detectors.PrefixRegex([]string{"blogger"}) + `\b([0-9A-Za-z-]{39})\b`)
+ // Google API keys always start with "AIzaSy" (6-char prefix + 33 remaining = 39 total).
+ // The prefix regex retains "blogger" proximity to distinguish from other Google API-backed things.
+ // No trailing \b because keys can end with '-', which is not a word character.
+ keyPat = regexp.MustCompile(detectors.PrefixRegex([]string{"blogger"}) + `\b(AIzaSy[0-9A-Za-z_-]{33})`)
)
// Keywords are used for efficiently pre-filtering chunks.
diff --git a/pkg/detectors/blogger/blogger_test.go b/pkg/detectors/blogger/blogger_test.go
index dce3c7a1c..35419c71c 100644
--- a/pkg/detectors/blogger/blogger_test.go
+++ b/pkg/detectors/blogger/blogger_test.go
@@ -25,7 +25,7 @@ func TestBlogger_Pattern(t *testing.T) {
input: `
func main() {
// Create a new request with the secret as a header
- req, err := http.NewRequest("GET", "https://api.example.com/v1/blogger/blogs?key=fnWLw7pz1tc6uCzq6qocQZIxRF6SqUaOOkLqePY", http.NoBody)
+ req, err := http.NewRequest("GET", "https://api.example.com/v1/blogger/blogs?key=AIzaSyDaGmWKa4JsXZ-HjGw7ISLn_3namBGewQe", http.NoBody)
if err != nil {
fmt.Println("Error creating request:", err)
return
@@ -44,28 +44,35 @@ func TestBlogger_Pattern(t *testing.T) {
}
}
`,
- want: []string{"fnWLw7pz1tc6uCzq6qocQZIxRF6SqUaOOkLqePY"},
+ want: []string{"AIzaSyDaGmWKa4JsXZ-HjGw7ISLn_3namBGewQe"},
},
{
name: "valid pattern - xml",
input: `
<com.cloudbees.plugins.credentials.impl.StringCredentialsImpl>
- <scope>GLOBAL</scope>
- <id>{blogger}</id>
- <secret>{blogger AQAAABAAA mtkwpygpNROxOgLZCnEvl7gNme1IuFiQm9oxPzJ}</secret>
- <description>configuration for production</description>
+ <scope>GLOBAL</scope>
+ <id>{blogger}</id>
+ <secret>{blogger AIzaSyCjkL9m2nOp4qRsTuVwXyZ0a1B2c3D4e5F}</secret>
+ <description>configuration for production</description>
<creationDate>2023-05-18T14:32:10Z</creationDate>
- <owner>jenkins-admin</owner>
+ <owner>jenkins-admin</owner>
</com.cloudbees.plugins.credentials.impl.StringCredentialsImpl>
`,
- want: []string{"mtkwpygpNROxOgLZCnEvl7gNme1IuFiQm9oxPzJ"},
+ want: []string{"AIzaSyCjkL9m2nOp4qRsTuVwXyZ0a1B2c3D4e5F"},
},
{
- name: "invalid pattern",
+ name: "false positive - java class name (CSM-2238)",
+ input: `
+ EJBLogger.logfinderReturnedMultipleValuesLoggable("@finderMethodName");
+ `,
+ want: nil,
+ },
+ {
+ name: "invalid pattern - wrong prefix",
input: `
func main() {
// Create a new request with the secret as a header
- req, err := http.NewRequest("GET", "https://api.example.com/v1/blogger/blogs?key=fnWL(w7pz1t)6uCz-q6qocQZIxRF6S/UqePY", http.NoBody)
+ req, err := http.NewRequest("GET", "https://api.example.com/v1/blogger/blogs?key=fnWLw7pz1tc6uCzq6qocQZIxRF6SqUaOOkLqePY", http.NoBody)
if err != nil {
fmt.Println("Error creating request:", err)
return
@@ -86,6 +93,19 @@ func TestBlogger_Pattern(t *testing.T) {
`,
want: nil,
},
+ {
+ name: "invalid pattern - special characters",
+ input: `
+ func main() {
+ req, err := http.NewRequest("GET", "https://api.example.com/v1/blogger/blogs?key=AIzaSy(w7pz1t)6uCz-q6qocQZIxRF6S/UqePY", http.NoBody)
+ if err != nil {
+ fmt.Println("Error creating request:", err)
+ return
+ }
+ }
+ `,
+ want: nil,
+ },
}
for _, test := range tests {