Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
mdn#42367- Added nonce to the glossary (mdn#42389)
  • Loading branch information
laxitajain authored Dec 15, 2025
commit dc788bf0ea36cb1ebe809c82aaae2c77cb3e18c0
24 changes: 24 additions & 0 deletions files/en-us/glossary/nonce/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
title: Nonce
slug: Glossary/Nonce
page-type: glossary-definition
sidebar: glossarysidebar
---

In cryptography and computer security, a **`nonce`** is an arbitrary number that is used **only once** in a cryptographic communication. The term is derived from "number used once" and is commonly employed to prevent replay attacks, ensure message freshness, and add randomness to cryptographic protocols.

Nonces are frequently used in authentication protocols, encryption schemes, hashing, and digital signatures. They may be generated randomly or pseudo-randomly, or derived deterministically, depending on the application and security requirements.

In web security, nonces are commonly used in mechanisms such as **Content Security Policy (CSP)** to allow specific scripts to execute while preventing cross-site scripting (XSS) attacks. In cryptographic protocols like {{Glossary("TLS")}}, nonces help ensure that each session is unique.

## See also

- [Cryptographic nonce](https://en.wikipedia.org/wiki/Cryptographic_nonce) on Wikipedia
- [Content Security Policy (CSP)](/en-US/docs/Web/HTTP/CSP)
- [Replay attack](https://en.wikipedia.org/wiki/Replay_attack) on Wikipedia
- Related glossary terms:
- {{Glossary("cryptography")}}
- {{Glossary("encryption")}}
- {{Glossary("hash")}}
- {{Glossary("TLS")}}
- {{Glossary("authentication")}}
2 changes: 1 addition & 1 deletion files/en-us/glossary/replay_attack/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ sidebar: glossarysidebar

In web security, a _replay attack_ happens when an attacker intercepts a previously-sent message and resends it later to get the same credentials as the original message, potentially with a different payload or instruction.

Replay attacks can be prevented by including a unique, single-use identifier with each message that the receiver can use to verify the authenticity of the transmission. This identifier can take the form of a session token or "number used only once" ("nonce").
Replay attacks can be prevented by including a unique, single-use identifier with each message that the receiver can use to verify the authenticity of the transmission. This identifier can take the form of a session token or "number used only once" ({{Glossary("Nonce", "nonce")}}).

## See also

Expand Down
2 changes: 1 addition & 1 deletion files/en-us/mozilla/firefox/releases/75/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ _No changes._

### Security

- [CSP](/en-US/docs/Web/HTTP/Guides/CSP) nonces from non-script sources, such as CSS selectors, and `.getAttribute("nonce")` calls, are now hidden. Instead, check the [`.nonce`](/en-US/docs/Web/API/HTMLElement/nonce) property to access nonces from scripts ([Firefox bug 1374612](https://bugzil.la/1374612)).
- [CSP](/en-US/docs/Web/HTTP/Guides/CSP) {{Glossary("Nonce", "nonces")}} from non-script sources, such as CSS selectors, and `.getAttribute("nonce")` calls, are now hidden. Instead, check the [`.nonce`](/en-US/docs/Web/API/HTMLElement/nonce) property to access nonces from scripts ([Firefox bug 1374612](https://bugzil.la/1374612)).

### Plugins

Expand Down
2 changes: 1 addition & 1 deletion files/en-us/web/api/aesctrparams/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ A given counter block value must never be used more than once with the same key:

Typically this is achieved by splitting the initial counter block value into two concatenated parts:

- A [nonce](https://en.wikipedia.org/wiki/Cryptographic_nonce) (that is, a number that may only be used once). The nonce part of the block stays the same for every block in the message. Each time a new message is to be encrypted, a new nonce is chosen. Nonces don't have to be secret, but they must not be reused with the same key.
- A {{Glossary("Nonce", "nonce")}} (that is, a number that may only be used once). The nonce part of the block stays the same for every block in the message. Each time a new message is to be encrypted, a new nonce is chosen. Nonces don't have to be secret, but they must not be reused with the same key.
- A counter. This part of the block gets incremented each time a block is encrypted.

Essentially: the nonce should ensure that counter blocks are not reused from one message to the next, while the counter should ensure that counter blocks are not reused within a single message.
Expand Down
2 changes: 1 addition & 1 deletion files/en-us/web/api/fedcm_api/rp_sign-in/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ The `identity.providers` property takes an array containing one or more objects
The previous example also includes some optional features:

- `identity.context` specifies the context in which the user is authenticating with FedCM. For example, is it a first-time signup for this account, or a sign-in with an existing account? The browser uses this information to vary the text in its FedCM UI to better suit the context.
- The `nonce` property provides a random nonce value that ensures the response is issued for this specific request, preventing {{glossary("replay attack", "replay attacks")}}.
- The `nonce` property provides a random {{Glossary("Nonce")}} value that ensures the response is issued for this specific request, preventing {{glossary("replay attack", "replay attacks")}}.
- The `loginHint` property provides a hint about the account option(s) the browser should present for user sign-in. This hint is matched against the `login_hints` values that the IdP provides at the [accounts list endpoint](/en-US/docs/Web/API/FedCM_API/IDP_integration#the_accounts_list_endpoint).

The browser requests the IdP config files and carries out the sign-in flow detailed below. For more information on the kind of interaction a user might expect from the browser-supplied UI, see [Implement an identity solution with FedCM on the Relying Party side](https://developer.chrome.com/docs/identity/fedcm/implement/relying-party).
Expand Down
2 changes: 1 addition & 1 deletion files/en-us/web/api/subtlecrypto/encrypt/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ A given counter block value must never be used more than once with the same key:

Typically this is achieved by splitting the initial counter block value into two concatenated parts:

- A [nonce](https://en.wikipedia.org/wiki/Cryptographic_nonce) (that is, a number that may only be used once). The nonce part of the block stays the same for every block in the message. Each time a new message is to be encrypted, a new nonce is chosen. Nonces don't have to be secret, but they must not be reused with the same key.
- A {{Glossary("Nonce", "nonce")}} (that is, a number that may only be used once). The nonce part of the block stays the same for every block in the message. Each time a new message is to be encrypted, a new nonce is chosen. Nonces don't have to be secret, but they must not be reused with the same key.
- A counter. This part of the block gets incremented each time a block is encrypted.

Essentially: the nonce should ensure that counter blocks are not reused from one message to the next, while the counter should ensure that counter blocks are not reused within a single message.
Expand Down
2 changes: 1 addition & 1 deletion files/en-us/web/api/svgelement/nonce/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ browser-compat: api.SVGElement.nonce

{{APIRef("SVG")}}

The **`nonce`** property of the {{DOMxRef("SVGElement")}} interface returns the nonce that is used by [Content Security Policy](/en-US/docs/Web/HTTP/Guides/CSP) to determine whether a given fetch will be allowed to proceed.
The **`nonce`** property of the {{DOMxRef("SVGElement")}} interface returns the {{Glossary("Nonce", "nonce")}} that is used by [Content Security Policy](/en-US/docs/Web/HTTP/Guides/CSP) to determine whether a given fetch will be allowed to proceed.

## Value

Expand Down
2 changes: 1 addition & 1 deletion files/en-us/web/api/websockets_api/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ Additionally, the [WebTransport API](/en-US/docs/Web/API/WebTransport_API) is ex
The HTTP headers are used in the [WebSocket handshake](/en-US/docs/Web/API/WebSockets_API/Writing_WebSocket_servers#the_websocket_handshake):

- {{HTTPHeader("Sec-WebSocket-Key")}}
- : An HTTP request header that contains a nonce from the client.
- : An HTTP request header that contains a {{Glossary("Nonce", "nonce")}} from the client.
This is used in the [WebSocket opening handshake](/en-US/docs/Web/API/WebSockets_API/Writing_WebSocket_servers#the_websocket_handshake) to verify that the client explicitly intends to open a WebSocket.
It is added automatically by the browser.
- {{HTTPHeader("Sec-WebSocket-Accept")}}
Expand Down
2 changes: 1 addition & 1 deletion files/en-us/web/html/reference/elements/script/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ This element includes the [global attributes](/en-US/docs/Web/HTML/Reference/Glo
- `nomodule`
- : This Boolean attribute is set to indicate that the script should not be executed in browsers that support [ES modules](/en-US/docs/Web/JavaScript/Guide/Modules) — in effect, this can be used to serve fallback scripts to older browsers that do not support modular JavaScript code.
- `nonce`
- : A cryptographic nonce (number used once) to allow scripts in a [script-src Content-Security-Policy](/en-US/docs/Web/HTTP/Reference/Headers/Content-Security-Policy/script-src). The server must generate a unique nonce value each time it transmits a policy. It is critical to provide a nonce that cannot be guessed as bypassing a resource's policy is otherwise trivial.
- : A cryptographic {{Glossary("Nonce", "nonce")}} (number used once) to allow scripts in a [script-src Content-Security-Policy](/en-US/docs/Web/HTTP/Reference/Headers/Content-Security-Policy/script-src). The server must generate a unique nonce value each time it transmits a policy. It is critical to provide a nonce that cannot be guessed as bypassing a resource's policy is otherwise trivial.
- `referrerpolicy`
- : Indicates which [referrer](/en-US/docs/Web/API/Document/referrer) to send when fetching the script, or resources fetched by the script:
- `no-referrer`: The {{HTTPHeader("Referer")}} header will not be sent.
Expand Down
2 changes: 1 addition & 1 deletion files/en-us/web/html/reference/elements/style/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ This element includes the [global attributes](/en-US/docs/Web/HTML/Reference/Glo
- `media`
- : This attribute defines which media the style should be applied to. Its value is a [media query](/en-US/docs/Web/CSS/Guides/Media_queries/Using), which defaults to `all` if the attribute is missing.
- `nonce`
- : A cryptographic nonce (number used once) used to allow inline styles in a [style-src Content-Security-Policy](/en-US/docs/Web/HTTP/Reference/Headers/Content-Security-Policy/style-src). The server must generate a unique nonce value each time it transmits a policy. It is critical to provide a nonce that cannot be guessed as bypassing a resource's policy is otherwise trivial.
- : A cryptographic {{Glossary("Nonce", "nonce")}} (number used once) used to allow inline styles in a [style-src Content-Security-Policy](/en-US/docs/Web/HTTP/Reference/Headers/Content-Security-Policy/style-src). The server must generate a unique nonce value each time it transmits a policy. It is critical to provide a nonce that cannot be guessed as bypassing a resource's policy is otherwise trivial.
- `title`
- : This attribute specifies [alternative style sheet](/en-US/docs/Web/HTML/Reference/Attributes/rel/alternate_stylesheet) sets.

Expand Down
2 changes: 1 addition & 1 deletion files/en-us/web/html/reference/global_attributes/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ In addition to the basic HTML global attributes, the following global attributes
- [`lang`](/en-US/docs/Web/HTML/Reference/Global_attributes/lang)
- : Helps define the language of an element: the language that non-editable elements are in, or the language that editable elements should be written in by the user. The attribute should contain a valid {{glossary("BCP 47 language tag")}}. `xml:lang` has priority over it.
- [`nonce`](/en-US/docs/Web/HTML/Reference/Global_attributes/nonce)
- : A cryptographic nonce ("number used once") which can be used by [Content Security Policy](/en-US/docs/Web/HTTP/Guides/CSP) to determine whether or not a given fetch will be allowed to proceed.
- : A cryptographic {{Glossary("Nonce", "nonce")}} ("number used once") which can be used by [Content Security Policy](/en-US/docs/Web/HTTP/Guides/CSP) to determine whether or not a given fetch will be allowed to proceed.
- [`part`](/en-US/docs/Web/HTML/Reference/Global_attributes/part)
- : A space-separated list of the part names of the element. Part names allows CSS to select and style specific elements in a shadow tree via the {{CSSxRef("::part")}} pseudo-element.
- [`popover`](/en-US/docs/Web/HTML/Reference/Global_attributes/popover)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ sidebar: htmlsidebar
---

The **`nonce`** [global attribute](/en-US/docs/Web/HTML/Reference/Global_attributes)
is a content attribute defining a cryptographic nonce ("number used once") which can be used by
is a content attribute defining a cryptographic {{Glossary("Nonce", "nonce")}} ("number used once") which can be used by
[Content Security Policy](/en-US/docs/Web/HTTP/Guides/CSP) to determine whether or not a given fetch will
be allowed to proceed for a given element.

Expand Down
2 changes: 1 addition & 1 deletion files/en-us/web/http/guides/csp/errors/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ When you see any of the following messages logged in the browser devtools consol
- Ignoring "%1$S" within script-src or style-src: nonce-source or hash-source specified
- Ignoring "%1$S" within script-src: 'strict-dynamic' specified
- Ignoring source "%1$S" (Only supported within script-src).
- Keyword 'strict-dynamic' within "%1$S" with no valid nonce or hash might block all scripts from loading
- Keyword 'strict-dynamic' within "%1$S" with no valid {{Glossary("Nonce", "nonce")}} or hash might block all scripts from loading
- The report URI (%1$S) should be an HTTP or HTTPS URI.
- This site (%1$S) has a Report-Only policy without a report URI. CSP will not block and cannot report violations of this policy.
- Failed to parse unrecognized source %1$S
Expand Down
2 changes: 1 addition & 1 deletion files/en-us/web/http/guides/csp/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ A CSP can provide protection against all of these. With a CSP, you can:

- define the permitted sources for JavaScript files and other resources, effectively blocking loads from `https://evil.example.com`
- disable inline script tags
- allow only script tags which have the correct nonce or hash set
- allow only script tags which have the correct {{Glossary("Nonce", "nonce")}} or hash set
- disable inline event handlers
- disable `javascript:` URLs
- disable dangerous APIs like `eval()`
Expand Down
2 changes: 1 addition & 1 deletion files/en-us/web/http/guides/iframe_credentialless/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ iframeElem.src =
> [!NOTE]
> The {{domxref("window.credentialless")}} property can be queried by a document embedded in an `<iframe>` to test whether it is being run in a credentialless context. A value of `true` means the embedding `<iframe>` is credentialless.

This results in the documents inside the credentialless `<iframe>` being loaded using new, ephemeral contexts — those contexts don't have access to the data associated with their origins; for example [cookies](/en-US/docs/Web/HTTP/Guides/Cookies) and [localStorage](/en-US/docs/Web/API/Window/localStorage). The credentialless storage is partitioned out separately with storage keys modified by a nonce ("number used once") value, set once per top-level document. So a cookie set in one credentialless `<iframe>` will be accessible only from other same-origin credentialless `<iframe>`s embedded below the same top-level document.
This results in the documents inside the credentialless `<iframe>` being loaded using new, ephemeral contexts — those contexts don't have access to the data associated with their origins; for example [cookies](/en-US/docs/Web/HTTP/Guides/Cookies) and [localStorage](/en-US/docs/Web/API/Window/localStorage). The credentialless storage is partitioned out separately with storage keys modified by a {{Glossary("Nonce", "nonce")}} ("number used once") value, set once per top-level document. So a cookie set in one credentialless `<iframe>` will be accessible only from other same-origin credentialless `<iframe>`s embedded below the same top-level document.

The nonce is shared for every credentialless iframe that is a descendant of the same top-level document, but it is different for each distinct top-level document the user navigates to, and no longer accessible once the user has navigated away. Credentialless IFrames do not share storage across different pages. Returning to the cookie mentioned above, reloading the document will load the credentialless `<iframe>`s in a different context, so none of the previously-set cookies will be available.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ The `<host-source>` and `<scheme-source>` formats must be unquoted, and all othe

### 'nonce-\<nonce_value>'

This value consists of the string `nonce-` followed by a nonce value. The nonce value may use any of the characters from [Base64](/en-US/docs/Glossary/Base64#base64_characters) or [URL-safe Base64](/en-US/docs/Glossary/Base64#url_and_filename_safe_base64).
This value consists of the string `nonce-` followed by a {{Glossary("Nonce", "nonce")}} value. The nonce value may use any of the characters from [Base64](/en-US/docs/Glossary/Base64#base64_characters) or [URL-safe Base64](/en-US/docs/Glossary/Base64#url_and_filename_safe_base64).

This string is a random value that the server generates for every HTTP response. For example:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ The following {{HTMLElement("script")}} element will be allowed by the policy:
```

Allowing all inline scripts is considered a security risk, so it's recommended to use a nonce-source or a hash-source instead.
To allow inline scripts and styles with a nonce-source, you need to generate a random nonce value (using a cryptographically secure random token generator) and include it in the policy.
To allow inline scripts and styles with a nonce-source, you need to generate a random {{Glossary("Nonce", "nonce")}} value (using a cryptographically secure random token generator) and include it in the policy.
It is important to note, this nonce value needs to be dynamically generated as it has to be unique for each HTTP request:

```http
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ The following {{HTMLElement("style")}} element and `style` attribute will be all
```

You can use a nonce-source to only allow specific inline style blocks.
You need to generate a random nonce value (using a cryptographically secure random token generator) and include it in the policy.
You need to generate a random {{Glossary("Nonce", "nonce")}} value (using a cryptographically secure random token generator) and include it in the policy.
It is important to note, this nonce value needs to be dynamically generated as it has to be unique for each HTTP request:

```http
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ Sec-WebSocket-Key: <key>

- `<key>`
- : The key for this request to upgrade.
This is a randomly selected 16-byte nonce that has been base64-encoded and isomorphic encoded.
This is a randomly selected 16-byte {{Glossary("Nonce", "nonce")}} that has been base64-encoded and isomorphic encoded.
The user agent adds this when initiating the WebSocket connection.

## Examples
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ The following sections describe token and auth parameters for some common auth s
- : A server-specified quoted string that the server can use to control the lifetime in which particular credentials will be considered valid.
This must be uniquely generated each time a 401 response is made, and may be regenerated more often (for example, allowing a digest to be used only once).
The specification contains advice on possible algorithms for generating this value.
The nonce value is opaque to the client.
The {{Glossary("Nonce", "nonce")}} value is opaque to the client.
- `opaque`
- : A server-specified quoted string that should be returned unchanged in the {{HTTPHeader("Authorization")}}.
This is opaque to the client. The server is recommended to include Base64 or hexadecimal data.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ In addition to the basic MathML global attributes, the following global attribut
- [`mathsize`](/en-US/docs/Web/MathML/Reference/Global_attributes/mathsize)
- : A {{cssxref("length-percentage")}} used as a [font-size](/en-US/docs/Web/CSS/Reference/Properties/font-size) for the element.
- [`nonce`](/en-US/docs/Web/MathML/Reference/Global_attributes/nonce)
- : A cryptographic nonce ("number used once") which can be used by [Content Security Policy](/en-US/docs/Web/HTTP/Guides/CSP) to determine whether a given fetch will be allowed to proceed.
- : A cryptographic {{Glossary("Nonce", "nonce")}} ("number used once") which can be used by [Content Security Policy](/en-US/docs/Web/HTTP/Guides/CSP) to determine whether a given fetch will be allowed to proceed.
- [`scriptlevel`](/en-US/docs/Web/MathML/Reference/Global_attributes/scriptlevel)
- : Specifies a [math-depth](/en-US/docs/Web/CSS/Reference/Properties/math-depth) for the element. See the [scriptlevel page](/en-US/docs/Web/MathML/Reference/Global_attributes/scriptlevel#values) for accepted values and mapping.
- [`style`](/en-US/docs/Web/MathML/Reference/Global_attributes/style)
Expand Down
Loading