Skip to content

[INS-399] Added Bitbucket data center(on prem) PAT detector#4883

Merged
MuneebUllahKhan222 merged 4 commits intotrufflesecurity:mainfrom
MuneebUllahKhan222:bitbucketdatacenter-detector
Apr 17, 2026
Merged

[INS-399] Added Bitbucket data center(on prem) PAT detector#4883
MuneebUllahKhan222 merged 4 commits intotrufflesecurity:mainfrom
MuneebUllahKhan222:bitbucketdatacenter-detector

Conversation

@MuneebUllahKhan222
Copy link
Copy Markdown
Contributor

@MuneebUllahKhan222 MuneebUllahKhan222 commented Apr 13, 2026

Description

This PR adds the Bitbucket Data Center Personal Access Token (PAT) Detector for TruffleHog.
It scans for Bitbucket Data Center (on-prem) personal access tokens (prefix BBDC-) and optionally verifies them against the
On-prem Bitbucket REST API.

Regex: \b(BBDC-[A-Za-z0-9+/@_-]{40,50})\b

In addition to detecting tokens, the detector attempts to extract associated Bitbucket endpoints from nearby context (e.g., URLs containing atlassian or bitbucket) to enable accurate verification and also allows the user to configure the verification endpoint.


Verification

For verification, we use the Bitbucket Data Center REST API:

GET /rest/api/1.0/projects?limit=1

A request is sent to the detected Bitbucket base URL with the token in the header:

Authorization: Bearer <token>
Accept: application/json
  • 200 OK → token is valid
  • 401 Unauthorized → token is invalid or revoked
  • Other responses → treated as verification errors

This endpoint is part of the standard Bitbucket Data Center API and is read-only, making it safe for verification. It does not perform any destructive actions and only attempts to fetch a minimal list of projects.

Corpora Test

The detector does not appear in the list.
image

Checklist:

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

Note

Medium Risk
Introduces a new network-verifying detector that may change scanning behavior via endpoint extraction and outbound HTTP requests, though it is isolated to a new detector and covered by tests.

Overview
Adds a new bitbucketdatacenter detector that identifies BBDC--prefixed Bitbucket Data Center PATs, associates them with nearby Bitbucket/Atlassian base URLs (or configured endpoints), and emits combined RawV2 results for verification.

When verification is enabled, the detector performs a read-only GET /rest/api/1.0/projects?limit=1 request with Authorization: Bearer <token> and marks results verified on 200, unverified on 401, and records other statuses/errors as verification errors; comprehensive unit tests cover pattern matching, endpoint handling, and verification outcomes/timeouts.

Extends the detector type enum by adding DetectorType_BitbucketDataCenter to detector_type.proto (and regenerated detector_type.pb.go).

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

@MuneebUllahKhan222 MuneebUllahKhan222 requested a review from a team April 13, 2026 11:30
@MuneebUllahKhan222 MuneebUllahKhan222 requested review from a team as code owners April 13, 2026 11:30
@MuneebUllahKhan222 MuneebUllahKhan222 changed the title Added Bitbucket data center(on prem) PAT detector [INS-399] Added Bitbucket data center(on prem) PAT detector Apr 13, 2026
Comment thread pkg/detectors/bitbucketdatacenter/bitbucketdatacenter.go Outdated
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

Reviewed by Cursor Bugbot for commit 1ab3d98. Configure here.

Comment thread pkg/detectors/bitbucketdatacenter/bitbucketdatacenter.go Outdated
// Bitbucket pat start with BBDC- prefix
// and are usually between the length of 40-50 character
// consisting of both alphanumeric and some special character like +, _, @ and etc
userPat = regexp.MustCompile(`\b(BBDC-[A-Za-z0-9+/@_-]{40,50})(?:[^A-Za-z0-9+/@_-]|$)`)
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.

Are we sure that the length is variable? I'm asking because for JIra the length was fixed.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I generated 10 tokens and they all had a fixed length of 44 but I have added a little relaxation in-case their is a little bit of variation in different versions of on-prem tokens.
Also the bitbucket token has a BBDC- prefix so we can get away with making the regex a bit loose.

Comment thread proto/detector_type.proto Outdated
Comment thread pkg/detectors/bitbucketdatacenter/bitbucketdatacenter.go Outdated
Copy link
Copy Markdown
Contributor

@mustansir14 mustansir14 left a comment

Choose a reason for hiding this comment

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

Approving to unblock, but it would be great if you could incorporate those comments.

@MuneebUllahKhan222 MuneebUllahKhan222 merged commit 0112444 into trufflesecurity:main Apr 17, 2026
14 checks passed
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.

3 participants