Add Stripe webhook signing secret detector#4920
Add Stripe webhook signing secret detector#4920tanishq-sf wants to merge 1 commit intotrufflesecurity:mainfrom
Conversation
|
Linked to #4711 (the originating feature request from @patcain-34). This PR implements the regex they proposed, with the base64-style char class collapsed to a single |
|
Hi @tanishq-sf, Currently, all our webhook-related detectors include a verification step to check whether the webhook is active. Could you please add similar verification logic to this Stripe webhook detector as well? |
Adding to this, here are some helpful resources: |
|
Thanks @MuneebUllahKhan222 and @shahzadhaider1 for the review! I looked into adding an active-webhook verification step, but Stripe Stripe exposes no API that accepts a
So a |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Reviewed by Cursor Bugbot for commit 0a62aea. Configure here.
Adds a pattern-only detector for Stripe webhook signing secrets (whsec_ prefix). These secrets are used to verify the authenticity of webhook events sent from Stripe. Closes trufflesecurity#4711. Regex: \b(whsec_[A-Za-z0-9+/]{32,64}) Uses the standard base64 alphabet [A-Za-z0-9+/] per the Standard Webhooks spec, covering both 32-char and 64-char (and intermediate stripe-cli) shapes. The trailing \b is intentionally omitted because '+' and '/' are non-word characters that would break the boundary. Detection is pattern-only because verifying a Stripe webhook secret requires a signed webhook payload (Stripe-Signature HMAC check), which cannot be synthesized from the secret alone. Stripe exposes no API that accepts whsec_ as a credential: GET /v1/webhook_endpoints authenticates with sk_* keys, and the secret field is only returned at endpoint creation time. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
ab9f363 to
7832668
Compare

Closes #4711
Summary
Adds a pattern-only detector for Stripe webhook signing secrets (
whsec_prefix), as requested in #4711 by @patcain-34.These secrets are used to verify the authenticity of webhook events sent from Stripe. They don't currently have a dedicated detector — existing
stripe(live API keyssk_live/rk_live) andstripepaymentintentdetectors don't cover them.Regex
Matches the format specified in #4711 (
whsec_[A-Za-z0-9+]{32}|whsec_[A-Za-z0-9+]{64}) but collapsed to a single range-quantifier for simplicity.Keyword:
whsec_Detector type:
StripeWebhookSecret = 1048Note: trailing
\bis intentionally omitted because+is a non-word character —\bwould refuse to match when a secret ends with+followed by whitespace/end-of-string. The restrictive char class combined with the{32,64}greedy quantifier is sufficient to delimit matches.Why pattern-only
Verifying a Stripe webhook secret requires a signed webhook payload (the
Stripe-SignatureHMAC check), which cannot be synthesized from the secret alone. There is no authenticated endpoint that accepts the secret as a standalone credential.Files changed
pkg/detectors/stripewebhooksecret/— new detector + testsproto/detector_type.proto— add enum entryStripeWebhookSecret = 1048pkg/pb/detector_typepb/detector_type.pb.go— corresponding enum entriespkg/engine/defaults/defaults.go— register scanner in alphabetical slot betweenstripeandstripepaymentintentTest plan
go test ./pkg/detectors/stripewebhooksecret/passes (4 cases: 32-char base64-style, 64-char with uppercase ++, 63-char stripe-cli-style hex, invalid)go build ./...succeedsstripe listen— detector fires with Detector Type 1048🤖 Generated with Claude Code
Note
Medium Risk
Adds a new detector type and registers it in defaults, which expands scanning behavior and updates the shared
DetectorTypeenum used by downstream consumers. Main risk is unintended false positives/negatives from the newwhsec_regex and any compatibility expectations around protobuf enum changes.Overview
Adds a new pattern-only detector
stripewebhooksecretto flag Stripe webhook signing secrets matchingwhsec_[A-Za-z0-9+/]{32,64}, including deduped matches and unit tests covering valid/invalid formats.Registers the new scanner in
defaults.goso it runs by default, and extends the protobufDetectorTypeenum (and generated Go bindings) withStripeWebhookSecret.Reviewed by Cursor Bugbot for commit 7832668. Bugbot is set up for automated code reviews on this repo. Configure here.