├── README.md └── index.html /README.md: -------------------------------------------------------------------------------- 1 | # Network Error Logging (NEL) 2 | 3 | This document defines a mechanism enabling web sites to declare a reporting policy that can be used by the user agent to report encountered network errors that prevented it from successfully loading the requested resource, the format of the error reports, and their transmission mechanism. 4 | 5 | Latest draft @ https://w3c.github.io/network-error-logging/ 6 | -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Network Error Logging 6 | 7 | 8 | 58 | 64 | 65 | 66 | 67 |
68 |

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.

69 |
70 | 71 |
72 |

73 |
74 | 75 |
76 |

Introduction

77 | 78 |

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.

79 | 80 |

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. 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.

81 | 82 |

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. To take advantage of NEL, a web application opts into using NEL by supplying a NEL HTTP response header field that describes the reporting policy. Then, if the NEL policy is available for a given origin, and an end user fails to successfully fetch a resource from that origin, the user agent logs the network error report and attempts to deliver it to the report URL defined by the policy - the delivery is done on a best effort basis and might be delayed due to connectivity issues or other reasons.

83 |
84 | 85 |
86 |

Network Error Logging

87 | 88 |
89 |

Key Concepts and Terminology

90 |
91 |
origin
92 |
Defined by the Origin specification. [[RFC6454]]
93 |
JSON object
94 |
JSON stringification
95 |
Defined in the JSON specification. [[RFC4627]]
96 |
URL
97 |
Defined by [[URL]].
98 |
99 |
100 | 101 |
102 |

Policy Delivery and Processing

103 |

The server delivers the NEL policy to the user agent via an HTTP response header field (NEL header field). If the result of executing is-origin-trusworthy algorithm ([[!POWERFUL-FEATURES]]) on origin that served the NEL policy is `Potentially Trustworthy` then the user agent MUST either:

104 | 105 | 109 | 110 |

Otherwise, if the result of the algorithm is **not** `Potentionally Trustworthy`, then the user MUST ignore the provided NEL policy.

111 | 112 |
113 |

`NEL` Header Field

114 |

The NEL header field is used to communicate the NEL policy to the user agent. The ABNF (Augmented Backus-Naur Form) syntax for the NEL header field is as follows:

115 | 116 |
117 | NEL = "NEL" ":" [ directive ]  \\\*( ";" [ directive ] )
118 | 
119 | directive                 = directive-name [ "=" directive-value ]
120 | directive-name            = token
121 | directive-value           = token | quoted-string
122 |         
123 | 124 |

See [[!RFC7230]] section 3.2.6 for definitions of `token` and `quoted-string`. This specification defines three NEL directives: report-uri, max-age, and includeSubDomains. The overall requirements for directives are:

125 | 126 |
    127 |
  • The order of appearance of directives is not significant.
  • 128 |
  • All directives MUST appear only once in an NEL header field. Directives are either optional or required, as stipulated in their definitions.
  • 129 |
  • Directive names are case-insensitive.
  • 130 |
  • User agents MUST ignore any NEL header field containing directives, or other header field value data, that does not conform to the syntax defined in this specification.
  • 131 |
  • If an NEL header field contains directive(s) not recognized by the user agent, the user agent MUST ignore the unrecognized directives, and if the NEL header field otherwise satisfies the above requirements, the user agent MUST process the recognized directives.
  • 132 |
133 | 134 |

Additional directives extending the semantic functionality of the NEL header field can be defined in other specifications, with a registry (having an IANA policy definition of IETF Review [[!RFC5226]]) defined for them at such time.

135 | 136 |

The user agent MUST ignore the NEL header specified via a meta element to mitigate hijacking of error reporting via scripting attacks. The NEL policy MUST be delivered via the NEL header field.

137 | 138 |

The restriction on meta element is consistent with [[CSP]] specification, which restricts reporting registration to HTTP header fields only for same reasons.

139 | 140 |
141 |

The `report-uri` Directive

142 |

The report-uri directive specifies a URL to which the user agent sends reports about network errors. The report-uri directive is a REQUIRED field to register an NEL policy, and OPTIONAL if the intent is to remove a previous registration - see max-age. The ABNF grammar for the name and value of the directive is:

143 | 144 |
145 | directive-name    = "report-uri"
146 | directive-value   = 1\\\*absolute-URI
147 |           
148 | 149 |

The set of report URLs is the value of the report-uri directive, which contains one or more `absolute-URI`'s - see [[!RFC3986]] section 4.3 and appendix C for definition of `absolute-URI` and delimiting recommendations.

150 | 151 |

The result of executing the is-origin-trustworthy algorithm on origin of each report URL in the provided set of report URLs MUST return `Potentially Trustworthy`. Report URL's that fail this criteria MUST be ignored by the user agent. The process of sending network error reports to the specified URL's in this directive's value is defined in this documents section.

152 | 153 |

To improve delivery of NEL reports the application should set `report-uri` to 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 `report-uri`'s to provide fallback alternatives if the preceding `report-uri` is unreachable.

154 | 155 |
156 |
157 |

The `max-age` Directive

158 |

The REQUIRED max-age directive specifies the number of seconds, after the reception of the NEL header field, during which the user agent regards the host (from whom the policy was received) as a known NEL origin. The ABNF grammar for the name and value of the directive is:

159 | 160 |
161 | directive-name    = "max-age"
162 | directive-value   = delta-seconds
163 |           
164 | 165 |

See [[!RFC7234]] section 1.2.1 for definition of `delta-seconds`. A max-age value of zero (i.e. "max-age=0") signals the user agent to cease regarding the host as a known NEL origin, including the includeSubDomains directive if provided.

166 |
167 |
168 |

The `includeSubDomains` Directive

169 |

The OPTIONAL includeSubDomains directive is a valueless directive that, if present, signals the user agent that the NEL policy applies not only to the origin that served the resource representation, but also to any origin whose host component is a subdomain of the host component of the resource representation’s origin.

170 |
171 |
172 |
173 | 174 |
175 |

Policy Storage and Maintenance

176 | 177 |

An HTTP host declares itself an NEL origin by issuing an NEL policy, which is communicated via the NEL header field from a `Potentially Trustworthy` origin. Upon error-free receipt and processing of this header by a conformant user agent, the user agent regards the host as a known NEL origin.

178 | 179 |

The user agent MUST maintain the NEL policy of any given NEL origin separately from any NEL policies issued by any other NEL origins. Only the given NEL origin can update or cause deletion of its NEL policy. This is accomplished by sending a NEL header field to the user agent with new values for the policy report URL, time duration, and subdomain applicability. Thus, the user agent MUST store the "freshest" NEL policy information on behalf of an NEL origin, and specifying a zero time duration MUST cause the user agent to delete the NEL policy (including any asserted includeSubDomains directive) for that NEL origin.

180 |
181 | 182 |
183 |

Reporting

184 | 185 |

A network error is any condition where a connection or a protocol error is encountered by the user agent, thus preventing it from successfully completing the request-response exchange. This may include, but is not limited to DNS, TCP, TLS, and HTTP connection and protocol errors. For example, a network error is triggered when the user agent:

186 | 187 | 196 | 197 |

The user agent MAY classify and report server error responses (5xx status code, [[RFC7231]]) as network errors. For example, a network error report may be triggered when a fetch fails due to proxy or gateway errors, service downtime, and other types of server errors.

198 | 199 |

The failure to fetch a resource when the user agent is known to be offline (when `navigator.onLine` returns `false`) MUST NOT be considered to be a network error.

200 | 201 |

Note that the above definition of "network error" is different from definition in [[Fetch]]. The definition of network error in this specification is a subset of [[Fetch]] definition - i.e. all of the above conditions would trigger a "network error" in [[Fetch]] processing, but conditions such as blocked requests due to mixed content, CORS failures, etc., would not.

202 | 203 |

When a network error occurs for a URL that belongs to a known NEL origin the user agent SHOULD log the error and attempt to deliver it to the report URL defined by the NEL policy of the associated NEL origin:

204 | 205 | 211 | 212 |

To generate a network error object, the user agent MUST use an algorithm equivalent to the following:

