mirror of
https://github.com/trufflesecurity/trufflehog.git
synced 2024-11-10 07:04:24 +00:00
[chore] - Use http.NewRequestWithContext (#2870)
This commit is contained in:
parent
0a3a62be0e
commit
fccf7c9a41
31 changed files with 39 additions and 38 deletions
|
@ -84,7 +84,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
|
|||
}
|
||||
|
||||
func verifyAeroworkflow(ctx context.Context, client *http.Client, resMatch, resIdMatch string) (bool, error) {
|
||||
req, err := http.NewRequest(http.MethodGet, aeroworkflowURL+"/api/"+resIdMatch+"/v1/AeroAppointments", nil)
|
||||
req, err := http.NewRequestWithContext(ctx, http.MethodGet, aeroworkflowURL+"/api/"+resIdMatch+"/v1/AeroAppointments", nil)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
|
|
@ -49,7 +49,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
|
|||
}
|
||||
|
||||
if verify {
|
||||
req, err := http.NewRequest("GET", "https://api.avaza.com/api/Account", nil)
|
||||
req, err := http.NewRequestWithContext(ctx, "GET", "https://api.avaza.com/api/Account", nil)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
|
|
|
@ -77,7 +77,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
|
|||
h := hmac.New(sha256.New, key)
|
||||
h.Write([]byte(stringToSign))
|
||||
signature := base64.StdEncoding.EncodeToString(h.Sum(nil))
|
||||
req, err := http.NewRequest("GET", url, nil)
|
||||
req, err := http.NewRequestWithContext(ctx, "GET", url, nil)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
|
|
|
@ -63,7 +63,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
|
|||
|
||||
auth := base64.StdEncoding.EncodeToString([]byte(fmt.Sprintf("%s:%s", username, password)))
|
||||
url := fmt.Sprintf("https://%s/v2/", endpoint)
|
||||
req, err := http.NewRequest("GET", url, nil)
|
||||
req, err := http.NewRequestWithContext(ctx, "GET", url, nil)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
|
|
|
@ -53,7 +53,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
|
|||
timeout := 10 * time.Second
|
||||
client.Timeout = timeout
|
||||
payload := strings.NewReader(`{"query":"{ sshList {id, name}}"}`)
|
||||
req, err := http.NewRequest("POST", "https://api.borgbase.com/graphql", payload)
|
||||
req, err := http.NewRequestWithContext(ctx, "POST", "https://api.borgbase.com/graphql", payload)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
|
|
|
@ -68,7 +68,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
|
|||
|
||||
if verify {
|
||||
payload := strings.NewReader(fmt.Sprintf(`grant_type=client_credentials&client_id=%s&client_secret=%s`, resIdMatch, resMatch))
|
||||
req, err := http.NewRequest("POST", fmt.Sprintf("https://%s.caspio.com/oauth/token", resDomainMatch), payload)
|
||||
req, err := http.NewRequestWithContext(ctx, "POST", fmt.Sprintf("https://%s.caspio.com/oauth/token", resDomainMatch), payload)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
|
|
|
@ -48,7 +48,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
|
|||
}
|
||||
|
||||
if verify {
|
||||
req, err := http.NewRequest("GET", "https://dashboard.chatfuel.com/api/bots", nil)
|
||||
req, err := http.NewRequestWithContext(ctx, "GET", "https://dashboard.chatfuel.com/api/bots", nil)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
|
|
|
@ -62,7 +62,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
|
|||
payload.Add("username", resEmailMatch)
|
||||
payload.Add("remote_key", resMatch)
|
||||
|
||||
req, err := http.NewRequest("GET", "https://checkvist.com/auth/login.json?version=2", strings.NewReader(payload.Encode()))
|
||||
req, err := http.NewRequestWithContext(ctx, "GET", "https://checkvist.com/auth/login.json?version=2", strings.NewReader(payload.Encode()))
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
|
|
|
@ -52,7 +52,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
|
|||
`)
|
||||
timeout := 10 * time.Second
|
||||
client.Timeout = timeout
|
||||
req, err := http.NewRequest("POST", "https://api.cloudimage.com/invalidate", payload)
|
||||
req, err := http.NewRequestWithContext(ctx, "POST", "https://api.cloudimage.com/invalidate", payload)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
|
|
|
@ -61,7 +61,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
|
|||
payload.Add("user", resEmailMatch)
|
||||
payload.Add("api_key", resMatch)
|
||||
|
||||
req, err := http.NewRequest("GET", "https://api.cloze.com/v1/profile?"+payload.Encode(), nil)
|
||||
req, err := http.NewRequestWithContext(ctx, "GET", "https://api.cloze.com/v1/profile?"+payload.Encode(), nil)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
|
|
|
@ -52,7 +52,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
|
|||
if verify {
|
||||
timeout := 10 * time.Second
|
||||
client.Timeout = timeout
|
||||
req, err := http.NewRequest("POST", "https://convier.me/api/event", nil)
|
||||
req, err := http.NewRequestWithContext(ctx, "POST", "https://convier.me/api/event", nil)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
|
|
|
@ -52,7 +52,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
|
|||
if verify {
|
||||
timeout := 10 * time.Second
|
||||
client.Timeout = timeout
|
||||
req, err := http.NewRequest("GET", fmt.Sprintf("https://api.diffbot.com/v4/account?token=%s", resMatch), nil)
|
||||
req, err := http.NewRequestWithContext(ctx, "GET", fmt.Sprintf("https://api.diffbot.com/v4/account?token=%s", resMatch), nil)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
|
|
|
@ -62,7 +62,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
|
|||
timeout := 10 * time.Second
|
||||
client.Timeout = timeout
|
||||
payload := strings.NewReader(`{"source":"abcde","destination":"+6512345678","text":"Hello World!","encoding":"AUTO"}`)
|
||||
req, err := http.NewRequest("POST", fmt.Sprintf("https://sms.8x8.com/api/v1/subaccounts/%s/messages", resIdMatch), payload)
|
||||
req, err := http.NewRequestWithContext(ctx, "POST", fmt.Sprintf("https://sms.8x8.com/api/v1/subaccounts/%s/messages", resIdMatch), payload)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
|
|
|
@ -56,7 +56,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
|
|||
}
|
||||
|
||||
if verify {
|
||||
req, err := http.NewRequest("GET", "https://api.enablex.io/voice/v1/call", nil)
|
||||
req, err := http.NewRequestWithContext(ctx, "GET", "https://api.enablex.io/voice/v1/call", nil)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
|
|
|
@ -57,7 +57,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
|
|||
}
|
||||
|
||||
if verify {
|
||||
req, err := http.NewRequest("GET", fmt.Sprintf("https://api.flightstats.com/flex/aircraft/rest/v1/json/availableFields?appId=%s&appKey=%s", resId, resMatch), nil)
|
||||
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 {
|
||||
continue
|
||||
}
|
||||
|
|
|
@ -8,11 +8,12 @@ import (
|
|||
"encoding/base64"
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
regexp "github.com/wasilibs/go-re2"
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
regexp "github.com/wasilibs/go-re2"
|
||||
|
||||
"github.com/trufflesecurity/trufflehog/v3/pkg/common"
|
||||
"github.com/trufflesecurity/trufflehog/v3/pkg/detectors"
|
||||
"github.com/trufflesecurity/trufflehog/v3/pkg/pb/detectorspb"
|
||||
|
@ -44,7 +45,7 @@ func (s Scanner) Keywords() []string {
|
|||
}
|
||||
|
||||
// FromData will find and optionally verify Gemini secrets in a given set of bytes.
|
||||
func (s Scanner) FromData(_ context.Context, verify bool, data []byte) (results []detectors.Result, err error) {
|
||||
func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (results []detectors.Result, err error) {
|
||||
dataStr := string(data)
|
||||
|
||||
idMatches := keyPat.FindAllStringSubmatch(dataStr, -1)
|
||||
|
@ -66,7 +67,7 @@ func (s Scanner) FromData(_ context.Context, verify bool, data []byte) (results
|
|||
}
|
||||
|
||||
if verify {
|
||||
req, err := constructRequest(resSecretMatch, resMatch)
|
||||
req, err := constructRequest(ctx, resSecretMatch, resMatch)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
|
@ -86,8 +87,8 @@ func (s Scanner) FromData(_ context.Context, verify bool, data []byte) (results
|
|||
return results, nil
|
||||
}
|
||||
|
||||
func constructRequest(secret, keyID string) (*http.Request, error) {
|
||||
req, err := http.NewRequest("POST", baseURL+accountDetail, &bytes.Buffer{})
|
||||
func constructRequest(ctx context.Context, secret, keyID string) (*http.Request, error) {
|
||||
req, err := http.NewRequestWithContext(ctx, "POST", baseURL+accountDetail, &bytes.Buffer{})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
@ -63,7 +63,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
|
|||
payload := url.Values{}
|
||||
payload.Add("username", resEmailMatch)
|
||||
|
||||
req, err := http.NewRequest("GET", "https://www.gocanvas.com/apiv2/forms.xml", strings.NewReader(payload.Encode()))
|
||||
req, err := http.NewRequestWithContext(ctx, "GET", "https://www.gocanvas.com/apiv2/forms.xml", strings.NewReader(payload.Encode()))
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
|
|
|
@ -79,7 +79,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
|
|||
signature := getKucoinSignature(resSecretMatch, timestamp, method, endpoint, bodyStr)
|
||||
passPhrase := getKucoinPassphrase(resSecretMatch, resPassphraseMatch)
|
||||
|
||||
req, err := http.NewRequest(method, "https://api.kucoin.com"+endpoint, nil)
|
||||
req, err := http.NewRequestWithContext(ctx, method, "https://api.kucoin.com"+endpoint, nil)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
|
|
|
@ -47,7 +47,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
|
|||
}
|
||||
|
||||
if verify {
|
||||
req, err := http.NewRequest("GET", "https://api.livestorm.co/v1/ping", nil)
|
||||
req, err := http.NewRequestWithContext(ctx, "GET", "https://api.livestorm.co/v1/ping", nil)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
|
|
|
@ -57,7 +57,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
|
|||
}
|
||||
|
||||
if verify {
|
||||
req, err := http.NewRequest("GET", fmt.Sprintf("https://api.meta-api.io/api/spells/%s/runSync", resSpellMatch), nil)
|
||||
req, err := http.NewRequestWithContext(ctx, "GET", fmt.Sprintf("https://api.meta-api.io/api/spells/%s/runSync", resSpellMatch), nil)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
|
|
|
@ -48,7 +48,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
|
|||
}
|
||||
|
||||
if verify {
|
||||
req, err := http.NewRequest("GET", "https://api.pandascore.co/videogames", nil)
|
||||
req, err := http.NewRequestWithContext(ctx, "GET", "https://api.pandascore.co/videogames", nil)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
|
|
|
@ -51,7 +51,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
|
|||
if verify {
|
||||
timeout := 15 * time.Second
|
||||
client.Timeout = timeout
|
||||
req, err := http.NewRequest("GET", "https://api.pipedream.com/v1/users/me", nil)
|
||||
req, err := http.NewRequestWithContext(ctx, "GET", "https://api.pipedream.com/v1/users/me", nil)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
|
|
|
@ -56,7 +56,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
|
|||
}
|
||||
|
||||
if verify {
|
||||
req, err := http.NewRequest("GET", fmt.Sprintf("https://%s.leankit.com/io/account", resSubdomainMatch), nil)
|
||||
req, err := http.NewRequestWithContext(ctx, "GET", fmt.Sprintf("https://%s.leankit.com/io/account", resSubdomainMatch), nil)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
|
|
|
@ -90,7 +90,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
|
|||
wg.Add(1)
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
data, err := lookupFingerprint(fingerprint, s.IncludeExpired)
|
||||
data, err := lookupFingerprint(ctx, fingerprint, s.IncludeExpired)
|
||||
if err == nil {
|
||||
if data != nil {
|
||||
extraData.Add("certificate_urls", strings.Join(data.CertificateURLs, ", "))
|
||||
|
@ -153,8 +153,8 @@ type result struct {
|
|||
GitHubUsername string
|
||||
}
|
||||
|
||||
func lookupFingerprint(publicKeyFingerprintInHex string, includeExpired bool) (*result, error) {
|
||||
req, err := http.NewRequest("GET", fmt.Sprintf("https://keychecker.trufflesecurity.com/fingerprint/%s", publicKeyFingerprintInHex), nil)
|
||||
func lookupFingerprint(ctx context.Context, publicKeyFingerprintInHex string, includeExpired bool) (*result, error) {
|
||||
req, err := http.NewRequestWithContext(ctx, "GET", fmt.Sprintf("https://keychecker.trufflesecurity.com/fingerprint/%s", publicKeyFingerprintInHex), nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
@ -50,7 +50,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
|
|||
}
|
||||
|
||||
if verify {
|
||||
req, err := http.NewRequest("GET", "https://api.razorpay.com/v1/items?count=1", nil)
|
||||
req, err := http.NewRequestWithContext(ctx, "GET", "https://api.razorpay.com/v1/items?count=1", nil)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
|
|
|
@ -55,7 +55,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
|
|||
}
|
||||
|
||||
if verify {
|
||||
req, err := http.NewRequest("GET", "https://"+resDomainMatch+".repairshopr.com/api/v1/appointment_types", nil)
|
||||
req, err := http.NewRequestWithContext(ctx, "GET", "https://"+resDomainMatch+".repairshopr.com/api/v1/appointment_types", nil)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
|
|
|
@ -60,7 +60,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
|
|||
timeout := 10 * time.Second
|
||||
client.Timeout = timeout
|
||||
payload := strings.NewReader(fmt.Sprintf(`{"clientId":"%s","clientSecret":"%s"}`, resIdMatch, resMatch))
|
||||
req, err := http.NewRequest("POST", "https://api.sirv.com/v2/token", payload)
|
||||
req, err := http.NewRequestWithContext(ctx, "POST", "https://api.sirv.com/v2/token", payload)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
|
|
|
@ -54,7 +54,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
|
|||
}
|
||||
|
||||
if verify {
|
||||
req, err := http.NewRequest("GET", "https://"+resDomainMatch+".sugester.com/app/clients.json?api_token="+resMatch, nil)
|
||||
req, err := http.NewRequestWithContext(ctx, "GET", "https://"+resDomainMatch+".sugester.com/app/clients.json?api_token="+resMatch, nil)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
|
|
|
@ -47,7 +47,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
|
|||
}
|
||||
|
||||
if verify {
|
||||
req, err := http.NewRequest("GET", "https://api.the-odds-api.com/v4/sports/?apiKey="+resMatch, nil)
|
||||
req, err := http.NewRequestWithContext(ctx, "GET", "https://api.the-odds-api.com/v4/sports/?apiKey="+resMatch, nil)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
|
|
|
@ -55,7 +55,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
|
|||
}
|
||||
|
||||
if verify {
|
||||
req, err := http.NewRequest("GET", "https://api.uploadcare.com/files/", nil)
|
||||
req, err := http.NewRequestWithContext(ctx, "GET", "https://api.uploadcare.com/files/", nil)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
|
|
|
@ -118,7 +118,7 @@ func verifyURL(ctx context.Context, client *http.Client, u *url.URL) (bool, erro
|
|||
u.User = nil
|
||||
nonCredentialedURL := u.String()
|
||||
|
||||
req, err := http.NewRequest("GET", credentialedURL, nil)
|
||||
req, err := http.NewRequestWithContext(ctx, "GET", credentialedURL, nil)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
@ -136,7 +136,7 @@ func verifyURL(ctx context.Context, client *http.Client, u *url.URL) (bool, erro
|
|||
|
||||
time.Sleep(time.Millisecond * 10)
|
||||
|
||||
req, err = http.NewRequest("GET", nonCredentialedURL, nil)
|
||||
req, err = http.NewRequestWithContext(ctx, "GET", nonCredentialedURL, nil)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue