Skip to content

feat: add Rancher/Cattle token detector#4874

Open
moeedrehman135 wants to merge 1 commit intotrufflesecurity:mainfrom
moeedrehman135:feat/rancher-token-detector
Open

feat: add Rancher/Cattle token detector#4874
moeedrehman135 wants to merge 1 commit intotrufflesecurity:mainfrom
moeedrehman135:feat/rancher-token-detector

Conversation

@moeedrehman135
Copy link
Copy Markdown

@moeedrehman135 moeedrehman135 commented Apr 8, 2026

Summary

Adds a detector for Rancher/Cattle API tokens as requested in #4622.

Changes

  • New detector in pkg/detectors/rancher/
  • Regex matches CATTLE_TOKEN, RANCHER_TOKEN, CATTLE_BOOTSTRAP_PASSWORD, RANCHER_API_TOKEN patterns
  • Requires server context (CATTLE_SERVER or RANCHER_URL) nearby to reduce false positives
  • HTTP verification against Rancher v3 API
  • Pattern tests included
  • Registered in defaults.go

Testing

All pattern tests pass:

  • Valid token with server context
  • Invalid token (too short)
  • Token without server context (should not detect)

Closes #4622


Note

Medium Risk
Adds a new secret detector with optional outbound HTTP verification and registers a new DetectorType enum value, which can affect scan behavior and proto compatibility across components.

Overview
Adds a new rancher detector that matches Rancher/Cattle API tokens (and bootstrap password) with a required nearby server/URL context to reduce false positives, and optionally verifies candidates via an HTTP request.

Registers the detector in pkg/engine/defaults/defaults.go and introduces DetectorType_Rancher (1045) in the protobuf enum, with accompanying unit tests/benchmarks for the new pattern matching.

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

@moeedrehman135 moeedrehman135 requested a review from a team April 8, 2026 14:42
@moeedrehman135 moeedrehman135 requested review from a team as code owners April 8, 2026 14:42
@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.


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


if verify {
client := common.SaneHttpClient()
req, err := http.NewRequestWithContext(ctx, "GET", "https://rancher.example.com/v3", nil)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Verification sends tokens to hardcoded placeholder URL

High Severity

The verification request is hardcoded to https://rancher.example.com/v3, which is a placeholder domain that will never host a real Rancher API. The serverPattern regex only checks for the presence of a server context but never extracts the actual URL value. As a result, token verification will always fail (tokens are never marked Verified), completely defeating the stated purpose of "HTTP verification against Rancher v3 API." Comparable detectors like Portainer extract the endpoint URL from the scanned data and use it for verification.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 86cc6fa. Configure here.

var (
tokenPattern = regexp.MustCompile(
`(?i)(?:CATTLE_TOKEN|RANCHER_TOKEN|CATTLE_BOOTSTRAP_PASSWORD|RANCHER_API_TOKEN)[^\w]{1,4}([a-z0-9]{54,64})`,
)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Token regex won't match real Rancher token format

High Severity

Real Rancher API tokens use the format token-xxxxx:yyyyyyyyyy (containing hyphens and colons), as documented in Rancher's official API docs. The capture group [a-z0-9]{54,64} only allows lowercase alphanumerics, so it will never match actual CATTLE_TOKEN or RANCHER_TOKEN values. The test data uses a fabricated token (kubeadmin5f8a3b...) that doesn't resemble any real Rancher token format, masking this fundamental mismatch.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 86cc6fa. Configure here.

- Add regex pattern for CATTLE_TOKEN/RANCHER_API_TOKEN format
- Require server context (CATTLE_SERVER/RANCHER_URL) to reduce false positives
- Add HTTP verification against Rancher v3 API
- Add pattern tests
- Register detector in defaults.go

Closes trufflesecurity#4622
@moeedrehman135 moeedrehman135 force-pushed the feat/rancher-token-detector branch from 86cc6fa to 74f5a74 Compare April 8, 2026 15:05
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.

There are 3 total unresolved issues (including 2 from previous reviews).

Fix All in Cursor

Reviewed by Cursor Bugbot for commit 74f5a74. Configure here.

"github.com/trufflesecurity/trufflehog/v3/pkg/pb/detectorspb"
)

type Scanner struct{}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Missing multi-part credential provider causes missed detections

Medium Severity

The Scanner struct doesn't embed detectors.DefaultMultiPartCredentialProvider, even though the detector requires two distinct patterns (server context via serverPattern and secret via tokenPattern) to co-occur in the same data chunk. Without this, the Aho-Corasick span calculator uses its default 512-byte radius, so if the server URL and token are farther apart in the scanned data, the chunk delivered to FromData may lack one of the two patterns, causing valid credentials to be silently missed. All comparable multi-part detectors (e.g., mattermostpersonaltoken, formsite) embed this provider.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 74f5a74. 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.

Rancher Tokens

2 participants