213 | 214 |
    215 |
  1. Prepare a JSON object neterror with the following keys and values: 216 | 217 |
    218 |
    uri
    219 |
    The URL that encountered the network error, with any fragment component removed.
    220 | 221 |
    referrer
    222 |
    The referrer information of the request, as determined by the Referrer policy ([[!REFERRER-POLICY]]) associated with its client.
    223 | 224 |
    server-ip
    225 |
    The IP address of the host to which the user agent sent the request, if available. Otherwise, an empty string. 226 |
      227 |
    • 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]]
    • 228 |
    • 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]]
    • 229 |
    230 |
    231 | 232 |
    protocol
    233 |
    The network protocol used to fetch the resource as identified by the ALPN Protocol ID, if available. Otherwise, an empty string.
    234 | 235 |
    status-code
    236 |
    The status-code of the HTTP response, if available. Otherwise, the number 0.
    237 | 238 |
    elapsed-time
    239 |
    The elapsed number of milliseconds between the start of the resource fetch and when it was aborted by the user agent.
    240 | 241 |
    age
    242 |
    The elapsed number of milliseconds between the time when the user agent aborted the request and when the error report is being delivered.
    243 | 244 |
    type
    245 |
    The description of the error type, which may be one the following strings: 246 | 247 |
    248 |
    dns.unreachable
    249 |
    DNS server is unreachable
    250 | 251 |
    dns.name_not_resolved
    252 |
    DNS server responded but is unable to resolve the address
    253 |
    dns.failed
    254 |
    Request to the DNS server failed due to reasons not covered by previous errors
    255 | 256 |
    257 |
    258 |
    tcp.timed_out
    259 |
    TCP connection to the server timed out
    260 | 261 |
    tcp.closed
    262 |
    The TCP connection was closed by the server
    263 | 264 |
    tcp.reset
    265 |
    The TCP connection was reset
    266 | 267 |
    tcp.refused
    268 |
    The TCP connection was refused by the server
    269 | 270 |
    tcp.aborted
    271 |
    The TCP connection was aborted
    272 | 273 |
    tcp.address_invalid
    274 |
    The IP address is invalid
    275 | 276 |
    tcp.address_unreachable
    277 |
    The IP address is unreachable
    278 | 279 |
    tcp.failed
    280 |
    The TCP connection failed due to reasons not covered by previous errors
    281 | 282 | 283 |
    284 |
    285 |
    tls.version_or_cipher_mismatch
    286 |
    The TLS connection was aborted due to version or cipher mismatch
    287 | 288 |
    tls.bad_client_auth_cert
    289 |
    The TLS connection was aborted due to invalid client certificate
    290 | 291 |
    tls.cert.name_invalid
    292 |
    The TLS connection was aborted due to invalid name
    293 | 294 |
    tls.cert.date_invalid
    295 |
    The TLS connection was aborted due to invalid certificate date
    296 | 297 |
    tls.cert.authority_invalid
    298 |
    The TLS connection was aborted due to invalid issuing authority
    299 | 300 |
    tls.cert.invalid
    301 |
    The TLS connection was aborted due to invalid certificate
    302 | 303 |
    tls.cert.revoked
    304 |
    The TLS connection was aborted due to revoked server certificate
    305 | 306 |
    tls.cert.pinned_key_not_in_cert_chain
    307 |
    The TLS connection was aborted due to a key pinning error
    308 | 309 |
    tls.protocol.error
    310 |
    The TLS connection was aborted due to a TLS protocol error
    311 | 312 |
    tls.failed
    313 |
    The TLS connection failed due to reasons not covered by previous errors
    314 | 315 |
    316 |
    317 |
    http.protocol.error
    318 |
    The connection was aborted due to an HTTP protocol error
    319 | 320 |
    http.response.invalid
    321 |
    Response is empty, has a content-length mismatch, has improper encoding, and/or other conditions that prevent user agent from processing the response
    322 | 323 |
    http.response.redirect_loop
    324 |
    The request was aborted due to a detected redirect loop
    325 | 326 |
    http.failed
    327 |
    The connection failed due to errors in HTTP protocol not covered by previous errors
    328 | 329 |
    330 |
    331 |
    abandoned
    332 |
    User aborted the resource fetch before it is complete
    333 | 334 |
    unknown
    335 |
    error type is unknown
    336 |
    337 | 338 |

    The user agent MAY extend the above error type list with custom values - e.g. new error types to accommodate new protocols, or more detailed error descriptions of existing ones. When doing so, the user agent SHOULD follow the dot-delimited pattern (`[group].[optional-subgroup].[error-name]`) to facilitate simple and consistent processing of the error reports - e.g. the collector may provide aggregation by category and/or one or multiple subgroups.

    339 |
    340 |
    341 |
  2. 342 | 343 |
  3. Return neterror.
  4. 344 |
345 | 346 |

To send network error reports, the user agent MUST use an algorithm equivalent to the following:

