[18] [[HTTP]] の[[ダイジェスト認証]]の [[nonce]] は、
次の場所で使われます。
[FIG(short list)[
- [CODE(HTTP)@en[[[nonce]]]] [[引数]] ([CODE(ABNF)@en[[[auth-param]]]])
- [CODE(HTTP)@en[[[cnonce]]]] [[引数]]
- [CODE(HTTP)@en[[[nextnonce]]]] [[引数]]
]FIG]

[19] [[HTML]] の [[nonce]] は、次の場所で使われます。
[FIG(short list)[
- [CODE(HTTP)@en[[[nonce]]]] [[引数]] ([[CSP]])
- [CODE(HTMLa)@en[[[nonce]]]] [[属性]]
]FIG]

* 仕様書

[REFS[
- [3] [CITE@en[RFC 7616 - HTTP Digest Access Authentication]] ([TIME[2015-11-10 07:05:08 +09:00]] 版) <https://tools.ietf.org/html/rfc7616#section-3.3>
- [22] [CITE@en-GB-x-hixie[HTML Standard]] ([TIME[2016-02-16 01:30:20 +09:00]] 版) <https://html.spec.whatwg.org/#the-script-element>
-- [24] [CITE@en-GB-x-hixie[HTML Standard]] ([TIME[2016-02-21 07:50:23 +09:00]] 版) <https://html.spec.whatwg.org/#attr-script-nonce>
- [32] [CITE@en-GB-x-hixie[HTML Standard]] ([TIME[2016-04-07 05:08:43 +09:00]] 版) <https://html.spec.whatwg.org/#concept-module-script-nonce>
]REFS]

* nonce (CSP、HTML)

** 意味

[25] [CODE(HTMLa)@en[[[nonce]]]] [[属性]]は、 [[CSP]]
で[[スクリプト]]を実行するかどうか決定するために使う[RUBYB[暗号学的]@en[cryptographic]] 
[[nonce]] (number used once) を指定するものです [SRC[>>24]]。

** 属性値

[26] [[属性値]]は、[[テキスト]]です [SRC[>>24]]。

** 文脈

[36] [CODE(HTMLa)@en[nonce]] [[属性]]は、
[CODE(HTMLe)@en[script]] [[要素]]と [CODE(HTMLe)@en[link]] [[要素]]で指定できます。

[23] [CODE(HTMLe)@en[[[script]]]] [[要素]]の種別が[[データブロック]]の時は、
[CODE(HTMLa)@en[[[nonce]]]] [[属性]]を使っては[['''なりません''']] [SRC[>>22]]。

[31] [[スクリプトfetchオプション群]]は、[DFN[[F[[RUBYB[[[暗号学的nonce]]]@en[cryptographic nonce]]]]]]を持ちます [SRC[>>32]]。
これは[[スクリプトのfetch]]で使われます。

** 処理

[27] [CODE(HTMLe)@en[[[script]]]] 参照。

[28] なお、初回処理時の値が使われるので、動的に変更しても、意味を持ちません [SRC[>>24]]。

** [CODE(DOMi)@en[HTMLScriptElement]] インターフェイス, [CODE(DOMi)@en[HTMLLinkElement]] インターフェイス [CODE(DOMa)@en[nonce]] 属性

[29] [CODE(DOMi)@en[HTMLScriptElement]] [[インターフェイス]],
[CODE(DOMi)@en[HTMLLinkElement]] [[インターフェイス]]の
[DFN[[CODE(DOMa)@en[[[nonce]]]]]] [[IDL属性]]は、
[CODE(HTMLa)@en[[[nonce]]]] [[内容属性]]を[[反映]]しなければ[MUST[なりません]]
[SRC[>>22]]。これは[[文字列]]として[[反映]]するものです。

** 歴史

[5] [CITE@en[Bug 26081 – Consider defining or mentioning the nonce attribute]]
( ([TIME[2014-06-14 02:59:38 +09:00]] 版))
<https://www.w3.org/Bugs/Public/show_bug.cgi?id=26081>

