fix(rest/nodejs): scope idempotency hashes to checkout operations - #171
Open
XiaolongZhang-TT wants to merge 1 commit into
Open
Conversation
The Node.js sample keyed idempotency records only by the Idempotency-Key header and fingerprinted the request body alone, so the same key reused against a different checkout (or a different operation) replayed the first response instead of conflicting. This was most severe for cancel, whose hash was always the empty body, so any two cancels sharing a key were treated as identical regardless of target. Include the operation and, for update/complete/cancel, the target checkout id in the fingerprint — mirroring the Python sample (Universal-Commerce-Protocol#166). Add regression tests showing a shared key across two checkouts (cancel and update) now returns 409 instead of replaying.
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.
Description
The Node.js sample keyed idempotency records only by the
Idempotency-Keyheader and fingerprinted the request body alone, so the same key reused against a different checkout (or a different operation) replayed the first response instead of conflicting. This was most severe forcancel, whose hash was always the empty body, so any two cancels sharing a key were treated as identical regardless of target.Repro: create two checkouts A and B, then cancel both with the same
Idempotency-Key→ the second cancel returns 200 with A's canceled checkout (silent replay) instead of conflicting.Root cause —
rest/nodejs/src/api/checkout.ts,computeHash(data): the fingerprint was the body only (cancel:{}), with no operation or target checkout.Fix: include the operation and, for
update/complete/cancel, the target checkout id in the fingerprint —computeHash(operation, data, resourceId?). This mirrors the Python sample (#166):createis keyed by body,update/complete/canceladditionally by the path checkout id, so a key can neither cross checkouts nor cross operations.Category (Required)
Related Issues
None — parity with the Python sample's idempotency scoping landed in #166.
Checklist
!for breaking changes).tsc --noEmitclean;prettierclean.)an idempotency key is scoped to the checkout (cancel)and…(update)— both fail before the fix, pass after.)Screenshots / Logs (if applicable)
Before/after — reusing one
Idempotency-Keyagainst two different checkouts:Before (bug):
After (fix):
Full Node.js suite: