Skip to content

Conversation

@MuneebUllahKhan222
Copy link
Contributor

Description:

Previously, the datadogtoken detector was responsible for verifying both API keys and Application keys for Datadog. This caused an issue where an invalid Application key would incorrectly mark a valid API key as unverified, leading to false positives.

To resolve this, we have introduced a new detector: datadogapikey. This detector is focused solely on validating Datadog API keys, ensuring that API key verification is isolated and accurate, independent of the App key status.

Checklist:

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

@MuneebUllahKhan222 MuneebUllahKhan222 requested a review from a team December 30, 2025 09:12
@MuneebUllahKhan222 MuneebUllahKhan222 requested review from a team as code owners December 30, 2025 09:12
Comment on lines +98 to +109
case "datadog":
inputs = []textinputs.InputConfig{{
Label: "API Key",
Key: "apiKey",
Required: true,
RedactInput: true,
}, {
Label: "Application Key",
Key: "appKey",
Required: true,
RedactInput: true,
}, {
Copy link
Contributor

Choose a reason for hiding this comment

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

From my understanding of the PR description, the API key and application key are distinct credentials and can be verified independently, which is why we now have separate detectors for each. However, since we use a single analyzer for Datadog, it appears that the analyzer treats the application key as optional while requiring the API key. Is this the intended behavior? Also, do both keys provide access to the same set of resources?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yup, you are right both app key and apikey are distinct credentials and can we verified independently, I will/have introduced a validation check in Datadog's analyzer to make sure both appkey and apikey are passed to the analyzer.
Also all the api key have the same permissions(Send metrics, logs and event) so we wont't need a analyzer for it.

Comment on lines +81 to +87
if endpoint != "" {
baseURL = endpoint + "/api"
} else {
baseURL, err = DetectDomain(client, apiKey, appKey)
if err != nil {
return nil, fmt.Errorf("[x] %v", err)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this is right, keeping the domain detection helps OSS.
In Enterprise, the Analyzer would only run after successfully detecting so I think we're good.

client = common.SaneHttpClient()

// Make sure that your group is surrounded in boundary characters such as below to reduce false positives.
apiKeyPat = regexp.MustCompile(detectors.PrefixRegex([]string{"datadog", "dd"}) + `\b([a-zA-Z-0-9]{32})\b`)
Copy link
Contributor

Choose a reason for hiding this comment

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

Checking for a 32-character string that contains numbers or letters seems a little broad. Maybe an entropy test on the found matches would filter out the "non secret" strings?

resApiMatch := strings.TrimSpace(apiMatch[1])
s1 := detectors.Result{
DetectorType: detectorspb.DetectorType_DatadogApikey,
Raw: []byte(resApiMatch),
Copy link
Contributor

Choose a reason for hiding this comment

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

I think associated endpoint the detected key is being tested on should be part of RawV2 in the results. It will help distinguish verified key-endpoint pairs with unverified ones.

Copy link
Contributor

Choose a reason for hiding this comment

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

Could add the URL in the result's extra data 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.

URL added in ExtraData.

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.

5 participants