Skip to content
Changes

Reference

netsuite · Oct 5, 2026

What this change means

Deduplication changed. Changes keywords, regex patterns or pairing.

pkg/detectors/netsuite/netsuite.go+59−3View file
@@ -7,7 +7,10 @@ import (
77 "crypto/sha256"
88 "encoding/base64"
99 "encoding/binary"
10added: "errors"
1011 "fmt"
12added: "io"
13added: "net"
1114 "net/http"
1215 "net/url"
1316 "strconv"
@@ -16,6 +19,7 @@ import (
1619
1720 regexp "github.com/wasilibs/go-re2"
1821
22added: "github.com/trufflesecurity/trufflehog/v3/pkg/cache/simple"
1923 "github.com/trufflesecurity/trufflehog/v3/pkg/common"
2024 "github.com/trufflesecurity/trufflehog/v3/pkg/detectors"
2125 "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb"
@@ -41,6 +45,9 @@ var (
4145 tokenSecretPat = regexp.MustCompile(detectors.PrefixRegex([]string{"netsuite", "token", "secret"}) + `\b([a-zA-Z0-9]{64})\b`)
4246
4347 accountIDPat = regexp.MustCompile(detectors.PrefixRegex([]string{"netsuite", "account", "id"}) + `\b([a-zA-Z0-9-_]{6,15})\b`)
48added:
49added: // invalidHosts holds account hosts that do not resolve, so later combinations skip the lookup.
50added: invalidHosts = simple.NewCache[struct{}]()
4451)
4552
4653type credentialSet struct {
@@ -68,8 +75,23 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
6875 tokenSecretMatches := trimUniqueMatches(tokenSecretPat.FindAllStringSubmatch(dataStr, -1))
6976 accountIDMatches := trimUniqueMatches(accountIDPat.FindAllStringSubmatch(dataStr, -1))
7077
78added: // Every combination needs a token key, token secret and account ID.
79added: if len(tokenKeyMatches) == 0 || len(tokenSecretMatches) == 0 || len(accountIDMatches) == 0 {
80added: return nil, nil
81added: }
82added:
83added: // Raw and RawV2 hold only the consumer key and secret, so every combination for a pair is a duplicate of the same
84added: // finding. Report one result per pair rather than one per combination of all five parts. The token key, token
85added: // secret and account ID decide whether the pair is reported and whether it verifies.
7186 for consumerKey := range consumerKeyMatches {
7287 for consumerSecret := range consumerSecretMatches {
88added: // No combination can use the same value as both consumer key and secret.
89added: if consumerKey == consumerSecret {
90added: continue
91added: }
92added:
93added: var pairResult *detectors.Result
94added: combinations:
7395 for tokenKey := range tokenKeyMatches {
7496 for tokenSecret := range tokenSecretMatches {
7597 for accountID := range accountIDMatches {
@@ -107,10 +129,28 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
107129 s1.Verified = isVerified
108130 s1.SetVerificationError(err, consumerKey)
109131 }
110removed: results = append(results, s1)
132added:
133added: // Keep the verified result, else the first indeterminate one, else the first one.
134added: if pairResult == nil || s1.Verified || (s1.VerificationError() != nil && pairResult.VerificationError() == nil) {
135added: pairResult = &s1
136added: }
137added: if !verify || s1.Verified {
138added: break combinations
139added: }
140added: if err := ctx.Err(); err != nil {
141added: // Combinations left untried might have verified.
142added: if pairResult.VerificationError() == nil {
143added: pairResult.SetVerificationError(err, consumerKey)
144added: }
145added: break combinations
146added: }
111147 }
112148 }
113149 }
150added:
151added: if pairResult != nil {
152added: results = append(results, *pairResult)
153added: }
114154 }
115155 }
@@ -126,9 +166,20 @@ func (s Scanner) Description() string {
126166}
127167
128168func verifyCredentials(ctx context.Context, client *http.Client, cs credentialSet) (bool, error) {
169added: // The engine waits for FromData to return even after its deadline, so send no request once the context is done.
170added: if err := ctx.Err(); err != nil {
171added: return false, err
172added: }
173added:
129174 // for url, filter or replace underscore in accountID if needed and lower case the accountID
130175 urlAccountId := strings.ToLower(strings.ReplaceAll(cs.accountID, "_", "-"))
131176
177added: // An earlier combination already found that this account's host does not resolve, so skip the lookup and
178added: // return what the lookup would.
179added: if invalidHosts.Exists(urlAccountId) {
180added: return false, nil
181added: }
182added:
132183 baseUrl := "https://" + urlAccountId + ".suitetalk.api.netsuite.com"
133184
134185 const path = "/services/rest/record/v1/metadata-catalog/check"
@@ -164,12 +215,17 @@ func verifyCredentials(ctx context.Context, client *http.Client, cs credentialSe
164215 // Make the request
165216 res, err := client.Do(req)
166217 if err != nil {
167removed: if strings.Contains(err.Error(), "no such host") {
218added: var dnsErr *net.DNSError
219added: if errors.As(err, &dnsErr) && dnsErr.IsNotFound {
220added: invalidHosts.Set(urlAccountId, struct{}{})
168221 return false, nil
169222 }
170223 return false, err
171224 }
172removed: defer func() { _ = res.Body.Close() }()
225added: defer func() {
226added: _, _ = io.Copy(io.Discard, res.Body)
227added: _ = res.Body.Close()
228added: }()
173229 switch res.StatusCode {
174230 case http.StatusOK:
175231 return true, nil