Skip to content

feat(detectors): add VisibleNpmRegistryAuthData detector#5052

Open
deerajcm wants to merge 1 commit into
trufflesecurity:mainfrom
deerajcm:add-visible-npm-registry-auth-detector
Open

feat(detectors): add VisibleNpmRegistryAuthData detector#5052
deerajcm wants to merge 1 commit into
trufflesecurity:mainfrom
deerajcm:add-visible-npm-registry-auth-detector

Conversation

@deerajcm

@deerajcm deerajcm commented Jun 18, 2026

Copy link
Copy Markdown

Description:

Summary

  • Adds a detector for visible npm registry auth data in .npmrc files
  • Detects both _authToken (npm tokens) and _auth (base64 credentials)
  • Verifier calls GET /-/whoami endpoint to validate npm tokens; treats 200 as verified, 401/403 as determinately invalid
  • Adds VisibleNpmRegistryAuthData = 1054 to proto/detector_type.proto, regenerated pb.go, and registers the scanner in pkg/engine/defaults/defaults.go
  • Populates SecretParts with auth_kind and key, includes a rotation_guide in ExtraData, and implements CustomFalsePositiveChecker

Test plan

  • go test ./pkg/detectors/visiblenpmregistryauthdata -tags=detectors -v — all pattern + verify cases pass
  • go build ./... succeeds
  • go vet ./... clean on touched packages

Notes

NPM registry auth data in .npmrc files can expose publish/install privileges to private or public registries. Leaked credentials grant full access to package publishing and consumption.

Detection

  • Keyword pre-filter: _authToken, _auth, registry.npmjs.org, npmrc
  • Patterns:
    • _authToken line: matches npm tokens and UUIDs
    • _auth line: matches base64-encoded credentials (16+ chars)

Verification

  • GET https://registry.npmjs.org/-/whoami with Authorization: Bearer <token>
  • 200 → verified
  • 401/403 → determinately unverified (no error)
  • Other status → indeterminate (verification error surfaced)
  • Note: _auth values (base64) are not verifiable without assuming decode structure

Note

Medium Risk
Adds outbound verification calls to the npm registry when scanning with verify enabled; detection logic is isolated but overlaps conceptually with existing npm token detectors.

Overview
Adds a VisibleNpmRegistryAuthData scanner for credentials embedded in .npmrc-style config (not bare npm_ tokens alone). It matches _authToken and _auth assignment lines, deduplicates hits, tags results with auth_kind / rotation metadata, and plugs into default detectors via proto enum 1054.

When verification is on, token-shaped values (npm_* or UUID) are checked with GET …/-/whoami and Authorization: Bearer; 200 marks verified, 401/403 unverified, other statuses surface a verification error. _auth base64 blobs are reported but not verified.

Unit tests cover regex/keyword matching and mocked whoami behavior.

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

Adds a detector for visible npm registry auth data in .npmrc files.
Detects both _authToken (npm tokens) and _auth (base64 credentials).
The verifier calls GET /-/whoami endpoint to validate npm tokens
(200 = verified, 401/403 = invalid).

- Adds DetectorType_VisibleNpmRegistryAuthData (enum 1054) to proto
- Implements Scanner with pattern matching for _authToken and _auth
- Includes comprehensive tests for pattern matching and verification
- Registers detector in DefaultDetectors

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@deerajcm deerajcm requested a review from a team June 18, 2026 11:38
@deerajcm deerajcm requested review from a team as code owners June 18, 2026 11:38
@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.


Deeraj CM seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

@cursor cursor Bot left a comment

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.

Cursor Bugbot has reviewed your changes and found 2 potential issues.

Fix All in Cursor

Reviewed by Cursor Bugbot for commit 7576597. Configure here.

Comment thread proto/detector_type.proto
GitLabOauth2 = 1050;
SpectralOps = 1051;
AWSAppSync = 1052;
VisibleNpmRegistryAuthData = 1054;

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.

Skipped proto enum value 1053

Medium Severity

VisibleNpmRegistryAuthData is assigned proto enum value 1054, but the previous entry AWSAppSync is 1052, skipping value 1053. Every other value in the enum from 0 through 1052 is sequential with no gaps. This looks like an accidental off-by-one and could cause confusion or conflicts if another detector is later assigned 1053.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 7576597. Configure here.

authLinePat = regexp.MustCompile(`(?im)(?:^|[\n\r])\s*(?:@[^:\s]+:)?(?:\/\/[^\s]+\/:)?_auth\s*=\s*([A-Za-z0-9+/=_-]{16,})`)

// NPM token shapes we can actively verify via whoami endpoint.
verifyableTokenPat = regexp.MustCompile(`^(?:npm_[A-Za-z0-9]{36}|[0-9A-Fa-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})$`)

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.

UUID regex inconsistently allows uppercase hex digits

Low Severity

verifyableTokenPat allows uppercase hex [0-9A-Fa-f] in the first 8-char UUID group but only lowercase [0-9a-f] in the remaining four groups. A valid UUID-style npm token with uppercase hex characters after the first segment (e.g. 1234abcd-ABCD-...) won't match, causing the detector to skip verification for an otherwise verifiable token.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 7576597. Configure here.

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