Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed mailchimp detector #909

Merged
merged 2 commits into from Nov 10, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 10 additions & 10 deletions pkg/detectors/mailchimp/mailchimp.go
Expand Up @@ -19,7 +19,7 @@ type Scanner struct{}
var _ detectors.Detector = (*Scanner)(nil)

var (
// TODO: Other country patterns?
client = common.SaneHttpClient()
keyPat = regexp.MustCompile(`[0-9a-f]{32}-us[0-9]{1,2}`)
)

Expand All @@ -46,29 +46,29 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
if verify {
datacenter := strings.Split(match, "-")[1]

client := common.SaneHttpClient()
// https://mailchimp.com/developer/guides/marketing-api-conventions/
req, err := http.NewRequestWithContext(ctx, "GET", fmt.Sprintf("https://%s.api.mailchimp.com/3.0/", datacenter), nil)
if err != nil {
continue
}
req.SetBasicAuth("anystring", match)
req.Header.Add("accept", "application/json")
res, err := client.Do(req)
if err == nil {
res.Body.Close() // The request body is unused.

if res.StatusCode == 200 {
defer res.Body.Close()
if res.StatusCode >= 200 && res.StatusCode < 300 {
s.Verified = true
} else {
// This function will check false positives for common test words, but also it will make sure the key appears 'random' enough to be a real key.
if detectors.IsKnownFalsePositive(match, detectors.DefaultFalsePositives, true) {
continue
}
}
}
}

if !s.Verified && detectors.IsKnownFalsePositive(string(s.Raw), detectors.DefaultFalsePositives, true) {
continue
}

results = append(results, s)
}

return
return results, nil
}