Skip to content

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

Open
MuneebUllahKhan222 wants to merge 2 commits intotrufflesecurity:mainfrom
MuneebUllahKhan222:bitbucketdatacenter-detector
Open

[INS-399] Added Bitbucket data center(on prem) PAT detector#4883
MuneebUllahKhan222 wants to merge 2 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
Adds a new detector that extracts host URLs from surrounding text and performs outbound verification requests against Bitbucket Data Center instances, which could affect scan behavior and network access. Changes also extend the shared DetectorType enum, requiring downstream compatibility with the new value.

Overview
Adds a new bitbucketdatacenter detector that finds BBDC- personal access tokens, associates them with discovered or configured Bitbucket base URLs, and (optionally) verifies candidates via GET /rest/api/1.0/projects?limit=1 using a bearer token.

Extends detector_type.proto/generated code with a new DetectorType_BitbucketDataCenter enum value and includes unit tests covering token/url matching and verification outcomes (200/401/unexpected status/timeout) using mocked HTTP.

Reviewed by Cursor Bugbot for commit 1ab3d98. 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
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.

// 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+/@_-]|$)`)

urlPat = regexp.MustCompile(detectors.PrefixRegex([]string{"atlassian", "bitbucket"}) + `(https://[a-zA-Z0-9.-]+(?::\d+)?)`)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

URL regex excludes HTTP for on-prem instances

Medium Severity

The urlPat regex hardcodes https:// for URL auto-discovery, but this detector specifically targets Bitbucket Data Center (on-prem) instances, which commonly run over plain http://. Tokens near http:// Bitbucket URLs won't be paired with an endpoint and will be silently dropped (producing zero results even though a valid token was found).

Fix in Cursor Fix in Web

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

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.

Yeah this is something that I would like the opinion of the reviewers on. It does make sense to make it detect http url as-well but idk how secure it is and when it will cause the potential risk of SSRF attacks.

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.

I agree with the bot on this. By not including http URLS, we may miss on potential matches. Regarding the security concern, we have many detectors like Portainer, OpenVPN, HashiCorp Vault, Metabase, LiveAgent etc that support on-prem instances and detect HTTP based URLs too, so I guess it's fine.

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

ArtifactoryReferenceToken = 1042;
DatadogApikey = 1043;
ShopifyOAuth = 1044;
BitbucketDataCenter=1045;
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.

nit: can we have consistent formatting here?

var _ detectors.EndpointCustomizer = (*Scanner)(nil)

var (
defaultClient = detectors.DetectorHttpClientWithNoLocalAddresses
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.

We may want to switch this to detectors.SaneHttpClient if we agree on detecting http URLs.

Copy link
Copy Markdown
Contributor

@mustansir14 mustansir14 Apr 15, 2026

Choose a reason for hiding this comment

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

Update: It seems detectors.DetectorHttpClientWithLocalAddresses is a better option

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.

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