Skip to content

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

Open
mustansir14 wants to merge 6 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 6 commits intotrufflesecurity:mainfrom
mustansir14:INS-339-Detector-Visible-New-Relic-User-API-Key

Conversation

@mustansir14
Copy link
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
Adds a new detector that performs outbound verification calls to New Relic’s NerdGraph API (US/EU), which can affect scan behavior via network timeouts/rate limits and introduces a new protobuf enum value consumed across the codebase.

Overview
Adds a new newrelicuserkey detector to identify New Relic User API keys via regex (NRAK-...) and optionally verify them by calling the NerdGraph GraphQL endpoint in both US and EU regions, returning region and user_id as ExtraData when validated.

Wires the detector into the default detector set and extends the detector type enum (DetectorType_NewRelicUserKey = 1044) in proto/detectors.proto (and regenerated detectors.pb.go), with unit and integration tests plus a benchmark for the new detector.

Written by Cursor Bugbot for commit b62ea01. This will update automatically on new commits. 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

res, err := client.Do(req)
if err != nil {
return false, nil, fmt.Errorf("error making request: %w", err)
Copy link
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

@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

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