Skip to content

[INS-351] Added Duffel Token Detector - #4795

Merged
MuneebUllahKhan222 merged 20 commits into
trufflesecurity:mainfrom
MuneebUllahKhan222:duffeltest-detector
Jul 7, 2026
Merged

[INS-351] Added Duffel Token Detector#4795
MuneebUllahKhan222 merged 20 commits into
trufflesecurity:mainfrom
MuneebUllahKhan222:duffeltest-detector

Conversation

@MuneebUllahKhan222

@MuneebUllahKhan222 MuneebUllahKhan222 commented Mar 6, 2026

Copy link
Copy Markdown
Contributor

Description

This PR adds the Duffel API Token Detector for TruffleHog.
It scans for Duffel sandbox API tokens (prefix duffel_test_ or duffel_live_) and optionally verifies them via the Duffel API.

Regex: \b(duffel_(test|live)_[A-Za-z0-9_-]{43})(?:$|[^A-Za-z0-9_-])

Verification

For verification, we use the Duffel Users API: /identity/customer/users?limit=1.
We send a GET request with the token in the Authorization header.

A response code of:

  • 200 OK → token is valid
  • 401 Unauthorized → token is invalid
  • 403 Forbidden → token exists but is revoked or has insufficient permissions

This endpoint is part of the official Duffel API and can be used safely for verification.
It is read-only, does not create or modify resources, and simply confirms whether the provided token is valid.

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

Low Risk
Additive detector behind a feature flag; verification only performs a read-only external API call, matching existing TruffleHog detector patterns.

Overview
Adds a DuffelToken detector that finds duffel_test_ and duffel_live_ API tokens (43-character suffix) and optionally verifies them against Duffel’s read-only GET /identity/customer/users?limit=1 endpoint (Bearer + Duffel-Version: v2).

Wiring follows the usual new-detector path: DetectorType_DuffelToken (1059) in proto, scanner registered in buildDetectorList(), gated by DuffelTokenDetectorEnabled (enabled in main.go), and listed in excludedFromDefaultList for the proto coverage test. Unit, pattern, integration, and benchmark tests are included under pkg/detectors/duffeltoken/.

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

@MuneebUllahKhan222
MuneebUllahKhan222 requested review from a team March 6, 2026 11:36
@MuneebUllahKhan222
MuneebUllahKhan222 requested a review from a team as a code owner March 6, 2026 11:36
Comment thread pkg/detectors/duffeltoken/duffeltoken_test.go
@MuneebUllahKhan222 MuneebUllahKhan222 changed the title Added Duffel Test Token Detector [INS-351] Added Duffel Test Token Detector Mar 6, 2026
Comment thread pkg/detectors/duffeltoken/duffeltoken_test.go Outdated
Comment thread pkg/detectors/duffeltesttoken/duffeltesttoken.go Outdated
Comment thread pkg/detectors/duffeltoken/duffeltoken.go
Comment thread pkg/detectors/duffeltoken/duffeltoken.go
@MuneebUllahKhan222
MuneebUllahKhan222 requested a review from a team April 27, 2026 11:34
Comment thread pkg/detectors/duffeltesttoken/duffeltesttoken.go Outdated
Comment thread pkg/detectors/duffeltoken/duffeltoken.go
Comment thread pkg/detectors/duffeltoken/duffeltoken.go
@MuneebUllahKhan222
MuneebUllahKhan222 requested a review from a team June 29, 2026 13:42
@MuneebUllahKhan222 MuneebUllahKhan222 changed the title [INS-351] Added Duffel Test Token Detector [INS-351] Added Duffel Token Detector Jun 29, 2026
Comment thread pkg/engine/defaults/defaults.go Outdated

@kashifkhan0771 kashifkhan0771 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.

Just two non-blocking comments but I would highly appreciate if we can improve pattern test cases as I mentioned.

Comment on lines +106 to +109
res, err := client.Do(req)
if err != nil {
return false, err
}

@kashifkhan0771 kashifkhan0771 Jul 1, 2026

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.

Non-blocking comment: As now we have a DoWithDedup we can use it in new detectors.
Example:

resp, err := detectors.DoWithDedup(client, detector_typepb.DetectorType_Meraki, match, req)
if err != nil {
  return nil, false, err
}

"github.com/trufflesecurity/trufflehog/v3/pkg/engine/ahocorasick"
)

func TestDuffelTestToken_Pattern(t *testing.T) {

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.

Pattern test cases are one of the most critical parts of any detector, so I'd suggest taking the time to write them thoroughly.

We've already spent a lot of time cleaning up and improving the test cases across existing detectors, and I'd like to avoid creating another backlog of fixes.

For reference, have a look at:

@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 1 potential issue.

Fix All in Cursor

Reviewed by Cursor Bugbot for commit f3c209a. Configure here.

Comment thread pkg/detectors/duffeltoken/duffeltoken_test.go
@MuneebUllahKhan222
MuneebUllahKhan222 merged commit d3b5487 into trufflesecurity:main Jul 7, 2026
16 checks passed
@MuneebUllahKhan222
MuneebUllahKhan222 deleted the duffeltest-detector branch July 7, 2026 06:58
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