Interface IWebhookReplayStore
- Namespace
- FlowOrchestrator.Core.Storage
- Assembly
- FlowOrchestrator.Core.dll
Persistence contract for webhook replay-attack protection. Maintains a set
of (flowId, triggerKey, nonce) tuples with expiry; a successful
registration means the nonce has not been seen before, a conflict means a
replay attack is in progress.
public interface IWebhookReplayStore
Remarks
Storage-neutral by design — in-memory, Sql Server, and PostgreSQL impls ship in their respective projects. Pick the backend that matches your deployment topology: in-memory for single-replica, Sql/Postgres for multi-replica coordination.
Methods
PurgeExpiredAsync(DateTimeOffset, CancellationToken)
Drops every entry whose ExpiresAt is at or before now.
ValueTask<int> PurgeExpiredAsync(DateTimeOffset now, CancellationToken ct = default)
Parameters
nowDateTimeOffsetReference instant; entries with
ExpiresAt <= noware removed.ctCancellationTokenCancellation token.
Returns
TryForgetAsync(Guid, string, string, Guid, CancellationToken)
Removes the entry for (flowId, triggerKey, nonce) only if it is still owned by
registrationId — the compensation for a delivery that passed replay protection and then
failed before its run was started, so the publisher's retry is not answered as a replay.
ValueTask<bool> TryForgetAsync(Guid flowId, string triggerKey, string nonce, Guid registrationId, CancellationToken ct = default)
Parameters
flowIdGuidFlow identifier the entry was registered under.
triggerKeystringTrigger key the entry was registered under.
noncestringThe nonce exactly as passed to TryRegisterAsync(Guid, string, string, DateTimeOffset, Guid, CancellationToken).
registrationIdGuidThe owner token the entry was registered with.
ctCancellationTokenCancellation token; callers on a failure path pass None.
Returns
- ValueTask<bool>
true when this call removed the entry; false when no entry exists or it is owned by another registration (including any entry recorded without a known owner).
Remarks
The owner match is what keeps this from opening a replay window: a replayer's own registration fails (the entry already exists), so it never holds the token of the entry that blocks it. There is deliberately no default implementation — a silent no-op would bring back the lost-retry bug this member exists to fix.
TryRegisterAsync(Guid, string, string, DateTimeOffset, Guid, CancellationToken)
Atomically records the nonce and remembers registrationId as the owner of the entry.
Returns true when the nonce had not been seen for this flow + trigger;
false when the same tuple is already present (replay) — the existing entry, and its
owner, are left untouched.
ValueTask<bool> TryRegisterAsync(Guid flowId, string triggerKey, string nonce, DateTimeOffset expiresAt, Guid registrationId, CancellationToken ct = default)
Parameters
flowIdGuidFlow identifier scoping the dedup window.
triggerKeystringTrigger key scoping the dedup window.
noncestringUnique-per-event token (timestamp + delivery-id, etc.).
expiresAtDateTimeOffsetWhen the entry may be purged.
registrationIdGuidSecret per-request owner token. Only a caller holding it can release the entry again (TryForgetAsync(Guid, string, string, Guid, CancellationToken)). Generated by the caller with NewGuid(); never derived from request data.
ctCancellationTokenCancellation propagated from the host pipeline.
Returns
Remarks
Implementations bound nonce with ToStorageForm(string),
exactly as the five-argument overload does.
TryRegisterAsync(Guid, string, string, DateTimeOffset, CancellationToken)
Atomically records the nonce under a fresh, unrevealed registration id. Returns true when the nonce had not been seen for this flow + trigger; false when the same tuple is already present (replay).
ValueTask<bool> TryRegisterAsync(Guid flowId, string triggerKey, string nonce, DateTimeOffset expiresAt, CancellationToken ct = default)
Parameters
flowIdGuidFlow identifier scoping the dedup window.
triggerKeystringTrigger key scoping the dedup window.
noncestringUnique-per-event token (timestamp + delivery-id, etc.).
expiresAtDateTimeOffsetWhen the entry may be purged.
ctCancellationTokenCancellation propagated from the host pipeline.
Returns
Remarks
Delegates to the overload that takes a registration id, with a new Guid nobody keeps, so an entry recorded this way can never be released by TryForgetAsync(Guid, string, string, Guid, CancellationToken).