Skip to content

Conversation

@MuneebUllahKhan222
Copy link
Contributor

Description:
According to this GitHub issue, secrets detected by the DatadogToken detector that failed verification were not being reported to the notifier worker (CLI output).

This PR updates the DatadogToken detector to follow the same verification pattern used by newer detectors by Setting verificationError on the detectors.Result with the error returned from verifyMatch function.
With this change, unverified Datadog token findings are correctly propagated to the notifier worker and reported in CLI output.

This PR also introduces resetVerificationError function which reset the verificationError field on the results struct required when the secret is verified with any of the endpoint found/configured so as to not report a false verification error.

Checklist:

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

@MuneebUllahKhan222 MuneebUllahKhan222 requested review from a team as code owners January 14, 2026 10:07
@MuneebUllahKhan222 MuneebUllahKhan222 changed the title [INS-255] Updated datadog detector to user verifyMatch func and report verifica… [INS-255] Updated datadog detector to set verificationError in case of a verification error Jan 14, 2026
@MuneebUllahKhan222 MuneebUllahKhan222 changed the base branch from datadog-detector-verification-fix to main January 14, 2026 10:43
@MuneebUllahKhan222 MuneebUllahKhan222 marked this pull request as draft January 14, 2026 10:45
@MuneebUllahKhan222
Copy link
Contributor Author

This PR is a PR stacked on top of PR #4616 . So we will wait for PR #4616 to be merged first.

@MuneebUllahKhan222 MuneebUllahKhan222 marked this pull request as ready for review January 26, 2026 14:28
Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.

appIncluded = true
results = append(results, s1)
}

Copy link

Choose a reason for hiding this comment

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

Unused API response causes missing user/org data

High Severity

The verifyMatch function returns the decoded *userServiceResponse as res, but the code creates a new empty var serviceResponse userServiceResponse and checks its fields instead of using res. Since serviceResponse is freshly declared and empty, len(serviceResponse.Data) and len(serviceResponse.Included) will always be 0, so setUserEmails and setOrganizationInfo are never called. The res returned from verifyMatch is completely ignored.

Fix in Cursor Fix in Web

Copy link
Contributor

Choose a reason for hiding this comment

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

+1

Comment on lines +119 to +127
var uniqueFoundUrls = make(map[string]struct{})
for _, matches := range datadogURLPat.FindAllStringSubmatch(dataStr, -1) {
uniqueFoundUrls["https://"+matches[1]] = struct{}{}
}
endpoints := make([]string, 0, len(uniqueFoundUrls))
for endpoint := range uniqueFoundUrls {
endpoints = append(endpoints, endpoint)
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Why not directly append found urls into a slice?

Comment on lines +142 to +152
for _, baseURL := range s.Endpoints(endpoints...) {
client := s.getClient()
res, isVerified, verificationErr := verifyMatch(ctx, client, resApiMatch, resAppMatch, baseURL)
s1.Verified = isVerified
s1.SetVerificationError(verificationErr, resApiMatch, resAppMatch)
if isVerified && res != nil {
s1.ResetVerificationError() // Reset verification error in case a secret is verified with an endpoint
s1.AnalysisInfo = map[string]string{"apiKey": resApiMatch, "appKey": resAppMatch, "endpoint": baseURL}
var serviceResponse userServiceResponse
if len(serviceResponse.Data) > 0 {
setUserEmails(serviceResponse.Data, &s1)
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you add some empty lines in between and some comments to have better readability?

appIncluded = true
results = append(results, s1)
}

Copy link
Contributor

Choose a reason for hiding this comment

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

+1

s1.Verified = isVerified
s1.SetVerificationError(verificationErr, resApiMatch, resAppMatch)
if isVerified && res != nil {
s1.ResetVerificationError() // Reset verification error in case a secret is verified with an endpoint
Copy link
Contributor

Choose a reason for hiding this comment

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

SetVerificationError only set the error if the error is not nil than why we need to reset an error?

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants