Skip to content

Commit

Permalink
Merge branch 'main' into coda
Browse files Browse the repository at this point in the history
  • Loading branch information
ankushgoel27 authored Oct 31, 2023
2 parents 6110a42 + 499cb64 commit 0be6087
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 12 deletions.
10 changes: 3 additions & 7 deletions pkg/detectors/appfollow/appfollow.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ package appfollow

import (
"context"
b64 "encoding/base64"
"fmt"
"net/http"
"regexp"
"strings"
Expand All @@ -22,7 +20,7 @@ var (
client = common.SaneHttpClient()

// Make sure that your group is surrounded in boundary characters such as below to reduce false positives.
keyPat = regexp.MustCompile(detectors.PrefixRegex([]string{"appfollow"}) + `\b([0-9A-Za-z]{20})\b`)
keyPat = regexp.MustCompile(detectors.PrefixRegex([]string{"appfollow"}) + `\b(eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9\.[0-9A-Za-z]{74}\.[0-9A-Z-a-z\-_]{43})\b`)
)

// Keywords are used for efficiently pre-filtering chunks.
Expand All @@ -49,13 +47,11 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
}

if verify {
data := fmt.Sprintf("%s:", resMatch)
sEnc := b64.StdEncoding.EncodeToString([]byte(data))
req, err := http.NewRequestWithContext(ctx, "GET", "https://api.appfollow.io/test", nil)
req, err := http.NewRequestWithContext(ctx, "GET", "https://api.appfollow.io/api/v2/account/users", nil)
if err != nil {
continue
}
req.Header.Add("Authorization", fmt.Sprintf("Basic %s", sEnc))
req.Header.Add("X-AppFollow-API-Token", resMatch)
res, err := client.Do(req)
if err == nil {
defer res.Body.Close()
Expand Down
51 changes: 49 additions & 2 deletions pkg/detectors/redis/redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package redis

import (
"context"
"fmt"
"net/url"
"regexp"
"strings"
Expand All @@ -18,7 +19,8 @@ type Scanner struct{}
var _ detectors.Detector = (*Scanner)(nil)

var (
keyPat = regexp.MustCompile(`\bredis://[\S]{3,50}:([\S]{3,50})@[-.%\w\/:]+\b`)
keyPat = regexp.MustCompile(`\bredi[s]{1,2}://[\S]{3,50}:([\S]{3,50})@[-.%\w\/:]+\b`)
azureRedisPat = regexp.MustCompile(`\b([\w\d.-]{1,100}\.redis\.cache\.windows\.net:6380),password=([^,]{44}),ssl=True,abortConnect=False\b`)
)

// Keywords are used for efficiently pre-filtering chunks.
Expand All @@ -32,6 +34,51 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
dataStr := string(data)

matches := keyPat.FindAllStringSubmatch(dataStr, -1)
azureMatches := azureRedisPat.FindAllStringSubmatch(dataStr, -1)

for _, match := range azureMatches {
host := match[1]
password := match[2]
urlMatch := fmt.Sprintf("rediss://:%s@%s", password, host)

// Skip findings where the password only has "*" characters, this is a redacted password
if strings.Trim(password, "*") == "" {
continue
}

parsedURL, err := url.Parse(urlMatch)
if err != nil {
continue
}
if _, ok := parsedURL.User.Password(); !ok {
continue
}

redact := strings.TrimSpace(strings.Replace(urlMatch, password, "*******", -1))

s := detectors.Result{
DetectorType: detectorspb.DetectorType_Redis,
Raw: []byte(urlMatch),
Redacted: redact,
}

if verify {
s.Verified = verifyRedis(ctx, parsedURL)
}

if !s.Verified {
// Skip unverified findings where the password starts with a `$` - it's almost certainly a variable.
if strings.HasPrefix(password, "$") {
continue
}
}

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

results = append(results, s)
}

for _, match := range matches {
urlMatch := match[0]
Expand All @@ -50,7 +97,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
continue
}

redact := strings.TrimSpace(strings.Replace(urlMatch, password, "********", -1))
redact := strings.TrimSpace(strings.Replace(urlMatch, password, "*******", -1))

s := detectors.Result{
DetectorType: detectorspb.DetectorType_Redis,
Expand Down
3 changes: 0 additions & 3 deletions pkg/detectors/redis/redis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,6 @@ func TestURI_FromChunk(t *testing.T) {
t.Errorf("URI.FromData() error = %v, wantErr %v", err, tt.wantErr)
return
}
// if os.Getenv("FORCE_PASS_DIFF") == "true" {
// return
// }
for i := range got {
got[i].Raw = nil
}
Expand Down

0 comments on commit 0be6087

Please sign in to comment.