Skip to content

fix(api): gate x402 video quota before settlement - #104

Draft
cursor[bot] wants to merge 2 commits into
mainfrom
cursor/critical-bug-management-5801
Draft

fix(api): gate x402 video quota before settlement#104
cursor[bot] wants to merge 2 commits into
mainfrom
cursor/critical-bug-management-5801

Conversation

@cursor

@cursor cursor Bot commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

Bug and impact

Anonymous x402 callers could pay for video-generate after their hourly video cap was already exhausted. The x402 middleware verified and settled payment before the route-level videoHourlyGate ran, so the handler could return 429 video_rate_limited after the payer had already been charged.

Root cause

toolMiddleware("video-generate") runs x402Middleware before the tool handler. The video hourly cap lived only in the handler, after x402Paid was set post-settlement.

Fix

  • Added a video-generate x402 pre-settlement quota gate after payment verification and before settlement.
  • Releases the reserved video slot if settlement fails.
  • Passes the reserved identity into the route so x402-paid requests are not counted twice.
  • Added focused regression assertions to the hardening audit.

Validation

  • npm run build
  • node tests/hardening-caps-audit.test.mjs
Open in Web View Automation 

cursoragent and others added 2 commits July 30, 2026 05:09
Co-authored-by: Deesmo <Deesmo@users.noreply.github.com>
Co-authored-by: Deesmo <Deesmo@users.noreply.github.com>
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