[2] [CITE@en[Merge pull request #171 from fmarier/csp2-remove-base64url · b4ab556 · w3c/webappsec]]
([TIME[2015-02-11 16:36:15 +09:00]] 版)
<https://github.com/w3c/webappsec/commit/b4ab55679f2261b05db896bd9399f25bc1314787>

[7] [CITE@en[Call out to CSP's inline element hooks · whatwg/html@ee3486e]]
([TIME[2015-11-08 16:32:08 +09:00]] 版)
<https://github.com/whatwg/html/commit/ee3486eb129bc350b5ca684d0c91dff23453ac1a>

[8] [CITE@en[Define script@nonce and style@nonce attributes · whatwg/html@882803c]]
([TIME[2015-11-12 00:04:23 +09:00]] 版)
<https://github.com/whatwg/html/commit/882803c4cc8fba2fa5472b76f628d95cc82c421d>

[9] [CITE@en[Accept base64url characters in nonces and hashes. · w3c/webappsec-csp@b4c5543]]
([TIME[2015-11-20 18:45:10 +09:00]] 版)
<https://github.com/w3c/webappsec-csp/commit/b4c5543c350417eb24f1f33247defe20e3430643>


* [CODE(HTTP)@en[nonce]] 引数 (auth-param)

** 意味

[10] [[nonce]] は、 [CODE(HTTP)[[[401]]]] [[応答]]の作成の度に毎回固有に[[生成]]するべき、
[[サーバー]]が指定する[[文字列]]です。 [SRC[>>3]]

[14] [[nonce]] は[[クライアント]]にとっては[[不透明]]です [SRC[>>3]]。

** 構文

[17] [CODE(ABNF)@en[[[auth-param]]]] 
の[[引用文字列]]構文を使わなければ[['''なりません''']] [SRC[>>3]]。

[11] [[nonce]] は、 [[Base64]] や[[十六進数]]で表記した[[文字列]]とすると[RUBYB[いいです]@en[advise]]。
[SRC[>>3]]

[12] 具体的な内容は、[[実装依存]]です [SRC[>>3]]。

** 文脈

[15] [CODE(HTTP)@en[[[nonce]]]] [[引数]]は、[[ダイジェスト認証]]の [[challenge]]
に指定できます [SRC[>>3]]。

[20] [CODE(HTTP)@en[[[nonce]]]] [[引数]]は必須です。

;; [21] [[RFC 2617]] 時代は、 [[ABNF]] [SRC[>>4]] 
で必須であることを主張しようとした形跡があります。 [[RFC 7616]]
には必須であるような規定はありません。しかし[[クライアント]]が [[credentials]]
の [CODE(HTTP)@en[[[response]]]] [[引数]]の計算に [CODE(HTTP)@en[[[nonce]]]]
を使いますから、[[サーバー]]は [[challenge]]
に [CODE(HTTP)@en[[[nonce]]]] を指定しないといけません。

** 処理

[13] 実装は、[[replay攻撃]]を防ぐため、前に使われた [[nonce]]
の再利用を認めないこととできます。 [SRC[>>3]]

[16] [CODE[[[response]]]] [[引数]]の値の計算に使われます。

** 歴史

[REFS[
- [1] [CITE@en[RFC 2069 - An Extension to HTTP : Digest Access Authentication]] ([TIME[2012-02-26 10:05:21 +09:00]] 版) <http://tools.ietf.org/html/rfc2069#page-5>
- [4] [CITE@en[RFC 2617 - HTTP Authentication: Basic and Digest Access Authentication]] ([TIME[2012-01-09 21:04:30 +09:00]] 版) <http://tools.ietf.org/html/rfc2617#section-3.2.1>
]REFS]

* メモ

[6] [CITE@ja-jp[ナンス ‐ 通信用語の基礎知識]]
([TIME[2015-07-14 22:47:40 +09:00]] 版)
<http://www.wdic.org/w/WDIC/%E3%83%8A%E3%83%B3%E3%82%B9>

[30] [CITE@en[Add 'cryptographic nonce metadata' to requests · whatwg/fetch@667ca32]]
([TIME[2016-04-06 16:33:03 +09:00]] 版)
<https://github.com/whatwg/fetch/commit/667ca3264e94ee4e5c7a1e1b85feb3344d107a1f>

[33] [CITE@en[Pass cryptographic nonce metadata to Fetch · whatwg/html@5479e07]]
([TIME[2016-04-07 16:08:44 +09:00]] 版)
<https://github.com/whatwg/html/commit/5479e07a6f6e01062b85b5fe6799752b0370336c>

[34] [CITE@en[Wire nonces up to Fetch's cryptographic nonce metadata. · w3c/webappsec-csp@86ae8b1]]
([TIME[2016-04-12 17:14:01 +09:00]] 版)
<https://github.com/w3c/webappsec-csp/commit/86ae8b1bcbd95c95dcac029f6b27c668e59164dd>

[35] [CITE@en[Add <link nonce>]]
([[mikewest]]著, [TIME[2016-09-28 20:17:08 +09:00]])
<https://github.com/whatwg/html/commit/1d4fc66465169312deaa8945fcb359813abc3fe0>

[37] [CITE@en[Value-agnostic nonce matching (#222)]]
([[andypaicu]]著, [TIME[2017-05-30 21:51:31 +09:00]])
<https://github.com/w3c/webappsec-csp/commit/af76f746928d6db9372d1ce5bc02f74c7ec88607>

[38] [CITE@en[Make integrity="" work on module scripts]]
([[domenic]]著, [TIME[2017-09-14 18:00:24 +09:00]])
<https://github.com/whatwg/html/commit/9275d955dcd604e959cfcc672e0c234b1b8c00db>

[39] [CITE@en[NoncedElement link.]]
([[mikewest]]著, [TIME[2017-12-01 22:53:04 +09:00]])
<https://github.com/w3c/webappsec-csp/commit/7024fc63655667d380056848966204c350669c8e>

[40] [CITE@en[Hide nonce content attribute values]]
([[mikewest]]著, [TIME[2017-11-23 00:15:47 +09:00]])
<https://github.com/whatwg/html/commit/19f5cce801550d278b9459f8c4797f9f86aae864>

[41] [CITE@en[Consider hiding `nonce` content attributes. · Issue #2369 · whatwg/html]]
([TIME[2018-02-17 23:20:14 +09:00]])
<https://github.com/whatwg/html/issues/2369>

[42] [CITE@en[Consider not exposing nonce="" to the page · Issue #65 · w3c/webappsec-csp]]
([TIME[2018-02-17 23:22:57 +09:00]])
<https://github.com/w3c/webappsec-csp/issues/65>

[43] [CITE@en[Hide `nonce` content attribute values. (#2369) by mikewest · Pull Request #2373 · whatwg/html]]
([TIME[2018-02-17 23:23:03 +09:00]])
<https://github.com/whatwg/html/pull/2373>

[44] [CITE@en[Hide `nonce` content attribute values from non-script sources. by mikewest · Pull Request #436 · whatwg/dom]]
([TIME[2018-02-17 23:40:09 +09:00]])
<https://github.com/whatwg/dom/pull/436>

[45] [CITE@en[Add HTMLOrSVGElement interface mixin]]
([[annevk]]著, [TIME[2018-03-23 19:30:45 +09:00]])
<https://github.com/whatwg/html/commit/81e82437a7ef1ee37d4ce2b5a982bc297d5b58b1>

[46] [CITE@en[Fix and clarify some '''['''CEReactions''']''' annotations]]
([[domenic]]著, [TIME[2018-08-11 19:59:46 +09:00]])
<https://github.com/whatwg/html/commit/023c11216ca2ee1c653df09a594b98fca1323975>

[47] [CITE@en[nonce IDL attribute should have the semantics of CEReactions · Issue #3887 · whatwg/html]]
([TIME[2018-08-18 23:59:26 +09:00]])
<https://github.com/whatwg/html/issues/3887>

[48] [CITE@en[Fix and clarify some '''['''CEReactions''']''' annotations by domenic · Pull Request #3901 · whatwg/html]]
([TIME[2018-08-19 00:00:06 +09:00]])
<https://github.com/whatwg/html/pull/3901>

[49] [CITE@en[Convert string to UTF-8 before applying hash algorithms (#342)]]
([[andypaicu]]著, [TIME[2018-10-04 21:44:55 +09:00]])
<https://github.com/w3c/webappsec-csp/commit/84cc0d929ed90b21575e2ec1973438a5745d5562>

[50] [CITE@en[Convert string to UTF-8 before applying hash algorithms by andypaicu · Pull Request #342 · w3c/webappsec-csp]]
([TIME[2018-10-22 01:19:24 +09:00]])
<https://github.com/w3c/webappsec-csp/pull/342>

[51] [CITE@en[Hash encodings should be converted to UTF-8 · Issue #109 · w3c/webappsec-csp]]
([TIME[2018-10-22 01:19:39 +09:00]])
<https://github.com/w3c/webappsec-csp/issues/109>

[52] [CITE@en[Only Chrome implements HTMLElement.nonce IDL attribute · Issue #4208 · whatwg/html · GitHub]]
([TIME[2019-01-08 10:43:25 +09:00]])
<https://github.com/whatwg/html/issues/4208>

[53] [CITE@en[Added more notes about nonce attacks (#356)]]
([[andypaicu]]著, [TIME[2018-11-09 21:59:26 +09:00]])
<https://github.com/w3c/webappsec-csp/commit/48b736b9049ec5d8c82375c5a972bd57ad43759a>

[54] [CITE@en[Added more notes about nonce attacks by andypaicu · Pull Request #356 · w3c/webappsec-csp]]
([TIME[2019-03-08 16:49:49 +09:00]])
<https://github.com/w3c/webappsec-csp/pull/356>

[55] [CITE@en[Add note about the importance of preventing nonce exfiltration/reuse · Issue #258 · w3c/webappsec-csp]]
([TIME[2019-03-08 16:50:08 +09:00]])
<https://github.com/w3c/webappsec-csp/issues/258>