Skip to content
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

fix: fixed verification endpoint and verification logic for brand fetch #3470

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

sahil9001
Copy link
Contributor

Description:

Fixes #3469 .

ssilare@Sahils-MacBook-Air trufflehog %    go test ./pkg/detectors/brandfetch -tags=detectors

ok      github.com/trufflesecurity/trufflehog/v3/pkg/detectors/brandfetch       3.096s

Checklist:

  • Tests passing (make test-community)?
  • Lint passing (make lint this requires golangci-lint)?

"domain": "www.example.com"
}`)
req, err := http.NewRequestWithContext(ctx, "POST", "https://api.brandfetch.io/v1/color", payload)
// API upgraded to v2 from v1, new API doc:
Copy link
Contributor

Choose a reason for hiding this comment

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

API documentation link is missing.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

added, thanks @kashifkhan0771

}`)
req, err := http.NewRequestWithContext(ctx, "POST", "https://api.brandfetch.io/v1/color", payload)
// API upgraded to v2 from v1, new API doc: https://docs.brandfetch.com/reference/brand-api
req, err := http.NewRequestWithContext(ctx, "GET", "https://api.brandfetch.io/v2/brands/google.com", nil)
Copy link
Contributor

Choose a reason for hiding this comment

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

The current v1 APIs with the old tokens are still functioning properly. Therefore, rather than updating the existing version, I would recommend adding a new version of the detector.

@@ -20,7 +21,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{"brandfetch"}) + `\b([0-9A-Za-z]{40})\b`)
keyPat = regexp.MustCompile(detectors.PrefixRegex([]string{"brandfetch"}) + `\b([a-zA-Z0-9=]{44})`)
Copy link
Contributor

Choose a reason for hiding this comment

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

The token I received included a / character as well. Its length was 44, which seems correct. I recommend generating multiple tokens to confirm the pattern.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Enhanced regex and created new version for the API v2

@sahil9001 sahil9001 requested a review from a team as a code owner October 22, 2024 12:49
@@ -1642,6 +1642,8 @@ func DefaultDetectors() []detectors.Detector {
meraki.Scanner{},
saladcloudapikey.Scanner{},
boxoauth.Scanner{},
brandfetchV1.Scanner{},
Copy link
Contributor

@kashifkhan0771 kashifkhan0771 Oct 22, 2024

Choose a reason for hiding this comment

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

Missing Versioner interface implementation. For reference see any detector which has two versions (e.g Github, Gitlab etc)

Copy link
Collaborator

Choose a reason for hiding this comment

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

I’ll create an issue to document this better since it can be confusing for most contributors. Even I find the interface smuggling confusing at times, so it’s likely unclear to others as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Missing Versioner interface implementation

Can you give me an example of PR where this is implemented.

Copy link
Contributor

@kashifkhan0771 kashifkhan0771 Oct 22, 2024

Choose a reason for hiding this comment

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

Here's the implementation

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have made the relevant changes.

"github.com/trufflesecurity/trufflehog/v3/pkg/pb/detectorspb"
)

func TestBrandfetch_FromChunk(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

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

These test cases for v2 might fail as the regex is different and these v2 secrets does not exist in the vault.
I am not sure what to do here so tagging experts 👨🏻‍💻 @zricethezav @mcastorina @abmussani

And please add the the pattern test cases for both versions separately.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Screenshot 2024-10-28 at 8 46 53 PM

Didn't get your point here, tests are passing, do you mean to add the tests which will fail in v2 but are of v1 pattern?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

Issue with incorrect verification endpoint and verification logic for BrandFetch
5 participants