Find, verify, and analyze leaked credentials
Go credentialsdevsecopsdynamic-analysisprecommitscanningsecretsecret-managementsecretssecuritysecurity-toolstrufflehogverification
fix(detectors/auth0oauth): match Auth0 Private Cloud auth0app.com domains (#5354)
Stephen Aghaulord5ef0f38cf39
diff --git a/pkg/detectors/auth0oauth/auth0oauth.go b/pkg/detectors/auth0oauth/auth0oauth.goindex fa2c1f5c5..619cc3f96 100644--- a/pkg/detectors/auth0oauth/auth0oauth.go+++ b/pkg/detectors/auth0oauth/auth0oauth.go@@ -27,7 +27,11 @@ var (clientIdPat = regexp.MustCompile(detectors.PrefixRegex([]string{"auth0"}) + `\b([a-zA-Z0-9_-]{32,60})\b`)clientSecretPat = regexp.MustCompile(`\b([a-zA-Z0-9_-]{64,})\b`)- domainPat = regexp.MustCompile(`\b([a-zA-Z0-9][a-zA-Z0-9._-]*auth0\.com)\b`) // could be part of url+ // could be part of url; auth0app.com is Auth0's managed domain for Private Cloud tenants.+ // TODO: a bare domain with no leading character (e.g. "auth0.com" or "auth0app.com" with+ // no subdomain/prefix at all) never matches, since the leading character class must be+ // consumed before the literal "auth0" substring. Pre-existing, unrelated to this fix.+ domainPat = regexp.MustCompile(`\b([a-zA-Z0-9][a-zA-Z0-9._-]*auth0(?:app)?\.com)\b`))// Keywords are used for efficiently pre-filtering chunks.diff --git a/pkg/detectors/auth0oauth/auth0oauth_test.go b/pkg/detectors/auth0oauth/auth0oauth_test.goindex 1f7882405..ffdc3eae3 100644--- a/pkg/detectors/auth0oauth/auth0oauth_test.go+++ b/pkg/detectors/auth0oauth/auth0oauth_test.go@@ -50,13 +50,54 @@ func TestAuth0oAuth_Pattern(t *testing.T) {name: "invalid pattern",input: `# do not share these credentials- auth0_credentials file:+ auth0_credentials file:auth0_clientID: e4T9Cw1CtwE8ufoESVBB7Hi1U-e4T9Cw1CtwE8ufoESVBB7Hi1U- secret: MBqIYgxH0vZaL1s5314lgPDLqHX^ZsY59PSew63A_L6rySqcy5J3rFcGcpdeSQ_+tTx1kCXOZY_JUy-rXwGtKCleBsaUfpchggQEAy_yhzWnqv4_GzJivBif85bqiJi3ZA63DAauoJ2PF27fvS+ secret: MBqIYgxH0vZaL1s5314lgPDLqHX^ZsY59PSew63A_L6rySqcy5J3rFcGcpdeSQ_+tTx1kCXOZY_JUy-rXwGtKCleBsaUfpchggQEAy_yhzWnqv4_GzJivBif85bqiJi3ZA63DAauoJ2PF27fvSdomain: 9-KhTIdSopSaMQ2v1YxdFEJN#qd51AzSGQu2yRaFauth1.com`,want: nil,},+ {+ // Auth0 Private Cloud tenants default to an Auth0-managed domain in+ // the form *.auth0app.com rather than *.auth0.com.+ name: "valid pattern - private cloud auth0app.com domain",+ input: `+ # do not share these credentials+ auth0_credentials file:+ auth0_clientID: odJFCrnl2edlBDdz1C5Jau2RJtBRnlWmTSHf6pWk+ secret: 6sHrFH2ZUCr-lgotu2iXW7GboIRoL3u6aHwnMztVuaP_coUNEhEkk_iqq8vH2BzNZV45pF+ domain: api.example-corp.auth0app.com+ `,+ want: []string{"odJFCrnl2edlBDdz1C5Jau2RJtBRnlWmTSHf6pWk6sHrFH2ZUCr-lgotu2iXW7GboIRoL3u6aHwnMztVuaP_coUNEhEkk_iqq8vH2BzNZV45pF"},+ },+ {+ // word-boundary behavior is unchanged by this fix: a leading run of+ // word characters immediately before "auth0app.com" still matches in+ // full, same as it already does today for "...auth0.com" domains.+ name: "valid pattern - auth0app.com with no separator before suffix",+ input: `+ # do not share these credentials+ auth0_credentials file:+ auth0_clientID: tyLBhhOhg9uhkxiiEZpFfk1OHAOEHYqM6Ojb+ secret: 6mjBHqSiFVKu4MbMnrHontIKARAH_Ggl2JfaQqHu42bojteVs3qfNUfTAFnT0tEuw0dwQ0FIunWe8Cz6+ domain: xauth0app.com+ `,+ want: []string{"tyLBhhOhg9uhkxiiEZpFfk1OHAOEHYqM6Ojb6mjBHqSiFVKu4MbMnrHontIKARAH_Ggl2JfaQqHu42bojteVs3qfNUfTAFnT0tEuw0dwQ0FIunWe8Cz6"},+ },+ {+ // a domain with neither the "auth0.com" nor "auth0app.com" suffix+ // must not match — the optional (?:app)? group must not degrade the+ // pattern into matching arbitrary ".com" domains.+ name: "invalid pattern - domain has neither auth0.com nor auth0app.com suffix",+ input: `+ # do not share these credentials+ auth0_credentials file:+ auth0_clientID: SNDCdyZQJiJSZQdoHwHen3SO3oXyGf3azU3iQOpMN0PZ+ secret: Lqy1WwMZaMKA3P744B8vkKQlENCzsdfF8j61yX-ZFsan2Cw7gFp6r7O425u85HFJ_EJ4jKEIQOkrtDXtBi10Q71hA1+ domain: api.example.com+ `,+ want: nil,+ },}for _, test := range tests {