-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Detect Organization ID to pass into AnalysisInfo for Atlassian Detector #4480
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
Changes from 1 commit
02d946b
0db029b
ab267c6
1ad2d85
907cae0
f39a6d8
66cb725
6d52a0d
b28c45e
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 |
|---|---|---|
|
|
@@ -35,7 +35,8 @@ var _ detectors.Versioner = (*Scanner)(nil) | |
| var ( | ||
| defaultClient = common.SaneHttpClient() | ||
| // Make sure that your group is surrounded in boundary characters such as below to reduce false positives. | ||
| keyPat = regexp.MustCompile(`\b(ATCTT3xFfG[A-Za-z0-9+/=_-]+=[A-Za-z0-9]{8})\b`) | ||
| keyPat = regexp.MustCompile(`\b(ATCTT3xFfG[A-Za-z0-9+/=_-]+=[A-Za-z0-9]{8})\b`) | ||
| organizationIdPat = regexp.MustCompile(detectors.PrefixRegex([]string{"org", "id"}) + `\b([0-9a-z]{8}-[0-9a-z]{4}-[0-9a-z]{4}-[0-9a-z]{4}-[0-9a-z]{12})\b`) | ||
| ) | ||
|
|
||
| // Keywords are used for efficiently pre-filtering chunks. | ||
|
|
@@ -58,31 +59,52 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result | |
| uniqueMatches[match[1]] = struct{}{} | ||
| } | ||
|
|
||
| for match := range uniqueMatches { | ||
| s1 := detectors.Result{ | ||
| DetectorType: detectorspb.DetectorType_Atlassian, | ||
| Raw: []byte(match), | ||
| ExtraData: map[string]string{ | ||
| "rotation_guide": "https://howtorotate.com/docs/tutorials/atlassian/", | ||
| "version": fmt.Sprintf("%d", s.Version()), | ||
| }, | ||
| } | ||
| uniqueOrgIdMatches := make(map[string]struct{}) | ||
| for _, match := range organizationIdPat.FindAllStringSubmatch(dataStr, -1) { | ||
| uniqueOrgIdMatches[match[1]] = struct{}{} | ||
| } | ||
| if len(uniqueOrgIdMatches) == 0 { | ||
| // we only need an org ID to pass into AnalysisInfo | ||
| // if we don't find one, we can still verify the key | ||
| // we can add a dummy entry here just to make sure a result is returned | ||
| uniqueOrgIdMatches[""] = struct{}{} | ||
| } | ||
|
|
||
| if verify { | ||
| client := s.client | ||
| if client == nil { | ||
| client = defaultClient | ||
| for match := range uniqueMatches { | ||
| for orgId := range uniqueOrgIdMatches { | ||
| s1 := detectors.Result{ | ||
| DetectorType: detectorspb.DetectorType_Atlassian, | ||
| Raw: []byte(match), | ||
| ExtraData: map[string]string{ | ||
| "rotation_guide": "https://howtorotate.com/docs/tutorials/atlassian/", | ||
| "version": fmt.Sprintf("%d", s.Version()), | ||
| }, | ||
| } | ||
|
|
||
| isVerified, orgResponse, verificationErr := verifyMatch(ctx, client, match) | ||
| s1.Verified = isVerified | ||
| if orgResponse != nil && len(orgResponse.Data) > 0 { | ||
| s1.ExtraData["Organization"] = orgResponse.Data[0].Attributes.Name | ||
| if verify { | ||
| client := s.client | ||
| if client == nil { | ||
| client = defaultClient | ||
| } | ||
|
|
||
| isVerified, orgResponse, verificationErr := verifyMatch(ctx, client, match) | ||
| s1.Verified = isVerified | ||
| if orgResponse != nil && len(orgResponse.Data) > 0 { | ||
| s1.ExtraData["Organization"] = orgResponse.Data[0].Attributes.Name | ||
| } | ||
| s1.SetVerificationError(verificationErr, match) | ||
| if s1.Verified { | ||
| s1.AnalysisInfo = map[string]string{ | ||
| "key": match, | ||
| } | ||
| if orgId != "" { | ||
| s1.AnalysisInfo["organization_id"] = orgId | ||
|
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. I'd really love to see non-integration test coverage that verifies that this value is appropriately included (given the right pre-conditions). 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. Will add. |
||
| } | ||
|
Comment on lines
+103
to
+105
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. Is it possible that some secrets may not actually belong to the 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. It may be possible that the secret might not belong to the For scoped keys, passing an incorrect |
||
| } | ||
| } | ||
| s1.SetVerificationError(verificationErr, match) | ||
| } | ||
|
|
||
| results = append(results, s1) | ||
| results = append(results, s1) | ||
| } | ||
| } | ||
|
|
||
| return | ||
|
|
||
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.
Can we include an example of the type of strings we expect to match on here in the inline comments? I think it will make it easier for future folks to understand the intent of the regex here. On that note - unless I'm missing it - there's not already test coverage verifying these regexes. We should add that.
Uh oh!
There was an error while loading. Please reload this page.
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.
That's a good idea. There are unit tests verifiying the regex of the key, I'll make changes to include the
organization_idas well