Imagine you walk up to an ATM, insert your card, and type your PIN. The ATM sends an encrypted message to the bank approving a $200 withdrawal. An attacker sitting in a van nearby records that encrypted message. They cannot decrypt it — they have no idea what it says. But later that night, they replay that exact encrypted message to the bank's server. The server decrypts it, sees what looks like a legitimate withdrawal request, and approves another $200.
This is a replay attack. The attacker never broke the encryption. They never stole your card or PIN. They simply recorded a valid encrypted message and sent it again. The cryptography worked perfectly, and the system was still compromised.
What Is a Replay Attack
A replay attack is a network attack in which an attacker intercepts and stores a legitimate message, then resends it later to produce an unauthorized effect. The attacker does not need to decrypt the message, modify it, or even understand its contents. The encrypted message is a black box — but a black box that the receiving system trusts.
Replay attacks are a category of attack on protocol design, not on cryptographic algorithms. The encryption itself is sound. The vulnerability is that the protocol does not distinguish between a fresh message and a copy of an old one. This distinction is the entire problem of replay prevention: how does a receiver know that a message is new?
### Replay vs. Other Network Attacks
| Attack Type | What the Attacker Does | Encryption Helps? | | --- | --- | --- | | Replay | Records and resends a valid message | No — the message is still validly encrypted | | Man-in-the-middle | Intercepts, reads, and modifies messages in real time | Yes — TLS prevents this | | Relay | Forwards authentication data to a real server in real time | Partially — protocols like WebAuthn add origin binding | | Reflection | Sends a challenge back to the initiator | Yes — direction-specific keys prevent this |
The key insight is that replay attacks exploit the absence of freshness, not weak encryption. You can have perfect encryption with AES-256-GCM and still be vulnerable to replay if your protocol does not include a freshness mechanism.
How a Replay Attack Works
A replay attack has four phases:
**Phase 1: Capture.** The attacker positions themselves to record network traffic. This could be a compromised router, a Wi-Fi pineapple, a malicious ISP, or a compromised certificate authority. They record encrypted messages passing between the client and server.
**Phase 2: Wait.** The attacker holds the captured message. This could be seconds, minutes, hours, or years. The message remains valid as long as the encryption keys have not changed.
**Phase 3: Replay.** The attacker sends the exact captured message to the server. The message is properly encrypted, properly formatted, and passes all integrity checks. The server has no way to know it is a copy.
**Phase 4: Effect.** The server processes the message as if it were new. If the message was a bank transfer, money moves. If it was an authentication token, the attacker gains access. If it was a command to open a door, the door opens.
### A Concrete Example: API Token Replay
Consider an API that uses bearer tokens for authentication. A client sends:
``` GET /api/transfer?to=account123&amount=500 Authorization: Bearer eyJhbGciOi... ```
An attacker records this request. The token is encrypted and signed — the attacker cannot read it or modify it. But they can resend the exact same request. If the API does not check for request freshness, the transfer executes again.
This is why token-based authentication systems must include replay protections like nonce tracking, short token lifetimes, or one-time-use tokens for sensitive operations.
Why Encryption Alone Does Not Stop Replay
This is the most counterintuitive part of replay attacks. You encrypted your message with AES-256. You authenticated it with HMAC. You used TLS 1.3 for transport. And the replay attack still works.
Encryption provides confidentiality — the attacker cannot read your message. Authentication provides integrity — the attacker cannot modify your message. Neither provides freshness — the ability to distinguish a new message from an old one.
Freshness requires additional mechanisms beyond encryption and authentication. These mechanisms fall into three categories: nonces, timestamps, and sequence numbers.
Cryptographic Defenses Against Replay
### Defense 1: Nonces (Number Used Once)
A nonce is a random value generated for each message. The sender includes the nonce in the encrypted message, and the receiver tracks which nonces it has already seen. If a message arrives with a previously seen nonce, it is rejected as a replay.
AES-GCM, the encryption mode used by NovelCrypt's AES text encryptor and self-destructing message system, relies on nonces for its security. Each encryption operation generates a unique 96-bit nonce. If the same nonce is ever reused with the same key, GCM's authentication tag reveals the duplication, and the decrypted message is rejected.
This is why AES-GCM is specifically resistant to replay attacks at the cryptographic level. The nonce is not just a best practice — it is a mathematical requirement. Reusing a nonce with the same key in GCM mode is a catastrophic security failure that exposes both the plaintext and the authentication key.
| Nonce Type | Size | Reuse Risk | Used By | | --- | --- | --- | --- | | Random nonce | 96 bits | Negligible (birthday bound: 2^48 messages) | AES-GCM, TLS 1.3 | | Counter nonce | 96 bits | None if counter is monotonic | IPSec, some TLS implementations | | Hybrid (counter + random) | 192 bits | Practically zero | ChaCha20-Poly1305 in some modes |
### Defense 2: Timestamps
The sender includes the current time in the message. The receiver checks that the timestamp is within an acceptable window — typically 5 minutes for financial transactions, 30 seconds for authentication protocols. Messages with timestamps outside the window are rejected.
Timestamps require synchronized clocks between sender and receiver. If the clocks drift by more than the acceptance window, legitimate messages will be rejected. This is why protocols like Kerberos include time synchronization as part of their design.
The weakness of timestamps is the window. During the acceptance window, a replay attack can still succeed. This is why timestamps are usually combined with nonces or sequence numbers for sensitive operations.
### Defense 3: Sequence Numbers
Each message includes a monotonically increasing sequence number. The receiver tracks the highest sequence number it has seen and rejects any message with a lower or equal number.
Sequence numbers are simple and effective but require state. The receiver must remember the last sequence number, which means the protocol is stateful. This is acceptable for established connections (like TCP or TLS sessions) but problematic for stateless protocols like HTTP.
| Mechanism | State Required | Clock Sync Required | Replay Window | Complexity | | --- | --- | --- | --- | --- | | Nonces | Yes (track seen nonces) | No | None | Medium | | Timestamps | No | Yes | Equal to window size | Low | | Sequence numbers | Yes (track last number) | No | None | Low | | Nonce + Timestamp | Yes | Yes | None | Medium-high |
How Real Protocols Prevent Replay
### TLS 1.3
TLS 1.3 uses sequence numbers for record-layer protection. Each record in a TLS session has an implicit sequence number that is included in the authenticated encryption. A replayed record will have the wrong sequence number and fail authentication.
TLS 1.3's 0-RTT (zero round-trip time) mode is an exception. 0-RTT data is sent before the handshake completes, which means anti-replay protections are not yet in place. The TLS 1.3 specification explicitly warns that 0-RTT data is vulnerable to replay attacks and must only be used for idempotent operations. This is a real, documented vulnerability — not a theoretical one.
### AES-GCM (Used by NovelCrypt)
NovelCrypt's encryption tools use AES-256-GCM, which provides built-in replay protection through its nonce requirement. Every encryption call generates a fresh, unique nonce. If an attacker replays an encrypted message, the nonce will have already been used, and the GCM authentication tag will not validate.
For self-destructing messages, this means an attacker who captures the encrypted message link cannot simply replay the decryption request. The nonce-based authentication ensures that each encrypted payload is unique and cannot be duplicated.
### SSH
SSH uses sequence numbers in its binary packet protocol. Each packet includes a 32-bit sequence number that increments with every packet sent. The MAC (message authentication code) covers the sequence number, so a replayed packet will have a stale sequence number and fail MAC verification.
### API Authentication
APIs use several replay prevention mechanisms:
- **JWT expiry timestamps:** Tokens include an `exp` claim that limits their lifetime. Read our guide to token-based authentication for details. - **Request signing with nonces:** Each API request includes a unique nonce that the server tracks. Popular in payment APIs like Stripe. - **HMAC with timestamps:** The client signs the request including a timestamp. The server rejects requests older than a threshold. Try this with the HMAC generator.
Replay Attacks on Self-Destructing Messages
Self-destructing messages have a unique replay risk. If an attacker captures the encrypted message before it self-destructs, they could theoretically replay the decryption request later. NovelCrypt prevents this through several mechanisms:
1. **One-time access:** Each message can only be viewed once. After decryption, the encrypted payload is deleted from the server. A replay attempt would find no data to decrypt.
2. **AES-GCM nonce protection:** Even if the encrypted payload were somehow preserved, the GCM nonce prevents duplicate decryption. Read more in our AES-256-GCM explainer.
3. **Server-side deletion:** The encrypted message is stored server-side only until first access. This is why self-destructing messages are safer than regular encrypted email for one-time sensitive communication. For a comparison with other secure messaging approaches, read our analysis of whether Privnote is safe.
Detecting Replay Attacks
Replay attacks are difficult to detect because the replayed message is valid — it was legitimately created. Detection relies on anomaly patterns:
- **Duplicate nonces or sequence numbers:** The most reliable signal. If your system tracks nonces, a duplicate is a definitive replay attempt. - **Impossible timing:** If a message has a timestamp from 2 hours ago but arrives now, and the acceptance window is 5 minutes, it is a replay. - **Duplicate actions:** If a bank sees two identical transfer requests with the same parameters within seconds, one may be a replay. - **Out-of-order sequence numbers:** A message with sequence number 50 arriving after sequence number 100 is suspicious.
A Replay Attack Prevention Checklist
If you are designing a protocol or API, verify these protections:
1. **Does every message include a freshness mechanism?** Nonce, timestamp, or sequence number — at least one. 2. **Can the receiver detect duplicate freshness values?** Tracking nonces or sequence numbers requires server-side state. Ensure your system can store and check them. 3. **Is the freshness value covered by authentication?** If an attacker can modify the nonce, they can replay with a new nonce. The nonce must be inside the authenticated envelope. 4. **Are sensitive operations idempotent or one-time-use?** A bank transfer should be one-time-use. A status query can be idempotent. 5. **Is the replay window as small as possible?** If using timestamps, minimize the acceptance window while accounting for clock drift. 6. **Are encryption nonces generated correctly?** For AES-GCM, use a cryptographically secure random number generator. Never reuse a nonce with the same key. Use the encryption key generator to create strong keys.
The Bottom Line
Replay attacks exploit the absence of freshness, not weak encryption. A perfectly encrypted message can be replayed if the protocol does not distinguish new messages from copies. The three defenses — nonces, timestamps, and sequence numbers — each add freshness in different ways, and real protocols combine them. AES-GCM's nonce requirement provides cryptographic replay protection, which is why it is the encryption mode used in TLS 1.3, IPSec, and NovelCrypt's own encryption tools. If you are building a system that handles authentication, payments, or commands, replay protection is not optional — it is as fundamental as the encryption itself.