347 | 348 |
    349 |
  1. Prepare a JSON object report object with the following keys and values: 350 | 351 |
    352 |
    nel-report
    353 |
    An array object containing one or more network error objects.
    354 |
    355 |
  2. 356 | 357 |
  3. Let report body be the JSON stringification of the report object.
  4. 358 | 359 |
  5. For each report URL in the set of report URLs: 360 | 361 |
      362 |
    1. Queue a task to fetch report URL using HTTP method POST, with a `Content-Type` header field of `application/nel-report`, and an entity body consisting of report body. If the origin of report URL is not the same as the origin of the NEL origin for which the report is generated, the block cookies flag MUST also be set. The task source for these tasks is the Network Error Logging task source.
    2. 363 | 364 |
    3. If the fetch is successful (2xx HTTP response code), the user agent MUST abort the remaining steps.
    4. 365 | 366 |
    5. If the fetch failed with a 410 Gone HTTP response code ([[RFC7231]]), the user agent MUST update the NEL policy by removing the current report URL from the set of report URLs.
    6. 367 | 368 |
    7. If the fetch failed after multiple delivery attempts the user agent MAY update the NEL policy by removing the current report URL from the set of report URLs. 369 | 370 |

      The user agent is allowed to garbage collect report-uri's that are no longer functional, but it should account for common failure cases such as captive portals, which may temporarily prevent it from delivering the error reports. The exact implementation logic is deferred to the user-agent, which may use own mechanisms and heuristics to detect such cases.

      371 |
    8. 372 | 373 |
    9. If the NEL policy was updated and the new NEL policy contains an empty set of report URLs the user agent MUST remove the NEL policy and abort the remaining steps.
    10. 374 | 375 |
    11. If the user agent has reached the end of the set of report URLs, the user agent MUST sleep before returning to the beginning of the set and reattempting delivery - e.g. use exponential backoff. Otherwise, the user agent MUST attempt immediate delivery of the error report to the next report URL in the set of report URLs.
    12. 376 |
    377 |
378 |
379 | 380 |
381 |

Examples

382 |
383 |

Sample Policy Definitions

384 |
385 | > GET / HTTP/1.1
386 | > Host: example.com
387 | 
388 | < HTTP/1.1 200 OK
389 | < ...
390 | < NEL: report-uri="https://example.com/report"; max-age=2592000
391 |         
392 | 393 |

The above NEL policy provided in the server response specifies that the user agent should register a new NEL policy, or update an existing one if one already exists, for the `example.com` NEL origin: the user agent should report network errors to `https://example.com/report` and the policy applies for 2592000 seconds (30 days).

394 | 395 |

Note that above registration will only succeed if the response is communicated from a `Potentially Trustworthy` origin - see . 396 | 397 |

398 | > GET / HTTP/1.1
399 | > Host: example.com
400 | 
401 | < HTTP/1.1 200 OK
402 | < ...
403 | < NEL: report-uri="https://other-origin.com/report"; max-age=2592000
404 |         
405 | 406 |

The above NEL policy provided in the server response is similar to the previous example but tells the user agent to report network errors to `https://other-origin.com/report`. The use of an alternative origin that is not coupled with the origin that is being accessed is **strongly encouraged** to enable real-time reporting and improved report delivery - see .

407 | 408 |
409 | > GET / HTTP/1.1
410 | > Host: example.com
411 | 
412 | < HTTP/1.1 200 OK
413 | < ...
414 | < NEL: report-uri="https://example.com/report" "https://other-origin.com/report"; max-age=2592000; includeSubDomains
415 |         
416 | 417 |

The above NEL policy provided in the server response specifies that the user agent should report network errors to `https://example.com/report`, or `https://other-origin.com/report` if the former is unreachable. Further, the policy is extended to all of the subdomains of the issuing NEL origin - see .

418 | 419 |
420 | > GET / HTTP/1.1
421 | > Host: example.com
422 | 
423 | < HTTP/1.1 200 OK
424 | < ...
425 | < NEL: max-age=0
426 |         
427 | 428 |

The above NEL policy provided in the server response contains max-age set to zero, which indicates that the user agent must delete the current registered NEL policy associated with the `example.com` NEL origin and all of its subdomains:

429 | 433 |
434 | 435 |
436 |

Sample Network Error Reports

437 |

This section contains an example network error report the user agent might send when a network error is encountered for a known NEL origin.

438 | 439 |
440 | {
441 |         "nel-report": [
442 |             {
443 |               "uri": "https://www.example.com/",
444 |               "referrer": "http://example.com/",
445 |               "server-ip": "123.122.121.120",
446 |               "protocol": "h2-15",
447 |               "status-code": 200,
448 |               "elapsed-time": 823,
449 |               "age": 0,
450 |               "type": "http.protocol.error"
451 |             }
452 |           ]
453 |         }
454 |         
455 | 456 |

The above report indicates that the user agent attempted to navigate from "example.com" to "www.example.com" (known NEL origin), which successfully resolved to the "123.122.121.120" IP address. However, while the user agent received a "200" response from the server via the "h2-15" protocol, it encountered a protocol error in the exchange and was forced to abandon the navigation. 823 milliseconds elapsed between the start of navigation and when the user agent aborted the navigation. Finally, the user agent sent this report immediately after the network error was encountered - i.e. the report age is 0.

