From cba3a0def2048de22e1ae26aef88c16f4902fd88 Mon Sep 17 00:00:00 2001 From: Shahzad Haider Date: Mon, 31 Aug 2026 12:50:36 +0500 Subject: [PATCH] detectors: review adjustments Addresses review feedback on the per-detector commits. - Rename the extracted verification function to verifyMatch in all 45 detectors. The branch had introduced a per-detector name (verifyCexIO, verifyWhoxy, ...); verifyMatch is the established convention in this package and each detector is its own package, so there is no collision. - gengo and gocanvas were still swallowing the body-read error: a failed io.ReadAll fell through to `return false, nil` and recorded nothing. That is the bug this branch exists to fix, so both now return the error. - Move `defer res.Body.Close()` above io.ReadAll and drain the body first in the 13 detectors where the deferred close sat after the read, which left the body unclosed on the error return: commodities, convier, cryptocompare, dareboost, flowflu, getemail, holistic, raven, reallysimplesystems, simfin, tefter, teletype, uptimerobot. - fixerio deferred res.Body.Close() twice; drop the second. - getemail and teletype had an empty if-branch with the work in the else, left behind when the redundant `Verified = false` assignment was removed. Inverted to `if !cond { return true, nil }`. Status-code interpretation is still carried over verbatim and is not touched here. --- pkg/detectors/cexio/cexio.go | 4 ++-- pkg/detectors/commodities/commodities.go | 9 +++++--- pkg/detectors/convier/convier.go | 9 +++++--- pkg/detectors/cryptocompare/cryptocompare.go | 9 +++++--- pkg/detectors/dareboost/dareboost.go | 9 +++++--- pkg/detectors/dyspatch/dyspatch.go | 4 ++-- pkg/detectors/etherscan/etherscan.go | 4 ++-- pkg/detectors/fixerio/fixerio.go | 5 ++-- pkg/detectors/flickr/flickr.go | 4 ++-- pkg/detectors/flightstats/flightstats.go | 4 ++-- pkg/detectors/flowflu/flowflu.go | 9 +++++--- pkg/detectors/freshbooks/freshbooks.go | 4 ++-- pkg/detectors/gengo/gengo.go | 23 ++++++++++--------- pkg/detectors/getemail/getemail.go | 12 ++++++---- pkg/detectors/gocanvas/gocanvas.go | 23 ++++++++++--------- pkg/detectors/holistic/holistic.go | 9 +++++--- pkg/detectors/humanity/humanity.go | 4 ++-- pkg/detectors/infura/infura.go | 4 ++-- pkg/detectors/instamojo/instamojo.go | 4 ++-- pkg/detectors/ipstack/ipstack.go | 4 ++-- pkg/detectors/linearapi/linearapi.go | 4 ++-- pkg/detectors/mailboxlayer/mailboxlayer.go | 4 ++-- pkg/detectors/metabase/metabase.go | 4 ++-- pkg/detectors/moosend/moosend.go | 4 ++-- pkg/detectors/mrticktock/mrticktock.go | 4 ++-- pkg/detectors/onedesk/onedesk.go | 4 ++-- pkg/detectors/paralleldots/paralleldots.go | 4 ++-- pkg/detectors/planyo/planyo.go | 4 ++-- pkg/detectors/raven/raven.go | 9 +++++--- pkg/detectors/razorpay/razorpay.go | 4 ++-- .../reallysimplesystems.go | 9 +++++--- pkg/detectors/semaphore/semaphore.go | 4 ++-- pkg/detectors/simfin/simfin.go | 9 +++++--- pkg/detectors/slackwebhook/slackwebhook.go | 4 ++-- pkg/detectors/tefter/tefter.go | 9 +++++--- pkg/detectors/teletype/teletype.go | 12 ++++++---- pkg/detectors/thinkific/thinkific.go | 4 ++-- pkg/detectors/twelvedata/twelvedata.go | 4 ++-- pkg/detectors/unifyid/unifyid.go | 4 ++-- pkg/detectors/uptimerobot/uptimerobot.go | 9 +++++--- pkg/detectors/walkscore/walkscore.go | 4 ++-- pkg/detectors/weatherstack/weatherstack.go | 4 ++-- pkg/detectors/webscraping/webscraping.go | 4 ++-- pkg/detectors/websitepulse/websitepulse.go | 4 ++-- pkg/detectors/whoxy/whoxy.go | 4 ++-- 45 files changed, 164 insertions(+), 126 deletions(-) diff --git a/pkg/detectors/cexio/cexio.go b/pkg/detectors/cexio/cexio.go index 732d7ce46..47abeba4c 100644 --- a/pkg/detectors/cexio/cexio.go +++ b/pkg/detectors/cexio/cexio.go @@ -71,7 +71,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result } if verify { - isVerified, verificationErr := verifyCexIO(ctx, client, resSecretMatch, resKeyMatch, resUserIdMatch) + isVerified, verificationErr := verifyMatch(ctx, client, resSecretMatch, resKeyMatch, resUserIdMatch) s1.Verified = isVerified s1.SetVerificationError(verificationErr, resSecretMatch, resKeyMatch, resUserIdMatch) } @@ -84,7 +84,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result return results, nil } -func verifyCexIO(ctx context.Context, client *http.Client, resSecretMatch string, resKeyMatch string, resUserIdMatch string) (bool, error) { +func verifyMatch(ctx context.Context, client *http.Client, resSecretMatch string, resKeyMatch string, resUserIdMatch string) (bool, error) { timestamp := strconv.FormatInt(time.Now().Unix()*1000, 10) diff --git a/pkg/detectors/commodities/commodities.go b/pkg/detectors/commodities/commodities.go index 8ae21e55b..2ae4c88f3 100644 --- a/pkg/detectors/commodities/commodities.go +++ b/pkg/detectors/commodities/commodities.go @@ -48,7 +48,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result } if verify { - isVerified, verificationErr := verifyCommodities(ctx, client, resMatch) + isVerified, verificationErr := verifyMatch(ctx, client, resMatch) s1.Verified = isVerified s1.SetVerificationError(verificationErr, resMatch) } @@ -59,7 +59,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result return results, nil } -func verifyCommodities(ctx context.Context, client *http.Client, resMatch string) (bool, error) { +func verifyMatch(ctx context.Context, client *http.Client, resMatch string) (bool, error) { client.Timeout = 5 * time.Second req, err := http.NewRequestWithContext(ctx, "GET", "https://commodities-api.com/api/latest?access_key="+resMatch, nil) if err != nil { @@ -69,13 +69,16 @@ func verifyCommodities(ctx context.Context, client *http.Client, resMatch string if err != nil { return false, err } + defer func() { + _, _ = io.Copy(io.Discard, res.Body) + _ = res.Body.Close() + }() bodyBytes, err := io.ReadAll(res.Body) if err != nil { return false, err } bodyString := string(bodyBytes) validResponse := strings.Contains(bodyString, `"success":true`) - defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { if validResponse { return true, nil diff --git a/pkg/detectors/convier/convier.go b/pkg/detectors/convier/convier.go index cad59ba07..a7154b595 100644 --- a/pkg/detectors/convier/convier.go +++ b/pkg/detectors/convier/convier.go @@ -49,7 +49,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result } if verify { - isVerified, verificationErr := verifyConvier(ctx, client, resMatch) + isVerified, verificationErr := verifyMatch(ctx, client, resMatch) s1.Verified = isVerified s1.SetVerificationError(verificationErr, resMatch) } @@ -60,7 +60,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result return results, nil } -func verifyConvier(ctx context.Context, client *http.Client, resMatch string) (bool, error) { +func verifyMatch(ctx context.Context, client *http.Client, resMatch string) (bool, error) { timeout := 10 * time.Second client.Timeout = timeout req, err := http.NewRequestWithContext(ctx, "POST", "https://convier.me/api/event", nil) @@ -72,13 +72,16 @@ func verifyConvier(ctx context.Context, client *http.Client, resMatch string) (b if err != nil { return false, err } + defer func() { + _, _ = io.Copy(io.Discard, res.Body) + _ = res.Body.Close() + }() bodyBytes, err := io.ReadAll(res.Body) if err != nil { return false, err } bodyString := string(bodyBytes) validResponse := strings.Contains(bodyString, `"error":false`) - defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { if validResponse { return true, nil diff --git a/pkg/detectors/cryptocompare/cryptocompare.go b/pkg/detectors/cryptocompare/cryptocompare.go index 1898febc7..87563f1d0 100644 --- a/pkg/detectors/cryptocompare/cryptocompare.go +++ b/pkg/detectors/cryptocompare/cryptocompare.go @@ -47,7 +47,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result } if verify { - isVerified, verificationErr := verifyCryptoCompare(ctx, client, resMatch) + isVerified, verificationErr := verifyMatch(ctx, client, resMatch) s1.Verified = isVerified s1.SetVerificationError(verificationErr, resMatch) } @@ -58,7 +58,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result return results, nil } -func verifyCryptoCompare(ctx context.Context, client *http.Client, resMatch string) (bool, error) { +func verifyMatch(ctx context.Context, client *http.Client, resMatch string) (bool, error) { req, err := http.NewRequestWithContext(ctx, "GET", "https://min-api.cryptocompare.com/data/blockchain/list?api_key="+resMatch, nil) if err != nil { return false, err @@ -67,13 +67,16 @@ func verifyCryptoCompare(ctx context.Context, client *http.Client, resMatch stri if err != nil { return false, err } + defer func() { + _, _ = io.Copy(io.Discard, res.Body) + _ = res.Body.Close() + }() bodyBytes, err := io.ReadAll(res.Body) if err != nil { return false, err } bodyString := string(bodyBytes) errCode := strings.Contains(bodyString, `"Response":"Success"`) - defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { if errCode { return true, nil diff --git a/pkg/detectors/dareboost/dareboost.go b/pkg/detectors/dareboost/dareboost.go index 44d1b0bf6..0ae3d7a2d 100644 --- a/pkg/detectors/dareboost/dareboost.go +++ b/pkg/detectors/dareboost/dareboost.go @@ -47,7 +47,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result } if verify { - isVerified, verificationErr := verifyDareboost(ctx, client, resMatch) + isVerified, verificationErr := verifyMatch(ctx, client, resMatch) s1.Verified = isVerified s1.SetVerificationError(verificationErr, resMatch) } @@ -58,7 +58,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result return results, nil } -func verifyDareboost(ctx context.Context, client *http.Client, resMatch string) (bool, error) { +func verifyMatch(ctx context.Context, client *http.Client, resMatch string) (bool, error) { payload := strings.NewReader(`{ "token": "` + resMatch + `", "location": "Paris"}`) req, err := http.NewRequestWithContext(ctx, "POST", "https://api.dareboost.com/0.8/config", payload) @@ -70,6 +70,10 @@ func verifyDareboost(ctx context.Context, client *http.Client, resMatch string) if err != nil { return false, err } + defer func() { + _, _ = io.Copy(io.Discard, res.Body) + _ = res.Body.Close() + }() bodyBytes, err := io.ReadAll(res.Body) if err != nil { return false, err @@ -78,7 +82,6 @@ func verifyDareboost(ctx context.Context, client *http.Client, resMatch string) bodyString := string(bodyBytes) validResponse := strings.Contains(bodyString, `"status":200`) - defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { if validResponse { return true, nil diff --git a/pkg/detectors/dyspatch/dyspatch.go b/pkg/detectors/dyspatch/dyspatch.go index 1a4cd3cbd..3842b4588 100644 --- a/pkg/detectors/dyspatch/dyspatch.go +++ b/pkg/detectors/dyspatch/dyspatch.go @@ -48,7 +48,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result } if verify { - isVerified, verificationErr := verifyDyspatch(ctx, client, resMatch) + isVerified, verificationErr := verifyMatch(ctx, client, resMatch) s1.Verified = isVerified s1.SetVerificationError(verificationErr, resMatch) } @@ -59,7 +59,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result return results, nil } -func verifyDyspatch(ctx context.Context, client *http.Client, resMatch string) (bool, error) { +func verifyMatch(ctx context.Context, client *http.Client, resMatch string) (bool, error) { req, err := http.NewRequestWithContext(ctx, "GET", "https://api.dyspatch.io/templates", nil) if err != nil { return false, err diff --git a/pkg/detectors/etherscan/etherscan.go b/pkg/detectors/etherscan/etherscan.go index cda5bf4be..b2fb2bab5 100644 --- a/pkg/detectors/etherscan/etherscan.go +++ b/pkg/detectors/etherscan/etherscan.go @@ -47,7 +47,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result } if verify { - isVerified, verificationErr := verifyEtherscan(ctx, client, resMatch) + isVerified, verificationErr := verifyMatch(ctx, client, resMatch) s1.Verified = isVerified s1.SetVerificationError(verificationErr, resMatch) } @@ -58,7 +58,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result return results, nil } -func verifyEtherscan(ctx context.Context, client *http.Client, resMatch string) (bool, error) { +func verifyMatch(ctx context.Context, client *http.Client, resMatch string) (bool, error) { req, err := http.NewRequestWithContext(ctx, "GET", "https://api.etherscan.io/api?module=account&action=balance&address=0xde0b295669a9fd93d5f28d9ec85e40f4cb697bae&tag=latest&apikey="+resMatch, nil) if err != nil { return false, err diff --git a/pkg/detectors/fixerio/fixerio.go b/pkg/detectors/fixerio/fixerio.go index b7ad01d61..8999e344a 100644 --- a/pkg/detectors/fixerio/fixerio.go +++ b/pkg/detectors/fixerio/fixerio.go @@ -47,7 +47,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result } if verify { - isVerified, verificationErr := verifyFixerIO(ctx, client, resMatch) + isVerified, verificationErr := verifyMatch(ctx, client, resMatch) s1.Verified = isVerified s1.SetVerificationError(verificationErr, resMatch) } @@ -58,7 +58,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result return results, nil } -func verifyFixerIO(ctx context.Context, client *http.Client, resMatch string) (bool, error) { +func verifyMatch(ctx context.Context, client *http.Client, resMatch string) (bool, error) { req, err := http.NewRequestWithContext(ctx, "GET", "https://data.fixer.io/api/latest?access_key="+resMatch, nil) if err != nil { return false, err @@ -80,7 +80,6 @@ func verifyFixerIO(ctx context.Context, client *http.Client, resMatch string) (b // ingenious! validResponse := strings.Contains(body, `"success": true`) || strings.Contains(body, `"info":"Access Restricted - Your current Subscription Plan does not support HTTPS Encryption."`) - defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 && validResponse { return true, nil diff --git a/pkg/detectors/flickr/flickr.go b/pkg/detectors/flickr/flickr.go index bc4591b5e..e67e3ee8f 100644 --- a/pkg/detectors/flickr/flickr.go +++ b/pkg/detectors/flickr/flickr.go @@ -48,7 +48,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result } if verify { - isVerified, verificationErr := verifyFlickr(ctx, client, resMatch) + isVerified, verificationErr := verifyMatch(ctx, client, resMatch) s1.Verified = isVerified s1.SetVerificationError(verificationErr, resMatch) } @@ -59,7 +59,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result return results, nil } -func verifyFlickr(ctx context.Context, client *http.Client, resMatch string) (bool, error) { +func verifyMatch(ctx context.Context, client *http.Client, resMatch string) (bool, error) { req, err := http.NewRequestWithContext(ctx, "GET", fmt.Sprintf("https://www.flickr.com/services/rest/?method=flickr.tags.getHotList&api_key=%s", resMatch), nil) if err != nil { return false, err diff --git a/pkg/detectors/flightstats/flightstats.go b/pkg/detectors/flightstats/flightstats.go index e34ed115c..32ed5d12a 100644 --- a/pkg/detectors/flightstats/flightstats.go +++ b/pkg/detectors/flightstats/flightstats.go @@ -55,7 +55,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result } if verify { - isVerified, verificationErr := verifyFlightstats(ctx, client, resId, resMatch) + isVerified, verificationErr := verifyMatch(ctx, client, resId, resMatch) s1.Verified = isVerified s1.SetVerificationError(verificationErr, resId, resMatch) } @@ -67,7 +67,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result return results, nil } -func verifyFlightstats(ctx context.Context, client *http.Client, resId string, resMatch string) (bool, error) { +func verifyMatch(ctx context.Context, client *http.Client, resId string, resMatch string) (bool, error) { req, err := http.NewRequestWithContext(ctx, "GET", fmt.Sprintf("https://api.flightstats.com/flex/aircraft/rest/v1/json/availableFields?appId=%s&appKey=%s", resId, resMatch), nil) if err != nil { return false, err diff --git a/pkg/detectors/flowflu/flowflu.go b/pkg/detectors/flowflu/flowflu.go index 6d5dc9e5e..29fc83b0b 100644 --- a/pkg/detectors/flowflu/flowflu.go +++ b/pkg/detectors/flowflu/flowflu.go @@ -56,7 +56,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result } if verify { - isVerified, verificationErr := verifyFlowFlu(ctx, client, resAccount, resMatch) + isVerified, verificationErr := verifyMatch(ctx, client, resAccount, resMatch) s1.Verified = isVerified s1.SetVerificationError(verificationErr, resAccount, resMatch) } @@ -68,7 +68,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result return results, nil } -func verifyFlowFlu(ctx context.Context, client *http.Client, resAccount string, resMatch string) (bool, error) { +func verifyMatch(ctx context.Context, client *http.Client, resAccount string, resMatch string) (bool, error) { req, err := http.NewRequestWithContext(ctx, "GET", fmt.Sprintf("https://%s.flowlu.com/api/v1/module/crm/lead/list?api_key=%s", resAccount, resMatch), nil) if err != nil { return false, err @@ -77,6 +77,10 @@ func verifyFlowFlu(ctx context.Context, client *http.Client, resAccount string, if err != nil { return false, err } + defer func() { + _, _ = io.Copy(io.Discard, res.Body) + _ = res.Body.Close() + }() bodyBytes, err := io.ReadAll(res.Body) if err != nil { return false, err @@ -85,7 +89,6 @@ func verifyFlowFlu(ctx context.Context, client *http.Client, resAccount string, bodyString := string(bodyBytes) validResponse := strings.Contains(bodyString, `total_result`) - defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { if validResponse { return true, nil diff --git a/pkg/detectors/freshbooks/freshbooks.go b/pkg/detectors/freshbooks/freshbooks.go index e9afb564c..893de60d1 100644 --- a/pkg/detectors/freshbooks/freshbooks.go +++ b/pkg/detectors/freshbooks/freshbooks.go @@ -53,7 +53,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result } if verify { - isVerified, verificationErr := verifyFreshbooks(ctx, client, resMatch, resURI) + isVerified, verificationErr := verifyMatch(ctx, client, resMatch, resURI) s1.Verified = isVerified s1.SetVerificationError(verificationErr, resMatch, resURI) } @@ -65,7 +65,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result return results, nil } -func verifyFreshbooks(ctx context.Context, client *http.Client, resMatch string, resURI string) (bool, error) { +func verifyMatch(ctx context.Context, client *http.Client, resMatch string, resURI string) (bool, error) { req, err := http.NewRequestWithContext(ctx, "GET", fmt.Sprintf(`https://auth.freshbooks.com/oauth/authorize?client_id=%s&redirect_uri=%s&response_type=code`, resMatch, resURI), nil) if err != nil { return false, err diff --git a/pkg/detectors/gengo/gengo.go b/pkg/detectors/gengo/gengo.go index c0201ec30..9178bfe7c 100644 --- a/pkg/detectors/gengo/gengo.go +++ b/pkg/detectors/gengo/gengo.go @@ -66,7 +66,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result } if verify { - isVerified, verificationErr := verifyGengo(ctx, client, resSecretMatch, resMatch) + isVerified, verificationErr := verifyMatch(ctx, client, resSecretMatch, resMatch) s1.Verified = isVerified s1.SetVerificationError(verificationErr, resSecretMatch, resMatch) } @@ -78,7 +78,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result return results, nil } -func verifyGengo(ctx context.Context, client *http.Client, resSecretMatch string, resMatch string) (bool, error) { +func verifyMatch(ctx context.Context, client *http.Client, resSecretMatch string, resMatch string) (bool, error) { timestamp := strconv.FormatInt(time.Now().Unix(), 10) signature := getGengoSignature(timestamp, resSecretMatch) @@ -93,17 +93,18 @@ func verifyGengo(ctx context.Context, client *http.Client, resSecretMatch string return false, err } defer func() { _ = res.Body.Close() }() - body, errBody := io.ReadAll(res.Body) + body, err := io.ReadAll(res.Body) + if err != nil { + return false, err + } - if errBody == nil { - var response Response - if err := json.Unmarshal(body, &response); err != nil { - return false, err - } + var response Response + if err := json.Unmarshal(body, &response); err != nil { + return false, err + } - if res.StatusCode >= 200 && res.StatusCode < 300 && response.OpStat == "ok" { - return true, nil - } + if res.StatusCode >= 200 && res.StatusCode < 300 && response.OpStat == "ok" { + return true, nil } return false, nil diff --git a/pkg/detectors/getemail/getemail.go b/pkg/detectors/getemail/getemail.go index 0aacc7790..0aed3b29f 100644 --- a/pkg/detectors/getemail/getemail.go +++ b/pkg/detectors/getemail/getemail.go @@ -49,7 +49,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result } if verify { - isVerified, verificationErr := verifyGetEmail(ctx, client, resMatch) + isVerified, verificationErr := verifyMatch(ctx, client, resMatch) s1.Verified = isVerified s1.SetVerificationError(verificationErr, resMatch) } @@ -60,7 +60,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result return results, nil } -func verifyGetEmail(ctx context.Context, client *http.Client, resMatch string) (bool, error) { +func verifyMatch(ctx context.Context, client *http.Client, resMatch string) (bool, error) { req, err := http.NewRequestWithContext(ctx, "GET", fmt.Sprintf("https://api.getemail.io/v1/find-mail?firstname=Larry&lastname=Page&domain=google.com&api_key=%s", resMatch), nil) if err != nil { return false, err @@ -69,16 +69,18 @@ func verifyGetEmail(ctx context.Context, client *http.Client, resMatch string) ( if err != nil { return false, err } + defer func() { + _, _ = io.Copy(io.Discard, res.Body) + _ = res.Body.Close() + }() bodyBytes, err := io.ReadAll(res.Body) if err != nil { return false, err } bodyString := string(bodyBytes) errCode := strings.Contains(bodyString, `"code":"USER_NOT_EXIST"`) - defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { - if errCode { - } else { + if !errCode { return true, nil } } diff --git a/pkg/detectors/gocanvas/gocanvas.go b/pkg/detectors/gocanvas/gocanvas.go index aa1d70aa3..88b9ddf4e 100644 --- a/pkg/detectors/gocanvas/gocanvas.go +++ b/pkg/detectors/gocanvas/gocanvas.go @@ -59,7 +59,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result } if verify { - isVerified, verificationErr := verifyGoCanvas(ctx, client, emailMatch, resMatch) + isVerified, verificationErr := verifyMatch(ctx, client, emailMatch, resMatch) s1.Verified = isVerified s1.SetVerificationError(verificationErr, emailMatch, resMatch) } @@ -71,7 +71,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result return results, nil } -func verifyGoCanvas(ctx context.Context, client *http.Client, emailMatch string, resMatch string) (bool, error) { +func verifyMatch(ctx context.Context, client *http.Client, emailMatch string, resMatch string) (bool, error) { payload := url.Values{} payload.Add("username", emailMatch) @@ -86,17 +86,18 @@ func verifyGoCanvas(ctx context.Context, client *http.Client, emailMatch string, return false, err } defer func() { _ = res.Body.Close() }() - body, errBody := io.ReadAll(res.Body) + body, err := io.ReadAll(res.Body) + if err != nil { + return false, err + } - if errBody == nil { - response := Response{} - if err := xml.Unmarshal(body, &response); err != nil { - return false, err - } + response := Response{} + if err := xml.Unmarshal(body, &response); err != nil { + return false, err + } - if res.StatusCode >= 200 && res.StatusCode < 300 && response.Error == nil { - return true, nil - } + if res.StatusCode >= 200 && res.StatusCode < 300 && response.Error == nil { + return true, nil } return false, nil diff --git a/pkg/detectors/holistic/holistic.go b/pkg/detectors/holistic/holistic.go index 126e8438c..56cd2f028 100644 --- a/pkg/detectors/holistic/holistic.go +++ b/pkg/detectors/holistic/holistic.go @@ -47,7 +47,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result } if verify { - isVerified, verificationErr := verifyHolistic(ctx, client, resMatch) + isVerified, verificationErr := verifyMatch(ctx, client, resMatch) s1.Verified = isVerified s1.SetVerificationError(verificationErr, resMatch) } @@ -58,7 +58,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result return results, nil } -func verifyHolistic(ctx context.Context, client *http.Client, resMatch string) (bool, error) { +func verifyMatch(ctx context.Context, client *http.Client, resMatch string) (bool, error) { req, err := http.NewRequestWithContext(ctx, "GET", "https://api.holistic.dev/api/v1/project", nil) if err != nil { return false, err @@ -68,6 +68,10 @@ func verifyHolistic(ctx context.Context, client *http.Client, resMatch string) ( if err != nil { return false, err } + defer func() { + _, _ = io.Copy(io.Discard, res.Body) + _ = res.Body.Close() + }() bodyBytes, err := io.ReadAll(res.Body) if err != nil { return false, err @@ -76,7 +80,6 @@ func verifyHolistic(ctx context.Context, client *http.Client, resMatch string) ( bodyString := string(bodyBytes) errorResponse := strings.Contains(bodyString, `"data":[]`) - defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 && !errorResponse { return true, nil } diff --git a/pkg/detectors/humanity/humanity.go b/pkg/detectors/humanity/humanity.go index 7f97f5ead..62398de81 100644 --- a/pkg/detectors/humanity/humanity.go +++ b/pkg/detectors/humanity/humanity.go @@ -47,7 +47,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result } if verify { - isVerified, verificationErr := verifyHumanity(ctx, client, resMatch) + isVerified, verificationErr := verifyMatch(ctx, client, resMatch) s1.Verified = isVerified s1.SetVerificationError(verificationErr, resMatch) } @@ -58,7 +58,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result return results, nil } -func verifyHumanity(ctx context.Context, client *http.Client, resMatch string) (bool, error) { +func verifyMatch(ctx context.Context, client *http.Client, resMatch string) (bool, error) { req, err := http.NewRequestWithContext(ctx, "GET", "https://www.humanity.com/api/v2/me?access_token="+resMatch, nil) if err != nil { return false, err diff --git a/pkg/detectors/infura/infura.go b/pkg/detectors/infura/infura.go index 525fafde7..a782bb33a 100644 --- a/pkg/detectors/infura/infura.go +++ b/pkg/detectors/infura/infura.go @@ -47,7 +47,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result } if verify { - isVerified, verificationErr := verifyInfura(ctx, client, resMatch) + isVerified, verificationErr := verifyMatch(ctx, client, resMatch) s1.Verified = isVerified s1.SetVerificationError(verificationErr, resMatch) } @@ -58,7 +58,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result return results, nil } -func verifyInfura(ctx context.Context, client *http.Client, resMatch string) (bool, error) { +func verifyMatch(ctx context.Context, client *http.Client, resMatch string) (bool, error) { payload := strings.NewReader(`{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":1}`) req, err := http.NewRequestWithContext(ctx, "POST", "https://mainnet.infura.io/v3/"+resMatch, payload) if err != nil { diff --git a/pkg/detectors/instamojo/instamojo.go b/pkg/detectors/instamojo/instamojo.go index 9de9e22cc..15203d609 100644 --- a/pkg/detectors/instamojo/instamojo.go +++ b/pkg/detectors/instamojo/instamojo.go @@ -61,7 +61,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result if client == nil { client = defaultClient } - isVerified, verificationErr := verifyInstamojo(ctx, client, resClientId, resSecret) + isVerified, verificationErr := verifyMatch(ctx, client, resClientId, resSecret) s1.Verified = isVerified s1.SetVerificationError(verificationErr, resClientId, resSecret) } @@ -73,7 +73,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result return results, nil } -func verifyInstamojo(ctx context.Context, client *http.Client, resClientId, resSecret string) (bool, error) { +func verifyMatch(ctx context.Context, client *http.Client, resClientId, resSecret string) (bool, error) { payload := strings.NewReader("grant_type=client_credentials&client_id=" + resClientId + "&client_secret=" + resSecret) req, err := http.NewRequestWithContext(ctx, "POST", "https://api.instamojo.com/oauth2/token/", payload) diff --git a/pkg/detectors/ipstack/ipstack.go b/pkg/detectors/ipstack/ipstack.go index 137dbe466..2f100d48a 100644 --- a/pkg/detectors/ipstack/ipstack.go +++ b/pkg/detectors/ipstack/ipstack.go @@ -46,7 +46,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result } if verify { - isVerified, verificationErr := verifyIpStack(ctx, client, resMatch) + isVerified, verificationErr := verifyMatch(ctx, client, resMatch) s1.Verified = isVerified s1.SetVerificationError(verificationErr, resMatch) } @@ -57,7 +57,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result return results, nil } -func verifyIpStack(ctx context.Context, client *http.Client, resMatch string) (bool, error) { +func verifyMatch(ctx context.Context, client *http.Client, resMatch string) (bool, error) { req, err := http.NewRequestWithContext(ctx, "GET", "https://api.ipstack.com/134.201.250.155?access_key="+resMatch, nil) if err != nil { return false, err diff --git a/pkg/detectors/linearapi/linearapi.go b/pkg/detectors/linearapi/linearapi.go index 8ed31736c..9b287f1bc 100644 --- a/pkg/detectors/linearapi/linearapi.go +++ b/pkg/detectors/linearapi/linearapi.go @@ -47,7 +47,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result } if verify { - isVerified, verificationErr := verifyLinearAPI(ctx, client, resMatch) + isVerified, verificationErr := verifyMatch(ctx, client, resMatch) s1.Verified = isVerified s1.SetVerificationError(verificationErr, resMatch) } @@ -58,7 +58,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result return results, nil } -func verifyLinearAPI(ctx context.Context, client *http.Client, resMatch string) (bool, error) { +func verifyMatch(ctx context.Context, client *http.Client, resMatch string) (bool, error) { reqDataQuery := strings.NewReader(`{ "query": "{ viewer { id name } }" }`) req, err := http.NewRequestWithContext(ctx, "POST", "https://api.linear.app/graphql", reqDataQuery) if err != nil { diff --git a/pkg/detectors/mailboxlayer/mailboxlayer.go b/pkg/detectors/mailboxlayer/mailboxlayer.go index 1a8bf01a1..9e038a8a7 100644 --- a/pkg/detectors/mailboxlayer/mailboxlayer.go +++ b/pkg/detectors/mailboxlayer/mailboxlayer.go @@ -47,7 +47,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result } if verify { - isVerified, verificationErr := verifyMailboxlayer(ctx, client, resMatch) + isVerified, verificationErr := verifyMatch(ctx, client, resMatch) s1.Verified = isVerified s1.SetVerificationError(verificationErr, resMatch) } @@ -58,7 +58,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result return results, nil } -func verifyMailboxlayer(ctx context.Context, client *http.Client, resMatch string) (bool, error) { +func verifyMatch(ctx context.Context, client *http.Client, resMatch string) (bool, error) { req, err := http.NewRequestWithContext(ctx, "GET", "https://apilayer.net/api/check?access_key="+resMatch+"&email=support@email.com", nil) if err != nil { return false, err diff --git a/pkg/detectors/metabase/metabase.go b/pkg/detectors/metabase/metabase.go index 2db3fbead..990eb83b5 100644 --- a/pkg/detectors/metabase/metabase.go +++ b/pkg/detectors/metabase/metabase.go @@ -66,7 +66,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result } if verify { - isVerified, verificationErr := verifyMetabase(ctx, client, u, resMatch) + isVerified, verificationErr := verifyMatch(ctx, client, u, resMatch) s1.Verified = isVerified s1.SetVerificationError(verificationErr, resMatch) } @@ -78,7 +78,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result return results, nil } -func verifyMetabase(ctx context.Context, client *http.Client, u *url.URL, resMatch string) (bool, error) { +func verifyMatch(ctx context.Context, client *http.Client, u *url.URL, resMatch string) (bool, error) { u.Path = "/api/user/current" req, err := http.NewRequestWithContext(ctx, http.MethodGet, u.String(), nil) if err != nil { diff --git a/pkg/detectors/moosend/moosend.go b/pkg/detectors/moosend/moosend.go index b372a6b80..489b3d751 100644 --- a/pkg/detectors/moosend/moosend.go +++ b/pkg/detectors/moosend/moosend.go @@ -47,7 +47,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result } if verify { - isVerified, verificationErr := verifyMoosend(ctx, client, resMatch) + isVerified, verificationErr := verifyMatch(ctx, client, resMatch) s1.Verified = isVerified s1.SetVerificationError(verificationErr, resMatch) } @@ -58,7 +58,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result return results, nil } -func verifyMoosend(ctx context.Context, client *http.Client, resMatch string) (bool, error) { +func verifyMatch(ctx context.Context, client *http.Client, resMatch string) (bool, error) { req, err := http.NewRequestWithContext(ctx, "GET", "https://api.moosend.com/v3/lists.json?apikey="+resMatch+"&format=json", nil) if err != nil { return false, err diff --git a/pkg/detectors/mrticktock/mrticktock.go b/pkg/detectors/mrticktock/mrticktock.go index 3d2b1a161..d4d497243 100644 --- a/pkg/detectors/mrticktock/mrticktock.go +++ b/pkg/detectors/mrticktock/mrticktock.go @@ -57,7 +57,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result } if verify { - isVerified, verificationErr := verifyMrticktock(ctx, client, emailMatch, resPassword) + isVerified, verificationErr := verifyMatch(ctx, client, emailMatch, resPassword) s1.Verified = isVerified s1.SetVerificationError(verificationErr, emailMatch, resPassword) } @@ -68,7 +68,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result return results, nil } -func verifyMrticktock(ctx context.Context, client *http.Client, emailMatch string, resPassword string) (bool, error) { +func verifyMatch(ctx context.Context, client *http.Client, emailMatch string, resPassword string) (bool, error) { payload := strings.NewReader(fmt.Sprintf(`email=%s&password=%s`, emailMatch, resPassword)) req, err := http.NewRequestWithContext(ctx, "POST", "https://mrticktock.com/app/api/is_timer_active", payload) if err != nil { diff --git a/pkg/detectors/onedesk/onedesk.go b/pkg/detectors/onedesk/onedesk.go index 24a9a0785..7c4910884 100644 --- a/pkg/detectors/onedesk/onedesk.go +++ b/pkg/detectors/onedesk/onedesk.go @@ -57,7 +57,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result } if verify { - isVerified, verificationErr := verifyOnedesk(ctx, client, emailMatch, resPword) + isVerified, verificationErr := verifyMatch(ctx, client, emailMatch, resPword) s1.Verified = isVerified s1.SetVerificationError(verificationErr, emailMatch, resPword) } @@ -68,7 +68,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result return results, nil } -func verifyOnedesk(ctx context.Context, client *http.Client, emailMatch string, resPword string) (bool, error) { +func verifyMatch(ctx context.Context, client *http.Client, emailMatch string, resPword string) (bool, error) { payload := strings.NewReader(fmt.Sprintf(`{"email": "%s", "password": "%s"}`, emailMatch, resPword)) req, err := http.NewRequestWithContext(ctx, "POST", "https://app.onedesk.com/rest/2.0/login/loginUser", payload) if err != nil { diff --git a/pkg/detectors/paralleldots/paralleldots.go b/pkg/detectors/paralleldots/paralleldots.go index b9a751d40..37d900ce8 100644 --- a/pkg/detectors/paralleldots/paralleldots.go +++ b/pkg/detectors/paralleldots/paralleldots.go @@ -49,7 +49,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result } if verify { - isVerified, verificationErr := verifyParallelDots(ctx, client, resMatch) + isVerified, verificationErr := verifyMatch(ctx, client, resMatch) s1.Verified = isVerified s1.SetVerificationError(verificationErr, resMatch) } @@ -60,7 +60,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result return results, nil } -func verifyParallelDots(ctx context.Context, client *http.Client, resMatch string) (bool, error) { +func verifyMatch(ctx context.Context, client *http.Client, resMatch string) (bool, error) { payload := &bytes.Buffer{} writer := multipart.NewWriter(payload) fw, err := writer.CreateFormField("api_key") diff --git a/pkg/detectors/planyo/planyo.go b/pkg/detectors/planyo/planyo.go index aadba1a0b..b57f295c0 100644 --- a/pkg/detectors/planyo/planyo.go +++ b/pkg/detectors/planyo/planyo.go @@ -48,7 +48,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result } if verify { - isVerified, verificationErr := verifyPlanyo(ctx, client, resMatch) + isVerified, verificationErr := verifyMatch(ctx, client, resMatch) s1.Verified = isVerified s1.SetVerificationError(verificationErr, resMatch) } @@ -59,7 +59,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result return results, nil } -func verifyPlanyo(ctx context.Context, client *http.Client, resMatch string) (bool, error) { +func verifyMatch(ctx context.Context, client *http.Client, resMatch string) (bool, error) { req, err := http.NewRequestWithContext(ctx, "GET", fmt.Sprintf("https://www.planyo.com/rest/?method=get_site_info&api_key=%s", resMatch), nil) if err != nil { return false, err diff --git a/pkg/detectors/raven/raven.go b/pkg/detectors/raven/raven.go index f4beda859..bc741ec39 100644 --- a/pkg/detectors/raven/raven.go +++ b/pkg/detectors/raven/raven.go @@ -49,7 +49,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result } if verify { - isVerified, verificationErr := verifyRaven(ctx, client, resMatch) + isVerified, verificationErr := verifyMatch(ctx, client, resMatch) s1.Verified = isVerified s1.SetVerificationError(verificationErr, resMatch) } @@ -60,7 +60,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result return results, nil } -func verifyRaven(ctx context.Context, client *http.Client, resMatch string) (bool, error) { +func verifyMatch(ctx context.Context, client *http.Client, resMatch string) (bool, error) { req, err := http.NewRequestWithContext(ctx, "GET", fmt.Sprintf("https://api.raventools.com/api?key=%s&method=profile_info&format=json", resMatch), nil) if err != nil { return false, err @@ -69,11 +69,14 @@ func verifyRaven(ctx context.Context, client *http.Client, resMatch string) (boo if err != nil { return false, err } + defer func() { + _, _ = io.Copy(io.Discard, res.Body) + _ = res.Body.Close() + }() bodyBytes, err := io.ReadAll(res.Body) if err != nil { return false, err } - defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { if json.Valid(bodyBytes) { return true, nil diff --git a/pkg/detectors/razorpay/razorpay.go b/pkg/detectors/razorpay/razorpay.go index f65fc727f..7263fb3f6 100644 --- a/pkg/detectors/razorpay/razorpay.go +++ b/pkg/detectors/razorpay/razorpay.go @@ -57,7 +57,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result } if verify { - isVerified, verificationErr := verifyRazorPay(ctx, client, key, secret) + isVerified, verificationErr := verifyMatch(ctx, client, key, secret) s1.Verified = isVerified s1.SetVerificationError(verificationErr, key, secret) } @@ -70,7 +70,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result return results, nil } -func verifyRazorPay(ctx context.Context, client *http.Client, key, secret string) (bool, error) { +func verifyMatch(ctx context.Context, client *http.Client, key, secret string) (bool, error) { req, err := http.NewRequestWithContext(ctx, "GET", "https://api.razorpay.com/v1/items?count=1", nil) if err != nil { return false, err diff --git a/pkg/detectors/reallysimplesystems/reallysimplesystems.go b/pkg/detectors/reallysimplesystems/reallysimplesystems.go index 24349a044..4cfd6cad6 100644 --- a/pkg/detectors/reallysimplesystems/reallysimplesystems.go +++ b/pkg/detectors/reallysimplesystems/reallysimplesystems.go @@ -49,7 +49,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result } if verify { - isVerified, verificationErr := verifyReallySimpleSystems(ctx, client, resMatch) + isVerified, verificationErr := verifyMatch(ctx, client, resMatch) s1.Verified = isVerified s1.SetVerificationError(verificationErr, resMatch) } @@ -60,7 +60,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result return results, nil } -func verifyReallySimpleSystems(ctx context.Context, client *http.Client, resMatch string) (bool, error) { +func verifyMatch(ctx context.Context, client *http.Client, resMatch string) (bool, error) { req, err := http.NewRequestWithContext(ctx, "GET", "https://apiv4.reallysimplesystems.com/accounts", nil) if err != nil { return false, err @@ -70,11 +70,14 @@ func verifyReallySimpleSystems(ctx context.Context, client *http.Client, resMatc if err != nil { return false, err } + defer func() { + _, _ = io.Copy(io.Discard, res.Body) + _ = res.Body.Close() + }() bodyBytes, err := io.ReadAll(res.Body) if err != nil { return false, err } - defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { if json.Valid(bodyBytes) { return true, nil diff --git a/pkg/detectors/semaphore/semaphore.go b/pkg/detectors/semaphore/semaphore.go index d21edd186..8d50be925 100644 --- a/pkg/detectors/semaphore/semaphore.go +++ b/pkg/detectors/semaphore/semaphore.go @@ -52,7 +52,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result } if verify { - isVerified, verificationErr := verifySemaphore(ctx, client, resMatch) + isVerified, verificationErr := verifyMatch(ctx, client, resMatch) s1.Verified = isVerified s1.SetVerificationError(verificationErr, resMatch) } @@ -63,7 +63,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result return results, nil } -func verifySemaphore(ctx context.Context, client *http.Client, resMatch string) (bool, error) { +func verifyMatch(ctx context.Context, client *http.Client, resMatch string) (bool, error) { req, err := http.NewRequestWithContext(ctx, "GET", fmt.Sprintf("https://api.semaphore.co/api/v4/account?apikey=%s", resMatch), nil) if err != nil { return false, err diff --git a/pkg/detectors/simfin/simfin.go b/pkg/detectors/simfin/simfin.go index dd8a5ddff..3f2558e0c 100644 --- a/pkg/detectors/simfin/simfin.go +++ b/pkg/detectors/simfin/simfin.go @@ -48,7 +48,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result } if verify { - isVerified, verificationErr := verifySimFin(ctx, client, resMatch) + isVerified, verificationErr := verifyMatch(ctx, client, resMatch) s1.Verified = isVerified s1.SetVerificationError(verificationErr, resMatch) } @@ -59,7 +59,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result return results, nil } -func verifySimFin(ctx context.Context, client *http.Client, resMatch string) (bool, error) { +func verifyMatch(ctx context.Context, client *http.Client, resMatch string) (bool, error) { req, err := http.NewRequestWithContext(ctx, "GET", fmt.Sprintf("https://simfin.com/api/v2/companies/list?api-key=%s", resMatch), nil) if err != nil { return false, err @@ -69,13 +69,16 @@ func verifySimFin(ctx context.Context, client *http.Client, resMatch string) (bo if err != nil { return false, err } + defer func() { + _, _ = io.Copy(io.Discard, res.Body) + _ = res.Body.Close() + }() bodyBytes, err := io.ReadAll(res.Body) if err != nil { return false, err } bodyString := string(bodyBytes) validResponse := !strings.Contains(bodyString, `"error"`) - defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 && validResponse { return true, nil } diff --git a/pkg/detectors/slackwebhook/slackwebhook.go b/pkg/detectors/slackwebhook/slackwebhook.go index 75c00c0db..e4955f212 100644 --- a/pkg/detectors/slackwebhook/slackwebhook.go +++ b/pkg/detectors/slackwebhook/slackwebhook.go @@ -63,7 +63,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result client = defaultClient } - isVerified, verificationErr := verifySlackWebhook(ctx, client, resMatch) + isVerified, verificationErr := verifyMatch(ctx, client, resMatch) s1.Verified = isVerified s1.SetVerificationError(verificationErr, resMatch) } @@ -75,7 +75,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result return results, nil } -func verifySlackWebhook(ctx context.Context, client *http.Client, resMatch string) (bool, error) { +func verifyMatch(ctx context.Context, client *http.Client, resMatch string) (bool, error) { // We don't want to actually send anything to webhooks we find. To verify them without spamming them, we // send an intentionally malformed message and look for a particular expected error message. payload := strings.NewReader(`intentionally malformed JSON from TruffleHog scan`) diff --git a/pkg/detectors/tefter/tefter.go b/pkg/detectors/tefter/tefter.go index 74e4a065e..90153847d 100644 --- a/pkg/detectors/tefter/tefter.go +++ b/pkg/detectors/tefter/tefter.go @@ -48,7 +48,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result } if verify { - isVerified, verificationErr := verifyTefter(ctx, client, resMatch) + isVerified, verificationErr := verifyMatch(ctx, client, resMatch) s1.Verified = isVerified s1.SetVerificationError(verificationErr, resMatch) } @@ -59,7 +59,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result return results, nil } -func verifyTefter(ctx context.Context, client *http.Client, resMatch string) (bool, error) { +func verifyMatch(ctx context.Context, client *http.Client, resMatch string) (bool, error) { req, err := http.NewRequestWithContext(ctx, "POST", "https://www.tefter.io/api/bookmarks?url=google.com", nil) if err != nil { return false, err @@ -70,13 +70,16 @@ func verifyTefter(ctx context.Context, client *http.Client, resMatch string) (bo if err != nil { return false, err } + defer func() { + _, _ = io.Copy(io.Discard, res.Body) + _ = res.Body.Close() + }() bodyBytes, err := io.ReadAll(res.Body) if err != nil { return false, err } validResponse := json.Valid(bodyBytes) - defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 && validResponse { return true, nil } diff --git a/pkg/detectors/teletype/teletype.go b/pkg/detectors/teletype/teletype.go index 08100ffab..792d040c0 100644 --- a/pkg/detectors/teletype/teletype.go +++ b/pkg/detectors/teletype/teletype.go @@ -47,7 +47,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result } if verify { - isVerified, verificationErr := verifyTeletype(ctx, client, resMatch) + isVerified, verificationErr := verifyMatch(ctx, client, resMatch) s1.Verified = isVerified s1.SetVerificationError(verificationErr, resMatch) } @@ -58,7 +58,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result return results, nil } -func verifyTeletype(ctx context.Context, client *http.Client, resMatch string) (bool, error) { +func verifyMatch(ctx context.Context, client *http.Client, resMatch string) (bool, error) { req, err := http.NewRequestWithContext(ctx, "GET", "https://api.teletype.app/public/api/v1/messages", nil) if err != nil { return false, err @@ -69,6 +69,10 @@ func verifyTeletype(ctx context.Context, client *http.Client, resMatch string) ( if err != nil { return false, err } + defer func() { + _, _ = io.Copy(io.Discard, res.Body) + _ = res.Body.Close() + }() bodyBytes, err := io.ReadAll(res.Body) if err != nil { return false, err @@ -77,10 +81,8 @@ func verifyTeletype(ctx context.Context, client *http.Client, resMatch string) ( bodyString := string(bodyBytes) validResponse := strings.Contains(bodyString, `"code":401`) - defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { - if validResponse { - } else { + if !validResponse { return true, nil } } diff --git a/pkg/detectors/thinkific/thinkific.go b/pkg/detectors/thinkific/thinkific.go index 5bdf6519b..4c549c8e0 100644 --- a/pkg/detectors/thinkific/thinkific.go +++ b/pkg/detectors/thinkific/thinkific.go @@ -52,7 +52,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result } if verify { - isVerified, verificationErr := verifyThinkific(ctx, client, resDomainMatch, resMatch) + isVerified, verificationErr := verifyMatch(ctx, client, resDomainMatch, resMatch) s1.Verified = isVerified s1.SetVerificationError(verificationErr, resDomainMatch, resMatch) } @@ -64,7 +64,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result return results, nil } -func verifyThinkific(ctx context.Context, client *http.Client, resDomainMatch string, resMatch string) (bool, error) { +func verifyMatch(ctx context.Context, client *http.Client, resDomainMatch string, resMatch string) (bool, error) { domainRes := fmt.Sprintf("%s-s-school", resDomainMatch) req, err := http.NewRequestWithContext(ctx, "GET", "https://api.thinkific.com/api/public/v1/collections", nil) if err != nil { diff --git a/pkg/detectors/twelvedata/twelvedata.go b/pkg/detectors/twelvedata/twelvedata.go index 47e50d412..c16add136 100644 --- a/pkg/detectors/twelvedata/twelvedata.go +++ b/pkg/detectors/twelvedata/twelvedata.go @@ -47,7 +47,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result } if verify { - isVerified, verificationErr := verifyTwelveData(ctx, client, resMatch) + isVerified, verificationErr := verifyMatch(ctx, client, resMatch) s1.Verified = isVerified s1.SetVerificationError(verificationErr, resMatch) } @@ -58,7 +58,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result return results, nil } -func verifyTwelveData(ctx context.Context, client *http.Client, resMatch string) (bool, error) { +func verifyMatch(ctx context.Context, client *http.Client, resMatch string) (bool, error) { req, err := http.NewRequestWithContext(ctx, "GET", "https://api.twelvedata.com/earliest_timestamp?symbol=AAPL&interval=1day&apikey="+resMatch, nil) if err != nil { return false, err diff --git a/pkg/detectors/unifyid/unifyid.go b/pkg/detectors/unifyid/unifyid.go index 39afb4ec9..be01f3e1d 100644 --- a/pkg/detectors/unifyid/unifyid.go +++ b/pkg/detectors/unifyid/unifyid.go @@ -47,7 +47,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result } if verify { - isVerified, verificationErr := verifyUnifyID(ctx, client, resMatch) + isVerified, verificationErr := verifyMatch(ctx, client, resMatch) s1.Verified = isVerified s1.SetVerificationError(verificationErr, resMatch) } @@ -58,7 +58,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result return results, nil } -func verifyUnifyID(ctx context.Context, client *http.Client, resMatch string) (bool, error) { +func verifyMatch(ctx context.Context, client *http.Client, resMatch string) (bool, error) { payload := strings.NewReader(`{"token": "sample"}`) req, err := http.NewRequestWithContext(ctx, "POST", "https://api.unify.id/v1/humandetect/verify", payload) if err != nil { diff --git a/pkg/detectors/uptimerobot/uptimerobot.go b/pkg/detectors/uptimerobot/uptimerobot.go index de08a6fb9..e41dcc97a 100644 --- a/pkg/detectors/uptimerobot/uptimerobot.go +++ b/pkg/detectors/uptimerobot/uptimerobot.go @@ -47,7 +47,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result } if verify { - isVerified, verificationErr := verifyUptimeRobot(ctx, client, resMatch) + isVerified, verificationErr := verifyMatch(ctx, client, resMatch) s1.Verified = isVerified s1.SetVerificationError(verificationErr, resMatch) } @@ -58,7 +58,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result return results, nil } -func verifyUptimeRobot(ctx context.Context, client *http.Client, resMatch string) (bool, error) { +func verifyMatch(ctx context.Context, client *http.Client, resMatch string) (bool, error) { req, err := http.NewRequestWithContext(ctx, "POST", "https://api.uptimerobot.com/v2/getMonitors?api_key="+resMatch, nil) if err != nil { return false, err @@ -67,13 +67,16 @@ func verifyUptimeRobot(ctx context.Context, client *http.Client, resMatch string if err != nil { return false, err } + defer func() { + _, _ = io.Copy(io.Discard, res.Body) + _ = res.Body.Close() + }() bodyBytes, err := io.ReadAll(res.Body) if err != nil { return false, err } bodyString := string(bodyBytes) validResponse := strings.Contains(bodyString, `"ok"`) - defer func() { _ = res.Body.Close() }() if res.StatusCode >= 200 && res.StatusCode < 300 { if validResponse { return true, nil diff --git a/pkg/detectors/walkscore/walkscore.go b/pkg/detectors/walkscore/walkscore.go index 926ab8118..c622108f3 100644 --- a/pkg/detectors/walkscore/walkscore.go +++ b/pkg/detectors/walkscore/walkscore.go @@ -48,7 +48,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result } if verify { - isVerified, verificationErr := verifyWalkScore(ctx, client, resMatch) + isVerified, verificationErr := verifyMatch(ctx, client, resMatch) s1.Verified = isVerified s1.SetVerificationError(verificationErr, resMatch) } @@ -59,7 +59,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result return results, nil } -func verifyWalkScore(ctx context.Context, client *http.Client, resMatch string) (bool, error) { +func verifyMatch(ctx context.Context, client *http.Client, resMatch string) (bool, error) { req, err := http.NewRequestWithContext(ctx, "GET", fmt.Sprintf("https://transit.walkscore.com/transit/search/stops/?lat=47.6101359&lon=-122.3420567&wsapikey=%s", resMatch), nil) if err != nil { return false, err diff --git a/pkg/detectors/weatherstack/weatherstack.go b/pkg/detectors/weatherstack/weatherstack.go index 962619fca..e0778f522 100644 --- a/pkg/detectors/weatherstack/weatherstack.go +++ b/pkg/detectors/weatherstack/weatherstack.go @@ -48,7 +48,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result } if verify { - isVerified, verificationErr := verifyWeatherStack(ctx, client, resMatch) + isVerified, verificationErr := verifyMatch(ctx, client, resMatch) s1.Verified = isVerified s1.SetVerificationError(verificationErr, resMatch) } @@ -59,7 +59,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result return results, nil } -func verifyWeatherStack(ctx context.Context, client *http.Client, resMatch string) (bool, error) { +func verifyMatch(ctx context.Context, client *http.Client, resMatch string) (bool, error) { req, err := http.NewRequestWithContext(ctx, "GET", fmt.Sprintf("https://api.weatherstack.com/current?access_key=%s&query=LA", resMatch), nil) if err != nil { return false, err diff --git a/pkg/detectors/webscraping/webscraping.go b/pkg/detectors/webscraping/webscraping.go index 15cc0d1be..d39d19169 100644 --- a/pkg/detectors/webscraping/webscraping.go +++ b/pkg/detectors/webscraping/webscraping.go @@ -47,7 +47,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result } if verify { - isVerified, verificationErr := verifyWebscraping(ctx, client, resMatch) + isVerified, verificationErr := verifyMatch(ctx, client, resMatch) s1.Verified = isVerified s1.SetVerificationError(verificationErr, resMatch) } @@ -58,7 +58,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result return results, nil } -func verifyWebscraping(ctx context.Context, client *http.Client, resMatch string) (bool, error) { +func verifyMatch(ctx context.Context, client *http.Client, resMatch string) (bool, error) { req, err := http.NewRequestWithContext(ctx, "GET", `https://api.webscrapingapi.com/v1?api_key=`+resMatch, nil) if err != nil { return false, err diff --git a/pkg/detectors/websitepulse/websitepulse.go b/pkg/detectors/websitepulse/websitepulse.go index 58a0d46d7..2c890d27f 100644 --- a/pkg/detectors/websitepulse/websitepulse.go +++ b/pkg/detectors/websitepulse/websitepulse.go @@ -53,7 +53,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result SecretParts: map[string]string{"key": resMatch}, } if verify { - isVerified, verificationErr := verifyWebsitepulse(ctx, client, resIdMatch, resMatch) + isVerified, verificationErr := verifyMatch(ctx, client, resIdMatch, resMatch) s1.Verified = isVerified s1.SetVerificationError(verificationErr, resIdMatch, resMatch) } @@ -66,7 +66,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result return results, nil } -func verifyWebsitepulse(ctx context.Context, client *http.Client, resIdMatch string, resMatch string) (bool, error) { +func verifyMatch(ctx context.Context, client *http.Client, resIdMatch string, resMatch string) (bool, error) { req, err := http.NewRequestWithContext(ctx, "GET", fmt.Sprintf("https://api.websitepulse.com/textserver.php?method=GetContacts&username=%s&key=%s", resIdMatch, resMatch), nil) if err != nil { return false, err diff --git a/pkg/detectors/whoxy/whoxy.go b/pkg/detectors/whoxy/whoxy.go index cb53e6568..9ce58d9fc 100644 --- a/pkg/detectors/whoxy/whoxy.go +++ b/pkg/detectors/whoxy/whoxy.go @@ -48,7 +48,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result } if verify { - isVerified, verificationErr := verifyWhoxy(ctx, client, resMatch) + isVerified, verificationErr := verifyMatch(ctx, client, resMatch) s1.Verified = isVerified s1.SetVerificationError(verificationErr, resMatch) } @@ -59,7 +59,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result return results, nil } -func verifyWhoxy(ctx context.Context, client *http.Client, resMatch string) (bool, error) { +func verifyMatch(ctx context.Context, client *http.Client, resMatch string) (bool, error) { req, err := http.NewRequestWithContext(ctx, "GET", fmt.Sprintf("https://api.whoxy.com/?key=%s&account=balance", resMatch), nil) if err != nil { return false, err