Skip to content

Find, verify, and analyze leaked credentials

Update results's extra data for Twilio (#2807)

Abdul Basitf527da9ecc6f
diff --git a/pkg/detectors/twilio/twilio.go b/pkg/detectors/twilio/twilio.go
index d761dc333..fa3224701 100644
--- a/pkg/detectors/twilio/twilio.go
+++ b/pkg/detectors/twilio/twilio.go
@@ -2,10 +2,12 @@ package twilio
import (
"context"
+ "encoding/json"
"fmt"
- regexp "github.com/wasilibs/go-re2"
"net/http"
+ 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"
@@ -25,6 +27,16 @@ var (
keyPat = regexp.MustCompile(`\b[0-9a-f]{32}\b`)
)
+type serviceResponse struct {
+ Services []service `json:"services"`
+}
+
+type service struct {
+ FriendlyName string `json:"friendly_name"` // friendly name of a service
+ SID string `json:"sid"` // object id of service
+ AccountSID string `json:"account_sid"` // account sid
+}
+
// Keywords are used for efficiently pre-filtering chunks.
// Use identifiers in the secret preferably, or the provider name.
func (s Scanner) Keywords() []string {
@@ -73,10 +85,16 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
req.SetBasicAuth(sid, key)
res, err := client.Do(req)
if err == nil {
- res.Body.Close() // The request body is unused.
+ defer res.Body.Close()
if res.StatusCode >= 200 && res.StatusCode < 300 {
s1.Verified = true
+ var serviceResponse serviceResponse
+ if err := json.NewDecoder(res.Body).Decode(&serviceResponse); err == nil && len(serviceResponse.Services) > 0 { // no error in parsing and have atleast one service
+ service := serviceResponse.Services[0]
+ s1.ExtraData["friendly_name"] = service.FriendlyName
+ s1.ExtraData["account_sid"] = service.AccountSID
+ }
} else if res.StatusCode == 401 || res.StatusCode == 403 {
// The secret is determinately not verified (nothing to do)
} else {