-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathindex.html
1937 lines (1643 loc) · 74.2 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html>
<head>
<title>Network Error Logging</title>
<meta charset='utf-8'>
<meta name="color-scheme" content="light dark">
<script src='https://www.w3.org/Tools/respec/respec-w3c' defer class='remove'></script>
<script class='remove'>
var respecConfig = {
group: "webperf",
github: "https://github.com/w3c/network-error-logging/",
shortname: "network-error-logging",
specStatus: "ED",
xref: ["network-reporting", "fetch", "hr-time", "html", "infra", "mixed-content", "referrer-policy", "reporting", "resource-timing", "secure-contexts", "url"],
editors: [{
name: "Douglas Creager",
url: "https://dcreager.net/",
company: "GitHub",
w3cid: "103120",
}, {
name: "Ian Clelland",
company: "Google",
w3cid: "76841",
}],
formerEditors: [{
name: "Ilya Grigorik",
url: "https://www.igvita.com/",
company: "Google",
retiredDate: "2019-08-01",
}, {
name: "Julia Tuttle",
company: "Google",
retiredDate: "2017-09-01",
}, {
name: "Arvind Jain",
company: "Google",
retiredDate: "2015-01-01",
}, {
name: "Alois Reitbauer",
company: "Compuware Corp.",
retiredDate: "2014-10-01",
}, {
name: "Jatinder Mann",
company: "Microsoft",
retiredDate: "2014-02-01",
}],
};
</script>
<style>
.reportTypeGroup {
margin-top: 1em; padding-top: 1ex;
border-top: 1px solid black;
}
</style>
</head>
<body>
<section id='abstract'>
<p>This document defines a mechanism that enables developers to declare a network error reporting policy for a web application. A user agent can use this policy to report encountered network errors that prevented it from successfully fetching requested resources.</p>
</section>
<section id='sotd'>
</section>
<section>
<h2>Introduction</h2>
<p>Accurately measuring performance characteristics of web applications is an important aspect in helping site developers understand how to improve their web applications. The worst case scenario is the failure to load the application, or a particular resource, due to a network error, and to address such failures the developer requires assistance from the user agent to identify when, where, and why such failures are occurring.</p>
<p>Today, application developers do not have real-time web application availability data from their end users. For example, if the user fails to load the page due to a network error, such as a failed DNS lookup, a connection timeout, a reset connection, or other reasons, the site developer is unable to detect and address this issue. Note that these kinds of network errors cannot be detected purely server-side, since by definition the client might not have been able to successfully establish a connection with the server.</p>
<p>Existing methods (such as synthetic monitoring) provide a partial solution by placing monitoring nodes in predetermined geographic locations, but require additional infrastructure investments, and cannot provide truly global and near real-time availability data for real end users.</p>
<p>Network Error Logging (NEL) addresses this need by defining a mechanism enabling web applications to declare a reporting policy that can be used by the user agent to report network errors for a given origin. A web application opts into using NEL by supplying a <a>NEL</a> HTTP response header field that describes the desired <a>NEL policy</a>. This policy instructs the user agent to log information about requests to that origin, and to attempt to deliver that information to a group of endpoints previously configured using the [[[REPORTING]]]. As the name implies, NEL reports are primarily used to describe <em>errors</em>. However, in order to determine <em>rates</em> of errors across different client populations, we must also know how many <em>successful</em> requests are occurring; these successful requests can also be reported via the NEL mechanism.</p>
<p>For example, if the user agent fails to fetch a resource from <code>https://www.example.com</code> due to an aborted TCP connection, the user agent would queue the following report via the Reporting API:</p>
<dl>
<dt>type</dt>
<dd><code>"network-error"</code></dd>
<dt>endpoint group</dt>
<dd>the endpoint group configured by the <a>report_to</a> field</dd>
<dt>data</dt>
<dd><pre class="highlight">
{
"referrer": "https://referrer.com/",
"sampling_fraction": 1.0,
"server_ip": "192.0.2.42",
"protocol": "http/1.1",
"elapsed_time": 321,
"phase": "connection",
"type": "tcp.aborted"
}
</pre></dd>
</dl>
<p>
See <a href="#generate-a-network-error-report"></a> for an explanation of
the communicated fields and format of the report, and <a
href="#examples"></a> for more hands-on examples of NEL registration and
reporting process.
</p>
</section>
<section id="conformance">
<p>Requirements phrased in the imperative as part of algorithms (such as "strip any leading space characters" or "return false and abort these steps") are to be interpreted with the meaning of the key word ("must", "should", "may", etc) used in introducing the algorithm.</p>
<p>Some conformance requirements are phrased as requirements on attributes, methods or objects. Such requirements are to be interpreted as requirements on the user agent.</p>
<p>Conformance requirements phrased as algorithms or specific steps may be implemented in any manner, so long as the end result is equivalent. (In particular, the algorithms defined in this specification are intended to be easy to follow, and not intended to be performant.)</p>
</section>
<section>
<h2>Concepts</h2>
<section>
<h2>Network requests</h2>
<p>
A <dfn data-lt="network requests">network request</dfn> occurs when the
[=user agent=] attempts to <a data-cite="fetch#http-network-fetch">HTTP-network fetch</a>
a resource over the network for a given [=request=].
</p>
<p>
A [=request=] MUST NOT result in a <a>network request</a> if the user
agent is known to be offline (i.e., when <code>navigator.</code>
{{NavigatorOnLine/onLine}} returns <code>false</code>).
</p>
<p>
A [=request=] MUST NOT result in a <a>network request</a> if it is
blocked due to [=mixed content=] or [=CORS protocol|CORS=] failures. Any
[=CORS-preflight request=] MUST result in its own <a>network request</a>.
</p>
<p>
Regardless of which fetch algorithm and which underlying application and
transport protocols are used, servicing a <a>network request</a> consists
of the following <dfn data-lt="phase">phases</dfn>:
</p>
<ol>
<li>
<dfn>DNS resolution</dfn>: The user agent uses the Domain Name System
[[RFC1034]] to resolve a domain name into an [=IP address=] of a
<dfn data-cite="RFC9110#core.semantics">server</dfn> can that service
HTTP [=requests=] to that domain.
</li>
<li>
<dfn>Secure connection establishment</dfn>: The user agent opens a
connection to the <a>server</a>, and establishes a secure channel over
this connection.
</li>
<li>
<dfn>Transmission of request and response</dfn>: Once the secure
channel is established, the user agent can transmit the HTTP
[=request=], and receive the [=response=] from the <a>server</a>.
</li>
</ol>
<p>
The only mandatory <a>phase</a> is the <a>transmission of request and
response</a>; the other <a>phases</a> might not be needed for every
<a>network request</a>. For instance, DNS results can be cached locally
in the user agent, eliminating <a>DNS resolution</a> for future requests
to the same domain. Similarly, HTTP
<a data-cite="RFC9112#persistent.connections">persistent connections</a>
allow open connections to be shared for multiple requests to the same
[=network partition key=]. However, if multiple <a>phases</a> occur, they
will occur in the above order.
</p>
<p class="ednote">
We would like to move the definition of these <a>phases</a> into [[FETCH]]
so that they are more reusable.
</p>
<p>
A <a>network request</a> is <dfn
data-lt="succeed|succeeded">successful</dfn> if the user agent is able
to receive a valid HTTP response from the server, and that response does
not have a <dfn data-cite="RFC9110#status.4xx">4xx</dfn> or
<dfn data-cite="RFC9110#status.5xx">5xx</dfn> status code.
</p>
<p>
A <a>network request</a> is <dfn data-lt="fail|failures">failed</dfn> if
it is not <a>successful</a>.
</p>
<p class="note">
Note that HTTP error responses (i.e., those with a <a>4xx</a> or
<a>5xx</a> status code) are considered <a>failures</a>, so that they are
subject to a <a>NEL policy</a>'s <a>failure sampling rate</a> instead of
its <a>successful sampling rate</a>.
</p>
</section>
<section>
<h2>Network errors</h2>
<p>
A <dfn data-lt="network errors">network error</dfn> is the error condition
that caused a <a>network request</a> to <a>fail</a>.
</p>
<p>
Each <a>network error</a> has a <dfn data-lt="types">type</dfn>, which is
a string.
</p>
<p>
Each <a>network error</a> has a <dfn data-lt-nodefault
data-lt="type-phase">phase</dfn>, which describes which <a>phase</a> the
error occurred in:
</p>
<dl>
<dt><code>dns</code></dt>
<dd>the error occurred during <a>DNS resolution</a></dd>
<dt><code>connection</code></dt>
<dd>
the error occurred during <a>secure connection establishment</a>
</dd>
<dt><code>application</code></dt>
<dd>
the error occurred during the <a>transmission of request and
response</a>
</dd>
</dl>
<p>
There are several predefined <a>network error</a> <a>types</a> defined in
<a href="#predefined-network-error-types"></a>.
</p>
</section>
<section>
<h2>Network error reports</h2>
<p>
A <dfn data-lt="network error reports">network error report</dfn> is a [[[REPORTING]]] <a>report</a> that describes a
<a>network error</a>.
</p>
<p>
<a>Network error reports</a> have a <a>report type</a> of
<code>network-error</code>.
</p>
<p>
<a>Network error reports</a> are <strong>NOT</strong> <a>visible to
<code>ReportingObserver</code>s</a>.
</p>
<p class="note">
<a>Network error reports</a> are not <a>visible to
<code>ReportingObserver</code>s</a> because they are only intended to be
visible to the administrator or owner of the server <em>receiving</em> the
requests. If they were <a>visible to <code>ReportingObserver</code>s</a>,
then the reports would also be visible to the <em>originator</em> of the
request. For cross-origin requests, this could leak information about the
server's network configuration to parties outside of its control.
</p>
</section>
<section>
<h2>NEL policies</h2>
<p>
A <dfn data-lt="NEL policies|NEL policy" data-export id="dfn-nel-policies">NEL policy</dfn>
instructs a user agent whether to collect reports about
<a>network requests</a> to an <a>origin</a>, and if so, where to send them.
<a>NEL policies</a> are delivered to the user agent via HTTP
<dfn data-cite="RFC9110#fields">response headers</dfn>.
</p>
<p>
Each <a>NEL policy</a> has a <dfn>received IP address</dfn>, which is the
[=IP address=] of the <a>server</a> that the user agent received this
<a>NEL policy</a> from.
</p>
<p>
Each <a>NEL policy</a> has an <dfn data-lt-nodefault data-lt="policy
origin">origin</dfn>.
</p>
<p>
Each <a>NEL policy</a> has a <dfn>subdomains</dfn> flag, which is either
<code>include</code> or <code>exclude</code>.
</p>
<p>
<p>
Each <a>NEL policy</a> has a list of <dfn data-lt-noDefault
data-lt="policy request headers">request headers</dfn> and a list of <dfn
data-lt-noDefault data-lt="policy response headers">response
headers</dfn>, each of which is a list of <a>header names</a>.
</p>
<p>
Each <a>NEL policy</a> has a <dfn>reporting group</dfn>, which is the name
of the Reporting <a>endpoint group</a> that reports for this policy will
be sent to.
</p>
<p>
Each <a>NEL policy</a> has a <dfn>ttl</dfn> representing the number of
seconds the policy remains valid.
</p>
<p>
Each <a>NEL policy</a> has a <dfn>creation</dfn> which is the timestamp
when the user agent received the policy.
</p>
<p>
A <a>NEL policy</a> is <dfn>stale</dfn> if the <a>duration from</a> its
<a>creation</a> to the [=wall clock=]'s [=wall clock/unsafe current time=]
is greater than 172800 seconds (48 hours).
</p>
<p>
A <a>NEL policy</a> is <dfn>expired</dfn> if the <a>duration from</a> its
<a>creation</a> to the [=wall clock=]'s [=wall clock/unsafe current time=]
is greater than its <a>ttl</a> (in seconds).
</p>
</section>
<section>
<h2>Sampling rates</h2>
<p>
An <a>origin</a> that expects to serve a large volume of traffic might not
be equipped to ingest NEL reports for every <a>network request</a> made to
the origin. The origin can define <dfn data-lt="sampling rate">sampling
rates</dfn> to limit the number of NEL reports that each user agent
submits. Since <a>successful</a> requests should typically greatly
outnumber <a>failed</a> requests, the origin can specify different
sampling rates for each.
</p>
<p>
Each <a>NEL policy</a> has a <dfn>successful sampling rate</dfn>, which is
a number between 0.0 and 1.0 inclusive.
</p>
<p>
Each <a>NEL policy</a> has a <dfn>failure sampling rate</dfn>, which is a
number between 0.0 and 1.0 inclusive.
</p>
</section>
<section>
<h2>Policy cache</h2>
<p>
A conformant user agent MUST provide a <dfn>policy cache</dfn>, which is a
storage mechanism that maintains a set of <a>NEL policies</a>, keyed by
(<a>network partition key</a>, <a>origin</a>) tuples.
</p>
<p>
This storage mechanism is opaque, vendor-specific, and not exposed to the
web, but it MUST provide the following methods which will be used in the
algorithms this document defines:
</p>
<ul>
<li>Insert, update, and delete <a>NEL policies</a>.</li>
<li>Retrieve the <a>NEL policy</a>, if any, for a given <a>origin</a>
and <a>network partition key</a>.</li>
<li>Clear the cache.</li>
</ul>
</section>
</section>
<section>
<h2>Policy delivery</h2>
<p>
A <a>server</a> MAY define a <a>NEL policy</a> for an origin it controls via
the <a>NEL</a> HTTP <a>response header</a>.
</p>
<section>
<h2><code>NEL</code> response header</h2>
<p>
The <dfn><code>NEL</code></dfn> <a>response header</a> is used to
communicate an <a>origin</a>'s <a>NEL policy</a> to the user agent. The
ABNF (Augmented Backus-Naur Form) [[RFC5234]] syntax for the <a>NEL</a> header is as
follows:
</p>
<pre>NEL = json-field-value</pre>
<p>
The header's value is interpreted as an array of JSON objects, as defined
by <a data-cite="HTTP-JFV#json-field-value">json-field-value</a>. Each object in the array defines an <a>NEL
policy</a> for the origin. The user agent MUST process the first valid
policy in the array and ignore any additional policies in the array.
</p>
<p>User agents MUST ignore any unknown or invalid field(s) or value(s) that do not conform to the syntax defined in this specification. A valid <a>NEL</a> header field MUST, at a minimum, contain one object with all of the "REQUIRED" fields defined in this specification.</p>
<p>The user agent MUST ignore the <a>NEL</a> header specified via a <code>meta</code> element to mitigate hijacking of error reporting via scripting attacks. The <a>NEL policy</a> MUST be delivered via the <a>NEL</a> <a>response header</a>.</p>
<p class="note">The restriction on <code>meta</code> element is consistent with the [[CSP]] specification, which restricts reporting registration to HTTP header fields only for the same reasons.</p>
<section>
<h2>The <code>report_to</code> member</h2>
<p>
The <dfn><code>report_to</code></dfn> member specifies the <a>endpoint
group</a> that reports for this <a>NEL policy</a> will be sent to.
The <a>report_to</a> member is REQUIRED to register a <a>NEL policy</a>,
and OPTIONAL if the intent is to remove a previous registration – see
<a>max_age</a>. If present, its value MUST be a string; any other type
will result in a parse error.
</p>
<p class="note">
To improve delivery of NEL reports, the <a>server</a> should set
<code>report_to</code> to an <a>endpoint group</a> containing at least
one endpoint in an alternative origin whose infrastructure is not
coupled with the origin from which the resource is being fetched —
otherwise network errors cannot be reported until the problem is solved,
if ever — and provide multiple endpoints to provide alternatives
if some endpoints are unreachable.
</p>
</section>
<section>
<h2>The <code>max_age</code> member</h2>
<p>
The REQUIRED <dfn><code>max_age</code></dfn> member specifies the
lifetime of this <a>NEL policy</a>, as a non-negative integer number of
seconds. Its value MUST be an non-negative integer; any other type will
result in a parse error.
</p>
<p>
A value of <code>0</code> will cause any <a>NEL policy</a> for this
<a>origin</a> to be removed from the <a>policy cache</a>.
</p>
<p class="note">
To ensure delivery of NEL reports, the <a>server</a> should ensure that
the Reporting <a>endpoint group</a> is also configured with a
sufficiently high <code>max_age</code>. If the Reporting policy
expires, NEL reports will not be delivered, even if the NEL policy has
not expired.
</p>
</section>
<section>
<h2>The <code>include_subdomains</code> member</h2>
<p>
The OPTIONAL <dfn><code>include_subdomains</code></dfn> member is a
boolean that enables this <a>NEL policy</a> for all subdomains of this
origin (to an unlimited subdomain depth). If no member named
<code>include_subdomains</code> is present in the object, or its value
is not <code>true</code>, the <a>NEL policy</a> will not be enabled
for subdomains.
</p>
<p class="note">
To ensure delivery of NEL reports for subdomains, the application should
ensure that the Reporting <a>endpoint group</a> is also configured with
<code>include_subdomains</code> enabled. If the Reporting policy is
not, and there is not a separate Reporting policy for a given subdomain,
NEL reports for that subdomain will not be delivered, even if the NEL
policy includes the subdomain.
</p>
</section>
<section>
<h2>The <code>success_fraction</code> member</h2>
<p>
The OPTIONAL <dfn><code>success_fraction</code></dfn> member defines the
<a>sampling rate</a> that should be applied to reports about
<a>successful</a> <a>network requests</a> for this origin. If present,
its value MUST be a number between <code>0.0</code> and
<code>1.0</code>, inclusive; any other value will result in a parse
error. If this member is not present, the user agent will <em>not</em>
collect NEL reports about <a>successful</a> <a>network requests</a> for
this origin.
</p>
</section>
<section>
<h2>The <code>failure_fraction</code> member</h2>
<p>
The OPTIONAL <dfn><code>failure_fraction</code></dfn> member defines the
<a>sampling rate</a> that should be applied to reports about
<a>failed</a> <a>network requests</a> for this origin. If present, its
value MUST be a number between <code>0.0</code> and <code>1.0</code>,
inclusive; any other value will result in a parse error. If this member
is not present, the user agent will collect NEL reports about
<em>all</em> <a>failed</a> <a>network requests</a> for this origin.
</p>
</section>
<section>
<h2>The <code>request_headers</code> member</h2>
<p>
The OPTIONAL <dfn><code>request_headers</code></dfn> member defines the
list of <a data-lt="policy request headers">request headers</a> whose <a
data-lt="header name">names</a> and <a data-lt="header
value">values</a> will be included in <a>network error reports</a>
about this <a>origin</a>. If present, its value MUST be a list of
strings.
</p>
</section>
<section>
<h2>The <code>response_headers</code> member</h2>
<p>
The OPTIONAL <dfn><code>response_headers</code></dfn> member defines the
list of <a data-lt="policy response headers">response headers</a> whose
<a data-lt="header name">names</a> and <a data-lt="header
value">values</a> will be included in <a>network error reports</a>
about this <a>origin</a>. If present, its value MUST be a list of
strings.
</p>
</section>
</section>
<section>
<h2>Process policy headers</h2>
<p>
Given a <a>network request</a> (<var>request</var>) and its corresponding
<a>response</a> (<var>response</var>), this algorithm extracts a <a>NEL
policy</a> for <var>request</var>'s <a>origin</a>, and updates the
<a>policy cache</a> accordingly.
</p>
<ol class="algorithm">
<li>
Abort these steps if any of the following conditions are true:
<ul>
<li>
The result of executing the "<a>Is origin potentially
trustworthy?</a>" algorithm on <var>request</var>'s
<a>origin</a> is <strong>not</strong> <code>Potentially
Trustworthy</code>.
</li>
<li>
<var>response</var> does not contain a <a>response header</a>
whose name is <code>NEL</code>.
</li>
</ul>
</li>
<li>
Let <var>origin</var> be <var>request</var>'s <a>origin</a>.
</li>
<li>
Let <var>key</var> be the result of calling <a>determine the network
partition key</a>, given <var>request</var>'s
[=request/reserved client=].
</li>
<li>
Let <var>header</var> be the value of the <a>response header</a> whose
name is <code>NEL</code>.
</li>
<li>
Let <var>list</var> be the result of executing the algorithm defined
in Section 4 of [[HTTP-JFV]] on <var>header</var>. If that algorithm
results in an error, or if <var>list</var> is empty, abort these
steps.
</li>
<li>
Let <var>item</var> be the first element of <var>list</var>.
</li>
<li>
If <var>item</var> has no member named <a>max_age</a>, or that
member's value is not a number, abort these steps.
</li>
<li>
If the value of <var>item</var>'s <a>max_age</a> member is
<code>0</code>, then remove any <a>NEL policy</a> from the <a>policy
cache</a> whose <a data-lt="policy origin">origin</a> is
<var>origin</var>, and skip the remaining steps.
</li>
<li>
If <var>item</var> has no member named <a>report_to</a>, or that
member's value is not a string, abort these steps.
</li>
<li>
If <var>item</var> has a member named <a>success_fraction</a>, whose
value is not a number in the range 0.0 to 1.0, inclusive, abort these
steps.
</li>
<li>
If <var>item</var> has a member named <a>failure_fraction</a>, whose
value is not a number in the range 0.0 to 1.0, inclusive, abort these
steps.
</li>
<li>
If <var>item</var> has a member named <a>request_headers</a>, whose
value is not a list, or if any element of that list is not a string,
abort these steps.
</li>
<li>
If <var>item</var> has a member named <a>response_headers</a>, whose
value is not a list, or if any element of that list is not a string,
abort these steps.
</li>
<li>
<p>
Let <var>policy</var> be a new <a>NEL policy</a> whose properties are
set as follows:
</p>
<dl>
<dt><a>received IP address</a></dt>
<dd>
the [=IP address=] of the <a>server</a> that the user agent received
<var>response</var> from
<p class="ednote">
Plumb this through more explicitly in [[FETCH]].
</p>
</dd>
<dt><a>origin</a></dt>
<dd><var>origin</var></dd>
<dt><a>subdomains</a> flag</dt>
<dd>
<code>include</code> if <var>item</var> has a member named
<a>include_subdomains</a> whose value is <code>true</code>,
<code>exclude</code> otherwise
</dd>
<dt><a data-lt="policy request headers">request headers</a></dt>
<dd>
the value of <var>item</var>'s <a>request_headers</a> member
</dd>
<dt><a data-lt="policy response headers">response headers</a></dt>
<dd>
the value of <var>item</var>'s <a>response_headers</a> member
</dd>
<dt><a>reporting group</a></dt>
<dd>the value of <var>item</var>'s <a>report_to</a> member</dd>
<dt><a>ttl</a></dt>
<dd>the value of <var>item</var>'s <a>max_age</a> member</dd>
<dt><a>creation</a></dt>
<dd>the [=wall clock=]'s [=wall clock/unsafe current time=]</dd>
<dt><a>successful sampling rate</a></dt>
<dd>
the value of <var>item</var>'s <a>success_fraction</a> member, if
present; <code>0.0</code> otherwise
</dd>
<dt><a>failure sampling rate</a></dt>
<dd>
the value of <var>item</var>'s <a>failure_fraction</a> member, if
present; <code>1.0</code> otherwise
</dd>
</dl>
</li>
<li>
If there is already an entry in the <a>policy cache</a> for
(<var>key</var>, <var>origin</var>), replace it with
<var>policy</var>; otherwise, insert <var>policy</var> into the
<a>policy cache</a> for (<var>key</var>, <var>origin</var>).
</li>
</ol>
</section>
</section>
<section>
<h2>Report delivery</h2>
<section>
<h2>Choose a policy for a request</h2>
<p>
Given a <a>network request</a> (<var>request</var>), this algorithm
determines which <a>NEL policy</a> in the <a>policy cache</a> should be
used to generate reports for that <a>network request</a>.
</p>
<ol class="algorithm">
<li>
Let <var>origin</var> be <var>request</var>'s <a>origin</a>.
</li>
<li>
Let <var>key</var> be the result of calling <a>determine the network
partition key</a>, given <var>request</var>'s'
[=request/reserved client=].
</li>
<li>
If there is an entry in the <a>policy cache</a> for (<var>key</var>,
<var>origin</var>):
<ol>
<li>Let <var>policy</var> be that entry.</li>
<li>If <var>policy</var> is not <a>expired</a>, return it.</li>
</ol>
</li>
<li>
For each <var>parent origin</var> that is a <a data-cite="!RFC6797#section-8.2">superdomain match</a>
of <var>origin</var>:
<ol>
<li>
If there is an entry in the <a>policy cache</a> for
(<var>key</var>, <var>parent origin</var>):
<ol>
<li>Let <var>policy</var> be that entry.</li>
<li>
If <var>policy</var> is not <a>expired</a>, and its
<a>subdomains</a> flag is <code>include</code>, return it.
</li>
</ol>
</li>
</ol>
</li>
<li>
Return <code>no policy</code>.
</li>
</ol>
</section>
<section>
<h2>Extract request headers</h2>
<p>
Given a <a>network request</a> (<var>request</var>) and a <a>NEL
policy</a> (<var>policy</var>), this algorithm extracts header values
from the request as instructed by the policy.
</p>
<ol class="algorithm">
<li>
Let <var>headers</var> be a new empty ECMAScript object.
</li>
<li>
For each <var>header name</var> in <var>policy</var>'s <a
data-lt="policy request headers">request headers</a> list:
<ol>
<li>
If <var>request</var>'s [=request/header
list=] does not [=header list/contain=]
<var>header name</var>, skip to the next <var>header name</var> in
the list.
</li>
<li>
Let <var>values</var> be an empty ECMAScript list.
</li>
<li>
For each <var>header</var> in <var>request</var>'s
[=request/header list=] whose <a data-lt="header name">name</a>
is <var>header name</var>, append <var>header</var>'s
<a data-lt="header value">value</a> to <var>values</var>.
</li>
<li>
Add a new property to <var>headers</var> whose name is <var>header
name</var> and whose value is <var>values</var>.
</li>
</ol>
</li>
<li>
Return <var>headers</var>.
</li>
</ol>
</section>
<section>
<h2>Extract response headers</h2>
<p>
Given a <a>response</a> (<var>response</var>) and a <a>NEL policy</a>
(<var>policy</var>), this algorithm extracts header values from the
response as instructed by the policy.
</p>
<ol class="algorithm">
<li>
Let <var>headers</var> be a new empty ECMAScript object.
</li>
<li>
For each <var>header name</var> in <var>policy</var>'s <a
data-lt="policy response headers">response headers</a> list:
<ol>
<li>
If <var>response</var>'s [=response/header list=]
does not [=header list/contain=]
<var>header name</var>, skip to the next <var>header name</var> in
the list.
</li>
<li>
Let <var>values</var> be an empty ECMAScript list.
</li>
<li>
For each <var>header</var> in <var>response</var>'s
[=response/header list=] whose <a
data-lt="header name">name</a> is <var>header name</var>, append
<var>header</var>'s <a data-lt="header value">value</a> to
<var>values</var>.
</li>
<li>
Add a new property to <var>headers</var> whose name is <var>header
name</var> and whose value is <var>values</var>.
</li>
</ol>
</li>
<li>
Return <var>headers</var>.
</li>
</ol>
</section>
<section>
<h2 id="generate-a-network-error-report" data-dfn-type="dfn"
data-export>Generate a network error report</h2>
<p>
Given a <a>network request</a> (<var>request</var>) and its corresponding
<a>response</a> (<var>response</var>), this algorithm generates a report
about <var>request</var> if instructed to by any matching <a>NEL
policy</a>, and returns the report and the NEL policy. Otherwise this
algorithm returns null.
</p>
<ol class="algorithm">
<li>
If the result of executing the "<a>Is origin potentially
trustworthy?</a>" algorithm on <var>request</var>'s <a>origin</a> is
<strong>not</strong> <code>Potentially Trustworthy</code>, return
null.
</li>
<li>
Let <var>origin</var> be <var>request</var>'s <a>origin</a>.
</li>
<li>
Let <var>policy</var> be the result of executing <a
href="#choose-a-policy-for-a-request"></a> on <var>request</var>. If
<var>policy</var> is <code>no policy</code>, return null.
</li>
<li>
Determine the active sampling rate for this request:
<ul>
<li>
If <var>request</var> <a>succeeded</a>, let <var>sampling rate</var>
be <var>policy</var>'s <a>successful sampling rate</a>.
</li>
<li>
If <var>request</var> <a>failed</a>, let <var>sampling rate</var>
be <var>policy</var>'s <a>failure sampling rate</a>.
</li>
</ul>
</li>
<li>
Decide whether or not to report on this request. Let <var>roll</var>
be a random number between 0.0 and 1.0, inclusive. If <var>roll</var>
≥ <var>sampling rate</var>, return null.
</li>
<li>
Let <var>report body</var> be a new ECMAScript object with the
following properties: [[ECMA-262]]
<dl>
<dt><code>sampling_fraction</code></dt>
<dd><var>sampling rate</var></dd>
<dt><code>elapsed_time</code></dt>
<dd>
The elapsed number of milliseconds between the start of the resource
fetch and when it was completed or aborted by the user agent.
</dd>
<dt><code>phase</code></dt>
<dd>
If <var>request</var> <a>failed</a>, the
<a data-lt="type-phase">phase</a> of its <a>network error</a>. If
<var>request</var> <a>succeeded</a>, <code>"application"</code>.
</dd>
<dt><code>type</code></dt>
<dd>
If <var>request</var> <a>failed</a>, the <a>type</a> of its
<a>network error</a>. If <var>request</var> <a>succeeded</a>,
<code>"ok"</code>.
</dd>
</dl>
</li>
<li>
If <var>report body</var>'s <code>phase</code> property is not
<code>dns</code>, append the following properties to <var>report
body</var>:
<dl>
<dt><code>server_ip</code></dt>
<dd>The IP address of the <a>server</a> to which the user agent sent
the request, if available. Otherwise, an empty string.
<ul>
<li>A host identified by an IPv4 address is represented in
dotted-decimal notation (a sequence of four decimal numbers in
the range 0 to 255, separated by "."). [[RFC1123]]</li>
<li>A host identified by an IPv6 address is represented as an
ordered list of eight 16-bit pieces (a sequence of
`x:x:x:x:x:x:x:x`, where the 'x's are one to four hexadecimal
digits of the eight 16-bit pieces of the address). [[RFC4291]]
</li>
</ul>
</dd>
<dt><code>protocol</code></dt>
<dd>
The <a data-cite="RESOURCE-TIMING-2#dom-performanceresourcetiming-nexthopprotocol">network protocol</a> used to fetch the resource as
identified by the ALPN Protocol ID, if available. Otherwise,
<code>""</code>.
</dd>
</dl>
</li>
<li>
If <var>report body</var>'s <code>phase</code> property is not
<code>dns</code> or <code>connection</code>, append the following
properties to <var>report body</var>:
<dl>
<dt><code>referrer</code></dt>
<dd>
<var>request</var>'s referrer, as determined by the <a>referrer
policy</a> associated with its [=request/client=].
</dd>
<dt><code>method</code></dt>
<dd><var>request</var>'s
<a data-cite="RFC9110#method">request method</a>.
</dd>