Nonce
A nonce is a value used only once in a given context, often a random number or a timestamp, generated fresh each time it is needed. It helps ensure that a message or request cannot be successfully reused by an attacker who captured it earlier. The name comes from the phrase "number used once."
A nonce is a time-varying or random value with an acceptably small probability of repeating within its scope of use, generated anew for each use. Common implementations include randomly generated values, timestamps, or monotonic counters. Nonces are used in cryptographic protocols to provide uniqueness or freshness—for example, to help mitigate replay attacks or to bind a request to a specific session. In web contexts, a cryptographic nonce may also be applied via mechanisms such as Content Security Policy to authorize specific inline content. The security value of a nonce depends on its unpredictability or uniqueness properties as required by the specific protocol; a poorly generated or reused nonce can undermine the guarantee it is intended to provide.
Why it matters
Replay attacks are a persistent threat in payment and authentication systems: an attacker who captures a valid message or request may attempt to resubmit it to gain unauthorized access or repeat a transaction. A nonce helps mitigate this class of attack by ensuring that each message or request carries a value that should only be accepted once, so a captured message loses its validity if replayed. This freshness property is a foundational building block in many cryptographic protocols rather than a standalone control.
The protection a nonce provides depends entirely on how it is implemented. A nonce that is predictable, reused, or generated with insufficient randomness can undermine the very guarantee it is intended to deliver, and in some protocols nonce reuse can weaken or break the underlying cryptography. For this reason, engineers treat nonce generation and validation as security-sensitive operations, not incidental details. A nonce should be understood as a mechanism that helps reduce specific risks such as replay, not as something that prevents fraud or eliminates attacks on its own.
In web contexts, cryptographic nonces also appear in defenses such as Content Security Policy, where a nonce may be used to authorize specific inline content. This illustrates that the same core concept serves different purposes across different layers, and that the security value in each case rests on the uniqueness or unpredictability properties required by the particular protocol.
Who it's relevant to
Inside Nonce
Common questions
Answers to the questions practitioners most commonly ask about Nonce.