Skip to content

API security

API idempotency keys: prevent duplicate business actions

Test how an API handles retries, concurrent requests and changed payloads under the same idempotency key.

By BugSnaps · Updated

Add BugSnaps as a preferred source on Google(opens in a new tab)

Want more of our security guides? Select BugSnaps and confirm your choice on Google.

Direct answer

An idempotency key helps a service recognize retries of an operation, but the server must define its scope, retention and behavior for changed payloads and concurrent requests. Verify the durable action rather than response status alone.

Define the operation contract

Choose a test-mode order or another reversible action. Record whether keys are scoped by user, endpoint or tenant, how long they are kept, and what the service promises for retries and changed payloads. Exclude real payment and notification systems.

Reference: OWASP Business Logic Security Cheat Sheet.

Test ordinary retries

Submit an approved request with a fresh test key, then repeat the same request using the same key. Confirm that one durable action exists and that the retry follows the documented response contract. A new key should behave according to the operation's business rules.

  • Use synthetic data and a known reset method.
  • Record key identifiers without exposing sensitive request values.
  • Inspect the ledger or object state after each case.

Test mismatch and concurrency

In the sandbox, reuse the same key with a deliberately different harmless payload and compare the result with the documented policy. Under the agreed request budget, send concurrent duplicates and verify that neither causes an additional side effect.

Verify failure recovery

Where safely supported, exercise a failure between receipt and completion. Ensure retry can recover without a lost or duplicate action. After changes, repeat the positive and duplicate cases and document the retention window tested.

Assessment limits

Idempotency semantics are provider-specific and may expire. A controlled retry cannot prove all distributed failure scenarios or substitute for transactional design.

Frequently asked questions

Does the same response mean the action ran once?

Not necessarily. Verify the durable record and external side effects in the test environment.

Can the same key be reused for a different payload?

Follow the API's documented contract; a safe implementation should handle the mismatch deliberately rather than silently performing an unintended action.

Primary sources and further reading

These guides combine published security guidance with practical assessment planning. Adapt checks to the owner's policy, environment, and authorized scope.

This guide was prepared with AI assistance using the linked sources and illustrative examples. Check current vendor guidance and your environment before making changes.

Apply the guide to your own assessment.

Start with an authorized target, known test data, and a clear scope. Use the report's evidence and coverage limits to decide which checks need further review.

Open MyPentest