Skip to content

fix(api): revert deterministic retry billing id (free-scan on redelivery)#3401

Merged
tofikwest merged 1 commit into
mainfrom
fix/pentest-retry-billing-redelivery
Jul 14, 2026
Merged

fix(api): revert deterministic retry billing id (free-scan on redelivery)#3401
tofikwest merged 1 commit into
mainfrom
fix/pentest-retry-billing-redelivery

Conversation

@tofikwest

@tofikwest tofikwest commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

Follow-up to #3400. The deterministic pending:retry:<parent> billing reservation id it introduced has a realistic bug, so this reverts it to a unique random id.

The bug

Billing consumption is idempotent on sourceResourceId, and a refund creates a separate refund event while leaving the original consume event in place (billing-included-usage-refunds.ts). With a deterministic per-parent reservation id:

  1. A retry reserves (debits) pending:retry:<parent>.
  2. The Maced create fails transiently → we refund it (net zero, but the consume idempotency key remains).
  3. Standard webhook redelivery re-runs the retry → reserves the same id → billing sees the existing consume key → returns "consumed" without debiting → the scan runs for free.

This is the normal sequential retry-on-failure path, so it's realistic — a worse trade than the (unverified, concurrent-only) over-charge the deterministic id was meant to prevent.

Fix

Revert to a unique random reservation id per create call, so a redelivered retry re-debits correctly. Concurrent duplicate scans are still deduped by the Maced idempotency key (unchanged); the residual concurrent-only reservation over-charge requires Maced to deliver duplicate webhooks concurrently (unverified) and isn't worth reintroducing a realistic free-scan to close.

Testing

npx jest src/security-penetration-tests → 154 green, typecheck + prettier clean.


Summary by cubic

Reverts the retry billing reservation id to a unique random id to prevent free scans on webhook redelivery after a refunded failure. Concurrent duplicate scans are still deduped by the Maced idempotency key, and billing now re-debits on redelivery.

  • Bug Fixes
    • Always generate a unique pending:<uuid> sourceResourceId; remove pending:retry:<parent>.
    • Avoids idempotency skip when a refund leaves the original consume event in place.
    • Updated tests to expect a non-deterministic billing id while keeping the same Maced idempotency behavior.

Written for commit ba6886c. Summary will update on new commits.

Review in cubic

…redelivery)

The deterministic pending:retry:<parent> reservation id introduced a worse,
realistic bug: billing consume is idempotent on the id AND a refund leaves the
consume event in place, so a failed-create-then-refund followed by the standard
webhook redelivery would reuse the key, skip the debit, and run the scan for
free. Revert to a unique random reservation id so redelivery re-debits
correctly. Concurrent duplicate SCANS are still deduped by the Maced
idempotency key; the residual concurrent-only over-charge requires concurrent
duplicate webhook delivery (unverified) and is not worth the regression risk of
a shared reservation.
@vercel

vercel Bot commented Jul 14, 2026

Copy link
Copy Markdown

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

Project Deployment Actions Updated (UTC)
comp-framework-editor Ready Ready Preview, Comment Jul 14, 2026 2:50am
2 Skipped Deployments
Project Deployment Actions Updated (UTC)
app Skipped Skipped Jul 14, 2026 2:50am
portal Skipped Skipped Jul 14, 2026 2:50am

Request Review

@cubic-dev-ai cubic-dev-ai 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.

All reported issues were addressed across 2 files

Confidence score: 5/5

  • Safe to merge after the addressed issues were fixed.

Reply with feedback, questions, or to request a fix.

Fix all with cubic | Re-trigger cubic

@tofikwest tofikwest merged commit 6033674 into main Jul 14, 2026
11 checks passed
@tofikwest tofikwest deleted the fix/pentest-retry-billing-redelivery branch July 14, 2026 02:55
claudfuen pushed a commit that referenced this pull request Jul 14, 2026
## [3.101.2](v3.101.1...v3.101.2) (2026-07-14)

### Bug Fixes

* **api:** pentest retry follow-ups from production review ([#3400](#3400)) ([e6e9239](e6e9239))
* **api:** revert deterministic retry billing id (caused free-scan on redelivery) ([#3401](#3401)) ([6033674](6033674))
@claudfuen

Copy link
Copy Markdown
Contributor

🎉 This PR is included in version 3.101.2 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants