Skip to content

Add Mailgun Webhook Token detector#5024

Open
asivaprasad09 wants to merge 1 commit into
trufflesecurity:mainfrom
asivaprasad09:add-mailgun-webhook-token-detector
Open

Add Mailgun Webhook Token detector#5024
asivaprasad09 wants to merge 1 commit into
trufflesecurity:mainfrom
asivaprasad09:add-mailgun-webhook-token-detector

Conversation

@asivaprasad09

@asivaprasad09 asivaprasad09 commented Jun 8, 2026

Copy link
Copy Markdown

Summary

This PR adds a detector for Mailgun webhook signing tokens used to verify webhook payload signatures.

Key features:

  • Detects 32-character hexadecimal tokens (case-insensitive)
  • Requires "mailgun" keyword in nearby context to reduce false positives
  • Implements CustomFalsePositiveChecker interface for additional validation
  • Non-verifying detector (webhook tokens cannot be verified via API)
  • Includes comprehensive test coverage

Changes

  • Added MailgunWebhookToken (ID 1053) to proto/detector_type.proto
  • Created detector implementation at pkg/detectors/mailgunwebhooktoken/
  • Integrated detector into default detector list in pkg/engine/defaults/defaults.go
  • Updated proto-generated files with new detector type
  • Added comprehensive unit tests with 100% pass rate

Pattern Details

The detector uses a context-aware regex pattern:

mailgun.*\b([a-fA-F0-9]{32})(?:['"|\n\r\s\x60;]|$)

This requires "mailgun" to appear before the token to avoid false positives from generic 32-character hex strings commonly found in examples and test fixtures.

Testing

All tests pass successfully:

go test ./pkg/detectors/mailgunwebhooktoken -tags=detectors -v

Test coverage includes:

  • Valid pattern detection in multiple contexts (env vars, assignments, config files)
  • Case-insensitive hex matching (both uppercase and lowercase)
  • Multiple tokens in the same file
  • Deduplication of repeated tokens
  • Rejection of invalid patterns (wrong length, non-hex characters, missing context)
  • Proper detector type and keyword registration

Design Rationale

Why context-aware matching?
Mailgun webhook tokens are 32-character hex strings, a format shared by many other types of secrets (MD5 hashes, other webhook tokens, UUIDs without hyphens). Requiring "mailgun" in nearby context significantly reduces false positives while maintaining high recall for actual Mailgun tokens.

Why no verification?
Webhook signing tokens are used to verify HMAC signatures of incoming webhook payloads. They cannot be verified independently via an API call - they only prove valid when used to verify an actual webhook signature with the corresponding message body and timestamp. Therefore, this detector does not implement verification.

SecretParts Population

The detector properly populates SecretParts with:

SecretParts: map[string]string{"token": token}

And includes a rotation guide in ExtraData:

ExtraData: map[string]string{
    "rotation_guide": "https://help.mailgun.com/hc/en-us/articles/360018328934-How-can-I-verify-webhooks",
}

🤖 Generated with Claude Code


Note

Low Risk
Additive detector-only change with no auth or engine behavior changes beyond one more default scanner; main risk is extra findings or false positives on generic 32-hex strings near "mailgun".

Overview
Adds Mailgun webhook signing token detection as a new detector type (MailgunWebhookToken, ID 1053), separate from the existing Mailgun API key detector.

The scanner matches 32-character hex strings only when mailgun appears in nearby context (PrefixRegex), deduplicates hits, and emits results with SecretParts, a Mailgun rotation guide link, and no API verification (signing keys are not verifiable out of band). It also implements CustomFalsePositiveChecker via the shared default false-positive list.

Wiring includes registering the scanner in default detectors, extending detector_type.proto and generated protobuf enums, plus unit tests for pattern matching, keywords, and type registration.

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

This commit adds a detector for Mailgun webhook signing tokens:
- Detects 32-character hexadecimal tokens with "mailgun" context requirement
- Uses context-aware regex to reduce false positives from generic webhook examples
- Implements CustomFalsePositiveChecker interface for additional validation
- Includes comprehensive test coverage for pattern matching and edge cases

The detector adds MailgunWebhookToken (ID 1053) to the detector type enum and
follows TruffleHog's best practices for secret detection.

Key features:
- Case-insensitive hex pattern matching
- Requires "mailgun" keyword in nearby context
- Deduplication of repeated tokens
- Proper SecretParts population
- Rotation guide in ExtraData

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@asivaprasad09 asivaprasad09 requested a review from a team June 8, 2026 09:14
@asivaprasad09 asivaprasad09 requested review from a team as code owners June 8, 2026 09:14

@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 c3e3f96. Configure here.


func (s Scanner) Keywords() []string {
return []string{"mailgun", "webhook", "signing"}
}

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.

Overly broad keywords cause unnecessary detector invocations

Medium Severity

Keywords() returns ["mailgun", "webhook", "signing"] but the regex (via PrefixRegex) requires "mailgun" to be present in the data for any match. The keywords "webhook" and "signing" are extremely common words that will trigger this detector on many irrelevant chunks where no "mailgun" context exists, causing unnecessary regex processing that can never produce results. Only "mailgun" is needed as a keyword.

Additional Locations (1)
Fix in Cursor Fix in Web

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

1 participant