-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support indeterminacy in alchemy and update detector docs #1510
Changes from all commits
6ec7852
492a180
384e202
c18faa5
f771f8d
b89f762
180a9bf
039bf44
1372722
df096b5
7189ce3
347a6ed
5d89ffc
e0c3886
1636d95
ea21dd5
5cf522e
af642d6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ package alchemy | |
|
||
import ( | ||
"context" | ||
"fmt" | ||
"net/http" | ||
"regexp" | ||
"strings" | ||
|
@@ -11,14 +12,15 @@ import ( | |
"github.com/trufflesecurity/trufflehog/v3/pkg/pb/detectorspb" | ||
) | ||
|
||
type Scanner struct{} | ||
type Scanner struct { | ||
client *http.Client | ||
} | ||
|
||
// Ensure the Scanner satisfies the interface at compile time. | ||
var _ detectors.Detector = (*Scanner)(nil) | ||
|
||
var ( | ||
client = common.SaneHttpClient() | ||
|
||
defaultClient = 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{"alchemy"}) + `\b([0-9a-zA-Z]{23}_[0-9a-zA-Z]{8})\b`) | ||
) | ||
|
@@ -47,6 +49,10 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result | |
} | ||
|
||
if verify { | ||
client := s.client | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. optional: You could maybe just check There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do you mean mutating the scanner struct? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep. Or set it as a default somewhere? As it is, every time this attempts to verify it will create a new client. Which is fine, but probably not necessary. |
||
if client == nil { | ||
client = defaultClient | ||
} | ||
req, err := http.NewRequestWithContext(ctx, "GET", "https://eth-mainnet.g.alchemy.com/v2/"+resMatch+"/getNFTs/?owner=vitalik.eth", nil) | ||
if err != nil { | ||
continue | ||
|
@@ -61,7 +67,13 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result | |
if detectors.IsKnownFalsePositive(resMatch, detectors.DefaultFalsePositives, true) { | ||
continue | ||
} | ||
|
||
if res.StatusCode != 401 { | ||
s1.VerificationError = fmt.Errorf("request to %v returned unexpected status %d", res.Request.URL, res.StatusCode) | ||
} | ||
} | ||
} else { | ||
s1.VerificationError = err | ||
} | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure we can say this is true for all apis we test against. e.g. Docker can still be a valid credential and return a 401 -
trufflehog/pkg/detectors/dockerhub/dockerhub.go
Lines 79 to 82 in 8ec5e49
So maybe adjust the language to be less certain about the indeterminate verification failure in the case of non 2XX or 403 responses.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was trying to pick language that made it clear that was a hypothetical case, but I guess I didn't do a good job :(
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe a separate paragraph for the start of the hypothetical case? And potentially changing the
would
towould likely
?