Repository navigation
fix(billing): reject requestId reuse with a different deduction - #1540
Open
tonysxn-eng wants to merge 1 commit into
Open
tonysxn-eng wants to merge 1 commit into
tonysxn-eng wants to merge 1 commit into
Conversation
|
@tonysxn-eng Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Overview
This PR closes a cross-tenant information leak and false-success reporting on the billing deduction path.
BillingServicepreviously treatedrequestIdas an idempotency key by existence only, so a second deduction reusing the samerequestIdwith a different user, amount, API or endpoint was answered with the first row'susageEventIdandstellarTxHashand reported asalreadyProcessed: true. This change stores a canonical request fingerprint and returns a typed conflict on mismatch, without disclosing the existing row's ids.Related Issue
Changes
🔐 Request Fingerprint and Conflict Detection
[ADD]
migrations/0027_usage_events_request_fingerprint.sqlrequest_fingerprint CHAR(64)tousage_events, holding the SHA-256 of the canonicaluserId|apiId|endpointId|apiKeyId|amountInContractUnitsstring."1.0"and"1.0000000"produce the same fingerprint.[MODIFY]
src/routes/billing/deduct/bulk.tsconflictresult to409 BILLING_REQUEST_ID_CONFLICTin the standard envelope.[MODIFY]
docs/error-codes.yamlBILLING_REQUEST_ID_CONFLICT(409) so the generated error-code artifacts stay in sync.[MODIFY]
docs/openapi.json/api/billing/deductdescribing arequestIdreused for a different deduction.🧪 Tests
src/__tests__/billing-credits.test.tssrc/__tests__/billing-index.test.tssrc/__tests__/billingDeductMetrics.test.tsuser_idonly) and the conflict response shape (nousageEventId/stellarTxHashleaked).Verification Results
runPhase1,23505recovery, and bulk paths all compare the fingerprintnpm run db:check-migrationsandnpm run error-codes:checkpassnpm run lint,npm run typecheck,npm run buildandnpm testpass, and CI is greenbilling.tsFingerprint format
request_fingerprint = SHA-256("userId|apiId|endpointId|apiKeyId|amountInContractUnits")user_idonly and treated as a conflict on mismatch.{ success: false, conflict: true, error: 'requestId already used for a different deduction' }and never includes the other row'susageEventIdorstellarTxHash.Closes #1501