457 | 458 |
459 | {
460 |         "nel-report": [
461 |             {
462 |               "uri": "https://widget.com/thing.js",
463 |               "referrer": "https://www.example.com/",
464 |               "server-ip": "234.233.232.231",
465 |               "protocol": "",
466 |               "status-code": 0,
467 |               "elapsed-time": 143,
468 |               "age": 0,
469 |               "type": "http.dns.name_not_resolved"
470 |             }
471 |           ]
472 |         }
473 |         
474 | 475 |

The above report indicates that the user agent attempted to fetch "https://widget.com/thing.js", which belongs to a previously registered NEL origin, from "www.example.com" origin. However, the user agent was unable to resolve the DNS name and the request was aborted by the user agent after 143 milliseconds. Because "widget.com" is a known NEL origin, a network error report was logged and sent to the report URL specified by the NEL policy of that host immediately after the network error was encountered - i.e. the report age is 0.

476 |
477 |
478 | 479 |
480 |

Use cases

481 | 482 |
483 |

Reporting of Navigation Failures

484 | 485 |

A navigation request initiated by the user (e.g. via a click on a link, direct input via the location bar, script-initiated due to user interaction, etc.) may fail due any number of connectivity reasons: DNS failure, TCP error, TLS protocol violation, and so on. These errors may be caused by network misconfiguration, transient routing issues, server downtime, malware or other attacks against the user, etc.

486 | 487 |

In such cases the destination host is often left unaware of the failed navigation since, by definition, it cannot see the request reach its infrastructure and it is unable to investigate the problem. To address this, the host can register an NEL policy with the user agent, which specifies where reports of such failures should be delivered such that they can be investigated.

488 |
489 | 490 |
491 |

Reporting of First-party Subresource Fetch Failures

492 | 493 |

A typical application requires dozens of resources, the fetching of which is typically initiated via HTML, CSS, or JavaScript. The application requesting such resources can observe failures of most such fetches (e.g. via `onerror` callbacks), but it does not have access to the detailed network error report of why the failure has occurred - e.g. DNS failure, TCP error, TLS protocol violation, etc.

494 | 495 |

To address this, the application can register relevant NEL policies with the user agent for the first-party hosts from which the subresources are being fetched. Then, if such a policy is present and a network error is encountered for a resource associated with a registered NEL origin, the user agent will report the detailed network error report and enable the application developers to investigate the error.

496 |
497 | 498 |
499 |

Reporting of Third-party Subresource Fetch Failures

500 | 501 |

In the case where a resource is embedded by a third party, the provider of the resource is often unable to instrument and observe the failure. For example, if `example.com` embeds a `widget.com/thing.js` resource on its site, and the user visiting `example.com` fails to fetch such resource due to a network error, the `widget.com` host is both unaware of the failure and unable to detect it.

502 | 503 |

To address this, `widget.com` can register an NEL policy for its host. Then, if such policy is present and a network error is encountered while fetching a resource — regardless of whether it is being requested from a first-party or third-party origin — from the registered NEL origin, the user agent will report the network error and enable the provider to investigate the error.

504 |
505 |
506 | 507 |
508 |

Privacy Considerations

509 | 510 |

NEL provides network error reports that could expose new information about the user's network configuration. For example, an attacker could abuse NEL reporting to probe users network configuration. Also, similar to HSTS, HPKP, and pinned CSP policies, the stored NEL policy could be used as a "supercookie" by setting a distinct policy with a custom (per-user) reporting URI to act as an identififer in combination with (or instead of) HTTP cookies.

511 | 512 |

To mitigate some of the above risks, NEL registration is restricted to trustworthy origins, and delivery of network error reports is similarly restricted to trustworthy origins. This disallows a transient HTTP MITM from trivially abusing NEL as a persistent tracker.

513 | 514 |

In addition to above restrictions, the user agents MUST:

515 | 516 |

520 |
521 | 522 |
523 |

IANA Considerations

524 |

... TODO ...

525 |
526 |
527 | 528 |
529 |

Acknowledgments

530 |

This document reuses text from the [[CSP]] and [[RFC6797]] specification, as permitted by the licenses of those specifications. Additionally, sincere thanks to Thomas Tuttle, Chris Bentzel, Todd Reifsteck, and Aaron Heady for their helpful comments and contributions to this work.

531 |
532 | 533 | 534 | 535 | --------------------------------------------------------------------------------