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
| Field | Purpose |
|---|---|
producer_id | Separate sequence domains for independent producers. |
nonce | Detect exact-token reuse. |
sequence | Reject old or reordered observations for the producer. |
| signature | Prevent an attacker from rewriting replay fields. |
| trusted time | Support 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.
| Failure | Expected response |
|---|---|
| Duplicate nonce | Reject. |
| Sequence rollback | Reject. |
| Corrupted replay state | Fail closed; investigate durable storage. |
| Coordinator timeout | Reject / UNKNOWN; never accept locally by convenience. |
| Expired fencing token | Reject the actor’s authority. |
| Trusted time unavailable | Do not validate a time-bound lease. |