Skip to content

fix: webhook secret rotation rejects valid events#1587

Merged
rohilsurana merged 1 commit intomainfrom
fix/webhook-secret-rotation-validation
Apr 30, 2026
Merged

fix: webhook secret rotation rejects valid events#1587
rohilsurana merged 1 commit intomainfrom
fix/webhook-secret-rotation-validation

Conversation

@rohilsurana
Copy link
Copy Markdown
Member

Summary

  • Fix bug in BillingWebhook where valid Stripe webhook events are rejected during secret rotation
  • When multiple StripeWebhookSecrets are configured, if the first secret fails verification but a later one succeeds, the condition len(parseErrs) > 0 incorrectly returns an error
  • Changed to len(parseErrs) == len(secrets) so it only fails when all secrets are exhausted

Test plan

  • Existing core/event tests pass
  • Configure two webhook secrets (old + new), send event signed with the second secret, verify it is accepted
  • Verify events signed with an invalid secret are still rejected

@vercel
Copy link
Copy Markdown

vercel Bot commented Apr 30, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
frontier Ready Ready Preview, Comment Apr 30, 2026 8:21am

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 30, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: b8ca0ab0-1e07-438c-b1c6-2c0ced2312c4

📥 Commits

Reviewing files that changed from the base of the PR and between 629838d and 4153901.

📒 Files selected for processing (1)
  • core/event/service.go

📝 Walkthrough

Summary by CodeRabbit

  • Bug Fixes
    • Enhanced webhook event processing robustness. Previously, webhook events would fail if any single configuration encountered issues. Now, events are successfully processed as long as at least one webhook configuration can handle the request.

Walkthrough

The BillingWebhook function in core/event/service.go now only returns an error when all configured Stripe webhook secrets fail to construct the event, instead of failing whenever any single secret fails during construction, allowing successful event parsing to proceed.

Changes

Cohort / File(s) Summary
Webhook Error Handling Logic
core/event/service.go
Modified error handling in BillingWebhook to only return an error when the count of parse errors equals the total number of configured Stripe webhook secrets, allowing successful parsing by later secrets to succeed despite earlier failures.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

🚥 Pre-merge checks | ✅ 2
✅ Passed checks (2 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
Review rate limit: 0/1 reviews remaining, refill in 60 minutes.

Comment @coderabbitai help to get the list of available commands and usage tips.

…ails

The webhook verification loop collects errors from each secret attempt.
When multiple secrets are configured for rotation, if the first secret
fails but a later one succeeds, the error check `len(parseErrs) > 0`
incorrectly returns an error despite successful verification.

Change condition to only fail when all secrets have been exhausted.
@rohilsurana rohilsurana force-pushed the fix/webhook-secret-rotation-validation branch from 5f25fb0 to 4153901 Compare April 30, 2026 08:20
@rohilsurana rohilsurana marked this pull request as ready for review April 30, 2026 08:21
@coveralls
Copy link
Copy Markdown

coveralls commented Apr 30, 2026

Coverage Report for CI Build 25155145290

Warning

Build has drifted: This PR's base is out of sync with its target branch, so coverage data may include unrelated changes.
Quick fix: rebase this PR. Learn more →

Coverage remained the same at 41.949%

Details

  • Coverage remained the same as the base build.
  • Patch coverage: 1 uncovered change across 1 file (0 of 1 lines covered, 0.0%).
  • No coverage regressions found.

Uncovered Changes

File Changed Covered %
core/event/service.go 1 0 0.0%

Coverage Regressions

No coverage regressions found.


Coverage Stats

Coverage Status
Relevant Lines: 37245
Covered Lines: 15624
Line Coverage: 41.95%
Coverage Strength: 11.88 hits per line

💛 - Coveralls

@rohilsurana rohilsurana enabled auto-merge (squash) April 30, 2026 08:26
@rohilsurana rohilsurana merged commit cfce034 into main Apr 30, 2026
8 checks passed
@rohilsurana rohilsurana deleted the fix/webhook-secret-rotation-validation branch April 30, 2026 08:27
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