fix: reject idempotency key reuse with mismatched payload#596
Open
Ope4196 wants to merge 1 commit into
Open
Conversation
|
@Ope4196 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.
PR: Structured rejection of idempotency key reuse with mismatched payload
Summary
Fixes a silent bug where
idempotencyMiddlewarereturned a cached response even when the new request body differed from the original. The middleware now computes a canonical SHA-256 payload fingerprint and returns409 Conflictwith error codeIDEMPOTENCY_KEY_REUSE_MISMATCHwhen fingerprints differ, along with aconflictingSummarythat helps clients diagnose the mismatch without exposing stored sensitive values.Changes
Modified files
src/middleware/idempotency.tsIDEMPOTENCY_KEY_REUSE_MISMATCHconstant (replaces inline'IDEMPOTENCY_CONFLICT'string)conflictingSummarywithidempotencyKey,incomingPayloadFingerprint,storedPayloadFingerprint, andincomingFields(sorted top-level key names only — no values leaked)src/middleware/idempotency.test.tsmakeDb/makeReq/makeReshelperscalculateRequestHashIdempotency-Keyrejection when client reuses a key with a different payload #427 acceptance criteria)Acceptance criteria
returns 409 with IDEMPOTENCY_KEY_REUSE_MISMATCH when payload differsIDEMPOTENCY_KEY_REUSE_MISMATCHexpect(code).toBe(IDEMPOTENCY_KEY_REUSE_MISMATCH)same payload with different key order still matchesproduces the same hash regardless of key order,same payload with different key order still matchesdoes NOT leak stored valuesconflictingSummaryfields presentresponse includes conflictingSummary...IDEMPOTENCY_IN_PROGRESS when hash matches but status is startedSecurity
conflictingSummaryexposes only SHA-256 fingerprints and sorted field names — never stored field valuescloses #427