Skip to content

[INS-339] Add New Relic User Key detector#4794

Open
mustansir14 wants to merge 8 commits intotrufflesecurity:mainfrom
mustansir14:INS-339-Detector-Visible-New-Relic-User-API-Key
Open

[INS-339] Add New Relic User Key detector#4794
mustansir14 wants to merge 8 commits intotrufflesecurity:mainfrom
mustansir14:INS-339-Detector-Visible-New-Relic-User-API-Key

Conversation

@mustansir14
Copy link
Copy Markdown
Contributor

@mustansir14 mustansir14 commented Mar 6, 2026

Description:

This PR adds the New Relic User Key Detector.

Regex: \b(NRAK-[A-Z0-9]{27})\b

Verification:
For verification, we use the New relic NerdGraph API: https://api.newrelic.com/graphql.
We send a POST request with body { requestContext { userId } }. A response code of 200 means the key is valid. 401 means it is an invalid/rotated key and 403 means the region is incorrect.
Note: For EU region keys, the endpoint should be https://api.eu.newrelic.com/graphql"

Corpora Test:
The detector does not appear in the list.
image
image

Checklist:

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

Note

Medium Risk
Introduces a new detector with live HTTP verification against New Relic’s US/EU NerdGraph endpoints, which could impact scan performance or verification behavior if the API/regions change.

Overview
Adds a new newrelicuserkey detector that matches NRAK-... user keys and (when verification is enabled) validates them by calling New Relic’s NerdGraph API across US/EU regions, returning the detected region and userId as extra metadata.

Registers the new detector in the default detector list and extends the DetectorType enum/proto to include NewRelicUserKey, with unit and integration tests covering matching and verification outcomes.

Reviewed by Cursor Bugbot for commit deaeb41. Bugbot is set up for automated code reviews on this repo. Configure here.

@mustansir14 mustansir14 requested a review from a team March 6, 2026 10:50
@mustansir14 mustansir14 requested review from a team as code owners March 6, 2026 10:50
Comment thread pkg/detectors/newrelicuserkey/newrelicuserkey.go Outdated
Comment thread pkg/detectors/newrelicuserkey/newrelicuserkey.go Outdated

res, err := client.Do(req)
if err != nil {
return false, nil, fmt.Errorf("error making request: %w", err)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

same suggestion as here

Copy link
Copy Markdown

@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.

Fix All in Cursor

type graphqlResponse struct {
Data struct {
RequestContext struct {
UserID string `json:"userId"`
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

UserID field type likely mismatches API integer response

High Severity

The graphqlResponse struct defines UserID as string, but the NerdGraph API's requestContext.userId field returns a JSON integer (number). Go's json.Decoder cannot unmarshal a JSON number into a string field and will return a decode error. This causes verifyRegion to return an error on valid 200 OK responses, so valid keys are never marked as verified — they get a verification error instead.

Additional Locations (1)
Fix in Cursor Fix in Web

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