Replay defense and fencing

A valid signed observation can still be unsafe if an attacker replays it after the state has changed. Replay protection binds producer identity, nonce and monotonic sequence to durable admission state.

Acceptance rule

ReplayGuard.observe(producer_id, nonce, sequence) accepts only when the producer and nonce are non-empty, the sequence is non-negative, the nonce has not been seen for that producer, and the sequence is greater than the last accepted sequence.

accept ⇔ nonce ∉ seen(producer)
      ∧ sequence > last_sequence(producer)
      ∧ durable update succeeds

Local durable guard

guard = ReplayGuard("state/replay.json")
adapter = MappingEvidenceAdapter(
    replay_guard=guard,
    require_replay=True,
)
engine = AssuranceEngine(require_replay=True)

The state file is locked, reloaded while locked, updated through a temporary file, flushed and atomically replaced. Invalid durable state causes refusal to continue.

Required record context

FieldPurpose
producer_idSeparate sequence domains for independent producers.
nonceDetect exact-token reuse.
sequenceReject old or reordered observations for the producer.
signaturePrevent an attacker from rewriting replay fields.
trusted timeSupport lease and expiry reasoning beyond sequence order.

Shared coordination

HTTPReplayGuard delegates admission to a shared coordinator for multi-process or multi-node operation. HTTPS is required except for an explicitly enabled loopback fixture. Coordinator failure returns false and preserves diagnostics so the evidence becomes UNKNOWN under strict policy.

Leases and fencing tokens

LeaseStore issues monotonic fencing tokens with expiry. A consumer validates the token against durable state and trusted time so an old worker cannot continue acting after its lease has been replaced.

FailureExpected response
Duplicate nonceReject.
Sequence rollbackReject.
Corrupted replay stateFail closed; investigate durable storage.
Coordinator timeoutReject / UNKNOWN; never accept locally by convenience.
Expired fencing tokenReject the actor’s authority.
Trusted time unavailableDo not validate a time-bound lease.