Table of Contents

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

now DateTimeOffset

Reference instant; entries with ExpiresAt <= now are removed.

ct CancellationToken

Cancellation token.

Returns

ValueTask<int>

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

flowId Guid

Flow identifier the entry was registered under.

triggerKey string

Trigger key the entry was registered under.

nonce string

The nonce exactly as passed to TryRegisterAsync(Guid, string, string, DateTimeOffset, Guid, CancellationToken).

registrationId Guid

The owner token the entry was registered with.

ct CancellationToken

Cancellation 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

flowId Guid

Flow identifier scoping the dedup window.

triggerKey string

Trigger key scoping the dedup window.

nonce string

Unique-per-event token (timestamp + delivery-id, etc.).

expiresAt DateTimeOffset

When the entry may be purged.

registrationId Guid

Secret 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.

ct CancellationToken

Cancellation propagated from the host pipeline.

Returns

ValueTask<bool>

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

flowId Guid

Flow identifier scoping the dedup window.

triggerKey string

Trigger key scoping the dedup window.

nonce string

Unique-per-event token (timestamp + delivery-id, etc.).

expiresAt DateTimeOffset

When the entry may be purged.

ct CancellationToken

Cancellation propagated from the host pipeline.

Returns

ValueTask<bool>

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).