Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions pkg/detectors/twilio/twilio.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ var _ detectors.Detector = (*Scanner)(nil)

var (
defaultClient = common.SaneHttpClient()
sidPat = regexp.MustCompile(`\bAC[0-9a-f]{32}\b`)
keyPat = regexp.MustCompile(`\b[0-9a-f]{32}\b`)
sidPat = regexp.MustCompile(detectors.PrefixRegex([]string{"twilio", "account", "id", "sid"}) + `\b(AC[0-9a-f]{32})\b`)
keyPat = regexp.MustCompile(detectors.PrefixRegex([]string{"twilio", "auth", "token", "secret", "key"}) + `\b([0-9a-f]{32})\b`)
)

type serviceResponse struct {
Expand All @@ -49,18 +49,20 @@ func (s Scanner) getClient() *http.Client {
// Keywords are used for efficiently pre-filtering chunks.
// Use identifiers in the secret preferably, or the provider name.
func (s Scanner) Keywords() []string {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really think we need to have unit test coverage the covers this case, especially since it's already been causing problems, just to prevent regressions in the future (and make absolutely clear why we're making this change).

return []string{"sid", "twilio"}
return []string{"twilio"}
}

// FromData will find and optionally verify Twilio secrets in a given set of bytes.
func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (results []detectors.Result, err error) {
dataStr := string(data)

keyMatches := keyPat.FindAllString(dataStr, -1)
sidMatches := sidPat.FindAllString(dataStr, -1)
keyMatches := keyPat.FindAllStringSubmatch(dataStr, -1)
sidMatches := sidPat.FindAllStringSubmatch(dataStr, -1)

for _, sid := range sidMatches {
for _, key := range keyMatches {
for _, sidMatch := range sidMatches {
sid := sidMatch[1]
for _, keyMatch := range keyMatches {
key := keyMatch[1]
s1 := detectors.Result{
DetectorType: detectorspb.DetectorType_Twilio,
Raw: []byte(sid),
Expand Down
1 change: 1 addition & 0 deletions pkg/detectors/twilioapikey/twilioapikey.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
for _, apiKey := range apiKeyMatches {
for _, secret := range secretMatches {
s1 := detectors.Result{
// TODO: We need to use the correct DetectorType here; detectorspb.DetectorType_TwilioApiKey
DetectorType: detectorspb.DetectorType_Twilio,
Raw: []byte(apiKey),
RawV2: []byte(apiKey + secret),
Expand Down