RFC 9530

Digest Fields

๐Ÿ“… published February 2024, from ietf

Digest Fields ๐ŸŽ€

  • RFC: 9530 โœจ
  • Series: Internet Engineering Task Force (IETF) ๐ŸŒธ
  • Authors: R. Polli (Team Digitale, Italian Government) and L. Pardue (Cloudflare) ๐Ÿ’…
  • Category: Standards Track ๐Ÿ‘‘
  • ISSN: 2070-1721
  • Date: February 2024 ๐Ÿฆ‹
  • Obsoletes: RFC 3230 (the original Digest and Want-Digest HTTP fields) ๐Ÿ’€
  • Updates: nothing ๐Ÿซถ

Abstract

okay bestie, so this doc defines HTTP fields for integrity digests ๐Ÿ”โœจ Content-Digest covers the integrity of HTTP message content, and Repr-Digest covers the integrity of HTTP representations. Then there are Want-Content-Digest and Want-Repr-Digest, which let a sender say "yes pls, I want those" and also share what kind of digest they prefer ๐Ÿ’–

This document obsoletes RFC 3230 and the Digest and Want-Digest HTTP fields. Bye bye, old ones ๐Ÿ‘‹๐Ÿ“


Status of This Memo

This is an Internet Standards Track document. ๐Ÿ‘‘

This document is a product of the Internet Engineering Task Force (IETF). It represents the consensus of the IETF community. It got public review and was approved for publication by the Internet Engineering Steering Group (IESG). If you want more info on Internet Standards, check out Section 2 of RFC 7841 ๐Ÿงš

Info about the current status of this document, any errata, and how to send feedback lives at https://www.rfc-editor.org/info/rfc9530 ๐Ÿ”—


Copyright (c) 2024 IETF Trust and the persons identified as the document authors. All rights reserved. ๐Ÿ’œ

This document is subject to BCP 78 and the IETF Trust's Legal Provisions Relating to IETF Documents (https://trustee.ietf.org/license-info) as in effect on the date this document was published. Please read these carefully, because they describe your rights and restrictions with respect to this document. Code Components pulled out of this document must include Revised BSD License text as described in Section 4.e of the Trust Legal Provisions, and they come without warranty as described in the Revised BSD License ๐ŸŒˆ


Table of Contents ๐Ÿ“‹

1.  Introduction
  1.1.  Document Structure
  1.2.  Concept Overview
  1.3.  Obsoleting RFC 3230
  1.4.  Notational Conventions
2.  The Content-Digest Field
3.  The Repr-Digest Field
  3.1.  Using Repr-Digest in State-Changing Requests
  3.2.  Repr-Digest and Content-Location in Responses
4.  Integrity Preference Fields
5.  Hash Algorithm Considerations and Registration
6.  Security Considerations
  6.1.  HTTP Messages Are Not Protected in Full
  6.2.  End-to-End Integrity
  6.3.  Usage in Signatures
  6.4.  Usage in Trailer Fields
  6.5.  Variations within Content-Encoding
  6.6.  Algorithm Agility
  6.7.  Resource Exhaustion
7.  IANA Considerations
  7.1.  HTTP Field Name Registration
  7.2.  Creation of the Hash Algorithms for HTTP Digest Fields
        Registry
  7.3.  Deprecate the Hypertext Transfer Protocol (HTTP) Digest
        Algorithm Values Registry
8.  References
  8.1.  Normative References
  8.2.  Informative References
Appendix A.  Resource Representation and Representation Data
Appendix B.  Examples of Unsolicited Digest
  B.1.  Server Returns Full Representation Data
  B.2.  Server Returns No Representation Data
  B.3.  Server Returns Partial Representation Data
  B.4.  Client and Server Provide Full Representation Data
  B.5.  Client Provides Full Representation Data and Server
         Provides No Representation Data
  B.6.  Client and Server Provide Full Representation Data
  B.7.  POST Response Does Not Reference the Request URI
  B.8.  POST Response Describes the Request Status
  B.9.  Digest with PATCH
  B.10. Error Responses
  B.11. Use with Trailer Fields and Transfer Coding
Appendix C.  Examples of Want-Repr-Digest Solicited Digest
  C.1.  Server Selects Client's Least Preferred Algorithm
  C.2.  Server Selects Algorithm Unsupported by Client
  C.3.  Server Does Not Support Client Algorithm and Returns an
        Error
Appendix D.  Sample Digest Values
Appendix E.  Migrating from RFC 3230
Acknowledgements
Authors' Addresses

1. Introduction ๐ŸŒท

okay so HTTP doesn't actually define a way to protect the data integrity of content or representations ๐Ÿ˜ญ When HTTP messages go between endpoints, lower-layer stuff like TCP checksums or TLS records [TLS] can give some integrity protection. BUT transport-level integrity is kinda limited, because the application layer can't see it and it only covers one connection. HTTP messages often hop over a whole chain of separate connections, and corruption can sneak in between them ๐Ÿ™ˆ An HTTP integrity mechanism gives endpoints (or apps using HTTP) a way to spot data corruption and decide what to do about it. A classic use case is helping with fault detection and diagnosis across system boundaries โœจ

This document defines two digest integrity mechanisms for HTTP. The first is content integrity, which acts on conveyed content (Section 6.4 of [HTTP]). The second is representation data integrity, which acts on representation data (Section 8.1 of [HTTP]). This is giving advanced energy, because it supports stuff like checking the integrity of a resource that was rebuilt from parts pulled down with multiple requests or connections ๐Ÿงฉ๐Ÿ’…

This document obsoletes [RFC3230] and therefore the Digest and Want-Digest HTTP fields; see Section 1.3 ๐Ÿ“

1.1. Document Structure

This document is structured as follows:

  • New request and response header and trailer field definitions:
    • Section 2 (Content-Digest),
    • Section 3 (Repr-Digest), and
    • Section 4 (Want-Content-Digest and Want-Repr-Digest).
  • Considerations specific to representation data integrity:
    • Section 3.1 (State-changing requests),
    • Section 3.2 (Content-Location),
    • Appendix A contains worked examples of representation data in message exchanges, and
    • Appendixes B and C contain worked examples of Repr-Digest and Want-Repr-Digest fields in message exchanges.
  • Section 5 presents hash algorithm considerations and defines registration procedures for future entries.

1.2. Concept Overview

The HTTP fields defined in this document can be used for HTTP integrity ๐Ÿฆ‹ Senders pick a hashing algorithm and calculate a digest from an input related to the HTTP message. The algorithm identifier and the digest get sent in an HTTP field. Receivers can validate the digest for integrity purposes. Hashing algorithms are registered in the "Hash Algorithms for HTTP Digest Fields" registry (see Section 7.2) ๐Ÿ“‹

Which data the digests get calculated over depends on the use case of the HTTP messages. This document gives you different fields for HTTP representation data and for HTTP content ๐Ÿ’–

When you need a simple digest of the HTTP content bytes, the Content-Digest request and response header and trailer field is defined to support digests of content (Section 6.4 of [HTTP]); see Section 2 โœจ

For the more advanced stuff, there's the Repr-Digest request and response header and trailer field (Section 3). It holds a digest value computed by applying a hashing algorithm to selected representation data (Section 8.1 of [HTTP]). Basing Repr-Digest on the selected representation makes it way easier to handle cases where the message content needs some manipulation to count as a representation of the resource, or where the content carries a partial representation of a resource, like with range requests (see Section 14 of [HTTP]) ๐Ÿงš

Content-Digest and Repr-Digest both support hashing algorithm agility. The Want-Content-Digest and Want-Repr-Digest fields let endpoints express interest in Content-Digest and Repr-Digest, respectively, and also share algorithm preferences for either one ๐ŸŒˆ

Content-Digest and Repr-Digest are collectively called "Integrity fields". Want-Content-Digest and Want-Repr-Digest are collectively called "Integrity preference fields" ๐Ÿซถ

Integrity fields are tied to the Content-Encoding and Content-Type header fields. So a given resource can have several different digest values when it's transferred with HTTP ๐Ÿ‘€

Integrity fields apply to HTTP message content or HTTP representations. They don't apply to HTTP messages or fields themselves. BUT they can be combined with other mechanisms that protect metadata, like digital signatures, to protect the phases of an HTTP exchange in whole or in part. For example, HTTP Message Signatures [SIGNATURES] could be used to sign Integrity fields, which gives coverage for HTTP content or representation data ๐Ÿ”ฅ

This specification does not define means for authentication, authorization, or privacy ๐Ÿ™…โ€โ™€๏ธ

1.3. Obsoleting RFC 3230

[RFC3230] defined the Digest and Want-Digest HTTP fields for HTTP integrity. It also coined the terms "instance" and "instance manipulation" to explain concepts, like selected representation data (Section 8.1 of [HTTP]), that are now more universally defined and implemented as HTTP semantics ๐Ÿฐ

Experience has shown that implementations of [RFC3230] have interpreted the meaning of "instance" inconsistently, and that caused interoperability issues ๐Ÿ˜ฉ The most common issue is calculating the digest over (what we now call) message content, instead of over (what we now call) representation data like was originally intended. Here's the twist: time has also shown that a digest of message content can be useful for some use cases, so it's hard to tell whether non-conformance to [RFC3230] was intentional or not ๐Ÿคทโ€โ™€๏ธ

To clear up the potential inconsistencies and ambiguity across implementations of Digest and Want-Digest, this document obsoletes [RFC3230]. The Integrity fields (Sections 2 and 3) and Integrity preference fields (Section 4) defined here line up better with current HTTP semantics, and their names more clearly say what they're for ๐Ÿ’œ

1.4. Notational Conventions ๐Ÿ“šโœจ

Okay bestie, let's lock in the vocab first ๐Ÿงš The BCP 14 key words in this doc are "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "NOT RECOMMENDED", "MAY", and "OPTIONAL". They only get the BCP 14 treatment [RFC2119] [RFC8174] when they're written in ALL CAPS, just like I'm doing right now ๐Ÿ’…

This doc uses the Augmented BNF from [RFC5234], which got updated by [RFC7405] ๐ŸŽ€ It gives us the rules CR (carriage return), LF (line feed), and CRLF (CR LF), so you can't be confused about line endings ๐Ÿ™ˆ

Next, the doc borrows some terms from Section 3 of [STRUCTURED-FIELDS] for syntax and parsing: Boolean, Byte Sequence, Dictionary, Integer, and List. Iconic, right? ๐Ÿ‘‘

The words "representation", "selected representation", "representation data", "representation metadata", "user agent", and "content" mean whatever [HTTP] says they mean. No new meanings here, no drama ๐Ÿฆ‹

This doc also uses the line folding strategies from [FOLDING] ๐ŸŒธ

Hashing algorithm names keep the casing from their own definition document (e.g., SHA-1, CRC32c). Respect the names, bestie ๐Ÿ’–

HTTP messages name hashing algorithms with an Algorithm Key (algorithms). When the doc talks about an Algorithm Key in prose, it's put in quotes (e.g., "sha", "crc32c") โœจ

Here's a fun distinction: "checksum" is the output of running an algorithm over a sequence of bytes, while "digest" is only used for the value that lives inside the fields ๐Ÿง

"Integrity fields" is the group name for Content-Digest and Repr-Digest ๐Ÿ›ก๏ธ

"Integrity preference fields" is the group name for Want-Repr-Digest and Want-Content-Digest ๐Ÿ“

2. The Content-Digest Field ๐ŸŽ€

Okay so the Content-Digest HTTP field can show up in requests and responses to carry digests calculated with a hashing algorithm over the actual message content (see Section 6.4 of [HTTP]). It's a Dictionary (see Section 3.2 of [STRUCTURED-FIELDS]), where each:

  • key tells you which hashing algorithm (see Section 5) was used to compute the digest;
  • value is a Byte Sequence (Section 3.3.5 of [STRUCTURED-FIELDS]) holding an encoded version of the byte output from the digest calculation.

Here's a little example, bestie ๐ŸŒˆ

NOTE: '' line wrapping per RFC 8792

Content-Digest: \
  sha-512=:YMAam51Jz/jOATT6/zvHrLVgOYTGFy1d6GJiOHTohq4yP+pgk4vf2aCs\
  yRZOtw8MjkM7iw7yZ/WkppmM44T3qg==:

The Dictionary type is super handy because you can attach multiple digests, each made with a different hashing algorithm. That helps you support a whole crowd of endpoints with different or changing capabilities ๐Ÿงš It could also help with moving away from weaker algorithms (see Section 6.6) ๐Ÿ’…

NOTE: '' line wrapping per RFC 8792

Content-Digest: \
  sha-256=:d435Qo+nKZ+gLcUHn7GQtQ72hiBVAgqoLsZnZPiTGPk=:,\
  sha-512=:YMAam51Jz/jOATT6/zvHrLVgOYTGFy1d6GJiOHTohq4yP+pgk4vf2aCs\
  yRZOtw8MjkM7iw7yZ/WkppmM44T3qg==:

A recipient MAY ignore any or all digests ๐Ÿ™ƒ Application-specific behavior or local policy MAY set additional constraints on how the conveyed digests get processed and validated ๐Ÿ” The security considerations cover some of the issues with ignoring digests (see Section 6.6) and with validating multiple digests (see Section 6.7). Read those, they're serious ๐Ÿ˜ญ

A sender MAY send a digest without knowing whether the recipient supports a given hashing algorithm. A sender MAY send a digest if it knows the recipient will ignore it ๐Ÿซถ

Content-Digest can be sent in a trailer section. In that case, Content-Digest MAY be merged into the header section; see Section 6.5.1 of [HTTP] ๐Ÿฆ‹

3. The Repr-Digest Field ๐Ÿฆ‹

Okay so the Repr-Digest HTTP field can show up in requests and responses to carry digests calculated with a hashing algorithm over the entire selected representation data (see Section 8.1 of [HTTP]) ๐Ÿ’–

Representations take the effect of HTTP semantics into account. For example, range requests or methods like HEAD can change the content, while the way the content travels "on the wire" depends on other transformations (e.g., transfer codings for HTTP/1.1; see Section 6.1 of [HTTP/1.1]) ๐ŸŒธ To help illustrate these HTTP representation concepts, Appendix A has several examples โœจ

When a message has no representation data, you can still assert that no representation data was sent by computing the digest over an empty string (see Section 6.3). Lowkey clever ๐Ÿง 

Repr-Digest is a Dictionary (see Section 3.2 of [STRUCTURED-FIELDS]), where each:

  • key tells you which hashing algorithm (see Section 5) was used to compute the digest;
  • value is a Byte Sequence that holds an encoded version of the byte output from the digest calculation.

For example ๐ŸŽ€

NOTE: '' line wrapping per RFC 8792

Repr-Digest: \
  sha-512=:YMAam51Jz/jOATT6/zvHrLVgOYTGFy1d6GJiOHTohq4yP+pgk4vf2aCs\
  yRZOtw8MjkM7iw7yZ/WkppmM44T3qg==:

The Dictionary type can be used to attach multiple digests calculated with different hashing algorithms, so a population of endpoints with different or evolving capabilities can all be supported ๐ŸŒˆ Such an approach could support transitions away from weaker algorithms (see Section 6.6) ๐Ÿ’…

NOTE: '' line wrapping per RFC 8792

Repr-Digest: \
  sha-256=:d435Qo+nKZ+gLcUHn7GQtQ72hiBVAgqoLsZnZPiTGPk=:,\
  sha-512=:YMAam51Jz/jOATT6/zvHrLVgOYTGFy1d6GJiOHTohq4yP+pgk4vf2aCs\
  yRZOtw8MjkM7iw7yZ/WkppmM44T3qg==:

A recipient MAY ignore any or all digests. Application-specific behavior or local policy MAY set additional constraints on the processing and validation practices of the conveyed digests. The security considerations cover some of the issues related to ignoring digests (see Section 6.6) and validating multiple digests (see Section 6.7) ๐Ÿ˜ญ

A sender MAY send a digest without knowing whether the recipient supports a given hashing algorithm. A sender MAY send a digest if it knows the recipient will ignore it ๐Ÿซถ

Repr-Digest can be sent in a trailer section. In that case, Repr-Digest MAY be merged into the header section; see Section 6.5.1 of [HTTP] โœจ

3.1. Using Repr-Digest in State-Changing Requests ๐Ÿ”ฅ

When the representation enclosed in a state-changing request does not describe the target resource, the representation digest MUST be computed on the representation data. Honestly this is the only possible choice, because the representation digest needs complete representation metadata (see Section 3) ๐Ÿ’€

In responses:

  • if the representation describes the status of the request, Repr-Digest MUST be computed on the enclosed representation (see Appendix B.8);
  • if there is a referenced resource, Repr-Digest MUST be computed on the selected representation of the referenced resource, even if that's different from the target resource. This might or might not end up computing Repr-Digest on the enclosed representation.

The latter case follows the HTTP semantics of the given method, for example using the Content-Location header field (see Section 8.7 of [HTTP]). In contrast, the Location header field does not affect Repr-Digest, because it isn't representation metadata ๐Ÿ™ˆ

For example, in PATCH requests, the representation digest is computed on the patch document, because the representation metadata refers to the patch document and not the target resource (see Section 2 of [PATCH]). In responses, instead, the representation digest is computed on the selected representation of the patched resource ๐Ÿ‘‘

3.2. Repr-Digest and Content-Location in Responses ๐Ÿฆ‹

When a state-changing method returns the Content-Location header field, the enclosed representation refers to the resource identified by its value, and Repr-Digest is computed accordingly. An example is given in Appendix B.7 ๐Ÿงš

4. Integrity Preference Fields ๐Ÿ’…

Senders can show their interest in Integrity fields and hashing algorithm preferences using the Want-Content-Digest or Want-Repr-Digest HTTP fields. These can be used in both requests and responses ๐Ÿซถ

Want-Content-Digest says the sender would like to receive a content digest (via the Content-Digest field) on messages associated with the request URI and representation metadata. Want-Repr-Digest says the sender would like to receive a representation digest (via the Repr-Digest field) on messages associated with the request URI and representation metadata ๐Ÿ’–

If Want-Content-Digest or Want-Repr-Digest is used in a response, it means the server would like the client to provide the respective Integrity field on future requests ๐ŸŒธ

Integrity preference fields are only a hint! The receiver can ignore them and send an Integrity field using any algorithm, or leave the field out entirely (for example, see Appendix C.2). It is not a protocol error if preferences get ignored. Applications that use Integrity fields and Integrity preferences can define expectations or constraints that work in addition to this specification. Ignored preferences are an application-specific concern ๐Ÿ™ƒ

Want-Content-Digest and Want-Repr-Digest are of type Dictionary, where each:

  • key conveys the hashing algorithm (see Section 5);
  • value is an Integer (Section 3.3.1 of [STRUCTURED-FIELDS]) that conveys an ascending, relative, weighted preference. It must be in the range 0 to 10 inclusive. 1 is the least preferred, 10 is the most preferred, and a value of 0 means "not acceptable" ๐Ÿ“

Examples ๐ŸŒˆ

Want-Repr-Digest: sha-256=1
Want-Repr-Digest: sha-512=3, sha-256=10, unixsum=0
Want-Content-Digest: sha-256=1
Want-Content-Digest: sha-512=3, sha-256=10, unixsum=0

5. Hash Algorithm Considerations and Registration โœจ

okay so there are SO many hashing algorithms out there ๐Ÿง and which one you pick for integrity depends on a bunch of stuff: your use case, what your implementation can handle or is limited by, and how your app is designed and flows. no one-size-fits-all moment here, bestie ๐Ÿ’…

An initial set of algorithms will be registered with IANA in the "Hash Algorithms for HTTP Digest Fields" registry; see Section 7.2. Additional algorithms can be registered in accordance with the policies set out in this section.

Each algorithm has a status field, and it's basically there to help you pick which algorithm to implement ๐ŸŽ€

Algorithms with a status value of "Active" are suitable for many purposes and it is RECOMMENDED that applications use these algorithms. These can be used in adversarial situations where hash functions might need to provide resistance to collision, first-preimage, and second-preimage attacks. For adversarial situations, selection of the acceptable "Active" algorithms will depend on the level of protection the circumstances demand. More considerations are presented in Section 6.6. ๐Ÿ”ฅ

Algorithms with a status value of "Deprecated" either provide none of these properties or are known to be weak (see [NO-MD5] and [NO-SHA]). These algorithms MAY be used to preserve integrity against corruption, but MUST NOT be used in a potentially adversarial setting, for example, when signing Integrity fields' values for authenticity. ๐Ÿ’€ Permitting the use of these algorithms can help some applications (such as those that previously used [RFC3230], are migrating to this specification (Appendix E), and have existing stored collections of computed digest values) avoid undue operational overhead caused by recomputation using other more-secure algorithms. Such applications are not exempt from the requirements in this section. Furthermore, applications without such legacy or history ought to follow the guidance for using algorithms with the status value "Active". ๐Ÿงš

Discussion of algorithm agility is presented in Section 6.6. ๐Ÿฆ‹

Registration requests for the "Hash Algorithms for HTTP Digest Fields" registry use the Specification Required policy (Section 4.6 of [RFC8126]). Requests should use the following template:

   Algorithm Key:  The Structured Fields key value used in Content-
      Digest, Repr-Digest, Want-Content-Digest, or Want-Repr-Digest
      field Dictionary member keys.

   Status:  The status of the algorithm.  The options are:

      "Active":  Algorithms without known problems

      "Provisional":  Unproven algorithms

      "Deprecated":  Deprecated or insecure algorithms

   Description:  A short description of the algorithm.

   Reference(s):  Pointer(s) to the primary document(s) defining the
      Algorithm Key and technical details of the algorithm.

When reviewing registration requests, the designated expert(s) should pay attention to the requested status. The status value should reflect standardization status and the broad opinion of relevant interest groups such as the IETF or security-related Standards Development Organizations (SDOs). The "Active" status is not suitable for an algorithm that is known to be weak, broken, or experimental. If a registration request attempts to register such an algorithm as "Active", the designated expert(s) should suggest an alternative status of "Deprecated" or "Provisional". ๐Ÿ‘€

When reviewing registration requests, the designated expert(s) cannot use a status of "Deprecated" or "Provisional" as grounds for rejection.

Requests to update or change the fields in an existing registration are permitted. For example, this could allow for the transition of an algorithm status from "Active" to "Deprecated" as the security environment evolves. ๐ŸŒˆ


6. Security Considerations ๐Ÿ”’

6.1. HTTP Messages Are Not Protected in Full ๐Ÿ™ˆ

This document specifies a data integrity mechanism that protects HTTP representation data or content, but not HTTP header and trailer fields, from certain kinds of corruption.

Integrity fields are not intended to be a general protection against malicious tampering with HTTP messages. In the absence of additional security mechanisms, an on-path malicious actor can either remove a digest value entirely or substitute it with a new digest value computed over manipulated representation data or content. This attack can be mitigated by combining mechanisms described in this document with other approaches such as Transport Layer Security (TLS) or digital signatures (for example, HTTP Message Signatures [SIGNATURES]).

โš ๏ธ bestie, this is the big one: an on-path attacker can straight up delete a digest or swap in a brand new one for tampered content. so you NEED TLS or signatures on top, or the digest alone won't save you ๐Ÿ˜ญ

6.2. End-to-End Integrity ๐Ÿ›ค๏ธ

Integrity fields can help detect representation data or content modification due to implementation errors, undesired "transforming proxies" (see Section 7.7 of [HTTP]), or other actions as the data passes across multiple hops or system boundaries. Even a simple mechanism for end-to-end representation data integrity is valuable because a user agent can validate that resource retrieval succeeded before handing off to an HTML parser, video player, etc., for parsing. ๐ŸŽฌ

Note that using these mechanisms alone does not provide end-to-end integrity of HTTP messages over multiple hops since metadata could be manipulated at any stage. Methods to protect metadata are discussed in Section 6.3.

6.3. Usage in Signatures โœ๏ธ

Digital signatures are widely used together with checksums to provide the certain identification of the origin of a message [FIPS186-5]. Such signatures can protect one or more HTTP fields and there are additional considerations when Integrity fields are included in this set.

There are no restrictions placed on the type or format of digital signature that Integrity fields can be used with. One possible approach is to combine them with HTTP Message Signatures [SIGNATURES].

Digests explicitly depend on the "representation metadata" (e.g., the values of Content-Type, Content-Encoding, etc.). A signature that protects Integrity fields but not other "representation metadata" can expose the communication to tampering. For example, an actor could manipulate the Content-Type field-value and cause a digest validation failure at the recipient, preventing the application from accessing the representation. Such an attack consumes the resources of both endpoints. See also Section 3.2.

Signatures are likely to be deemed an adversarial setting when applying Integrity fields; see Section 5. Repr-Digest offers an interesting possibility when combined with signatures. In the scenario where there is no content to send, the digest of an empty string can be included in the message and, if signed, can help the recipient detect if content was added either as a result of accident or purposeful manipulation. The opposite scenario is also supported; including an Integrity field for content and signing it can help a recipient detect where the content was removed. ๐Ÿง

Any mangling of Integrity fields might affect signature validation. Examples of such mangling include de-duplicating digests or combining different field values (see Section 5.2 of [HTTP]).

6.4. Usage in Trailer Fields ๐Ÿงพ

Before sending Integrity fields in a trailer section, the sender should consider that intermediaries are explicitly allowed to drop any trailer (see Section 6.5.2 of [HTTP]).

When Integrity fields are used in a trailer section, the field-values are received after the content. Eager processing of content before the trailer section prevents digest validation, possibly leading to processing of invalid data. ๐Ÿšซ

One of the benefits of using Integrity fields in a trailer section is that it allows hashing of bytes as they are sent. However, it is possible to design a hashing algorithm that requires processing of content in such a way that would negate these benefits. For example, Merkle Integrity Content Encoding [MICE] requires content to be processed in reverse order. This means the complete data needs to be available, which means there is negligible processing difference in sending an Integrity field in a header versus a trailer section. ๐Ÿคทโ€โ™€๏ธ

6.5. Variations within Content-Encoding ๐ŸŒ€

Content coding mechanisms can support different encoding parameters, meaning that the same input content can produce different outputs. For example, GZIP supports multiple compression levels. Such encoding parameters are generally not communicated as representation metadata. For instance, different compression levels would all use the same "Content-Encoding: gzip" field. Other examples include where encoding relies on nonces or timestamps, such as the aes128gcm content coding defined in [RFC8188].

Since it is possible for there to be variation within content coding, the checksum conveyed by the Integrity fields cannot be used to provide a proof of integrity "at rest" unless the whole content is persisted. ๐Ÿ’พ

6.6. Algorithm Agility ๐Ÿ”„

The security properties of hashing algorithms are not fixed. Algorithm agility (see [RFC7696]) is achieved by providing implementations with flexibility to choose hashing algorithms from the IANA Hash Algorithms for HTTP Digest Fields registry; see Section 7.2.

Transition from weak algorithms is supported by negotiation of hashing algorithm using Want-Content-Digest or Want-Repr-Digest (see Section 4) or by sending multiple digests from which the receiver chooses. A receiver that depends on a digest for security will be vulnerable to attacks on the weakest algorithm it is willing to accept. Endpoints are advised that sending multiple values consumes resources that may be wasted if the receiver ignores them (see Section 3). ๐Ÿฅ€

While algorithm agility allows the migration to stronger algorithms, it does not prevent the use of weaker algorithms. Integrity fields do not provide any mitigations for downgrade or substitution attacks (see Section 1 of [RFC6211]) of the hashing algorithm. To protect against such attacks, endpoints could restrict their set of supported algorithms to stronger ones and protect the fields' values by using TLS and/or digital signatures. ๐Ÿ›ก๏ธ

6.7. Resource Exhaustion ๐Ÿฅต

Integrity field validation consumes computational resources. In order to avoid resource exhaustion, implementations can restrict validation of the algorithm types, the number of validations, or the size of content. In these cases, skipping validation entirely or ignoring validation failure of a more-preferred algorithm leaves the possibility of a downgrade attack (see Section 6.6). ๐Ÿ“‰


7. IANA Considerations ๐Ÿ“‹

7.1. HTTP Field Name Registration ๐Ÿ’…

okay so IANA went and updated the "Hypertext Transfer Protocol (HTTP) Field Name Registry" [HTTP] ๐Ÿ‘€ here's the whole glow-up in one table:

    +=====================+===========+========================+
    | Field Name          | Status    | Reference              |
    +=====================+===========+========================+
    | Content-Digest      | permanent | Section 2 of RFC 9530  |
    +---------------------+-----------+------------------------+
    | Repr-Digest         | permanent | Section 3 of RFC 9530  |
    +---------------------+-----------+------------------------+
    | Want-Content-Digest | permanent | Section 4 of RFC 9530  |
    +---------------------+-----------+------------------------+
    | Want-Repr-Digest    | permanent | Section 4 of RFC 9530  |
    +---------------------+-----------+------------------------+
    | Digest              | obsoleted | [RFC3230], Section 1.3 |
    |                     |           | of RFC 9530            |
    +---------------------+-----------+------------------------+
    | Want-Digest         | obsoleted | [RFC3230], Section 1.3 |
    |                     |           | of RFC 9530            |
    +---------------------+-----------+------------------------+

       Table 1: Hypertext Transfer Protocol (HTTP) Field Name
                          Registry Update

the new ones are Content-Digest, Repr-Digest, Want-Content-Digest, and Want-Repr-Digest, all marked permanent ๐ŸŽ€ while Digest and Want-Digest are now obsoleted (retired, bestie ๐Ÿฅ€) and point back to [RFC3230] and Section 1.3 of RFC 9530.

7.2. Creation of the Hash Algorithms for HTTP Digest Fields Registry ๐Ÿ”ฅ

okay this is the big one โœจ IANA made a brand new registry called "Hash Algorithms for HTTP Digest Fields" at https://www.iana.org/assignments/http-digest-hash-alg/ and filled it with the entries in Table 2. if you want to register something new later, the procedure is in Section 5, so go read that first ๐Ÿงš

here's the starter pack:

+===========+============+============================+============+
| Algorithm | Status     | Description                | Reference  |
| Key       |            |                            |            |
+===========+============+============================+============+
| sha-512   | Active     | The SHA-512 algorithm.     | [RFC6234], |
|           |            |                            | [RFC4648], |
|           |            |                            | RFC 9530   |
+-----------+------------+----------------------------+------------+
| sha-256   | Active     | The SHA-256 algorithm.     | [RFC6234], |
|           |            |                            | [RFC4648], |
|           |            |                            | RFC 9530   |
+-----------+------------+----------------------------+------------+
| md5       | Deprecated | The MD5 algorithm.  It is  | [RFC1321], |
|           |            | vulnerable to collision    | [RFC4648], |
|           |            | attacks; see [NO-MD5] and  | RFC 9530   |
|           |            | [CMU-836068]               |            |
+-----------+------------+----------------------------+------------+
| sha       | Deprecated | The SHA-1 algorithm.  It   | [RFC3174], |
|           |            | is vulnerable to collision | [RFC4648], |
|           |            | attacks; see [NO-SHA] and  | [RFC6234], |
|           |            | [IACR-2020-014]            | RFC 9530   |
+-----------+------------+----------------------------+------------+
| unixsum   | Deprecated | The algorithm used by the  | [RFC4648], |
|           |            | UNIX "sum" command.        | [RFC6234], |
|           |            |                            | [UNIX],    |
|           |            |                            | RFC 9530   |
+-----------+------------+----------------------------+------------+
| unixcksum | Deprecated | The algorithm used by the  | [RFC4648], |
|           |            | UNIX "cksum" command.      | [RFC6234], |
|           |            |                            | [UNIX],    |
|           |            |                            | RFC 9530   |
+-----------+------------+----------------------------+------------+
| adler     | Deprecated | The ADLER32 algorithm.     | [RFC1950], |
|           |            |                            | RFC 9530   |
+-----------+------------+----------------------------+------------+
| crc32c    | Deprecated | The CRC32c algorithm.      | Appendix A |
|           |            |                            | of         |
|           |            |                            | [RFC9260], |
|           |            |                            | RFC 9530   |
+-----------+------------+----------------------------+------------+

                 Table 2: Initial Hash Algorithms

so sha-512 and sha-256 are the active ๐Ÿ’– and md5, sha, unixsum, unixcksum, adler, and crc32c are all marked Deprecated ๐Ÿฅ€ each one has its own reasons (go check the table, it's giving receipts ๐Ÿงพ)

7.3. Deprecate the Hypertext Transfer Protocol (HTTP) Digest Algorithm Values Registry ๐ŸŒธ

last but not least, IANA deprecated the old "Hypertext Transfer Protocol (HTTP) Digest Algorithm Values" registry at https://www.iana.org/assignments/http-dig-alg/ ๐Ÿ™ˆ they also swapped its note for this new text:

   |  This registry is deprecated since it lists the algorithms that can
   |  be used with the Digest and Want-Digest fields defined in
   |  [RFC3230], which has been obsoleted by RFC 9530.  While
   |  registration is not closed, new registrations are encouraged to
   |  use the Hash Algorithms for HTTP Digest Fields
   |  (https://www.iana.org/assignments/http-digest-hash-alg/) registry
   |  instead.

basically the old list is retired, and if you're adding something new, the new registry is where it's at ๐Ÿ’…

8. References ๐Ÿ“š

8.1. Normative References

these are the sources this document leans on, so bookmark them ๐Ÿ”–

[FOLDING] Watsen, K., Auerswald, E., Farrel, A., and Q. Wu, "Handling Long Lines in Content of Internet-Drafts and RFCs", RFC 8792, DOI 10.17487/RFC8792, June 2020, https://www.rfc-editor.org/info/rfc8792.

[HTTP] Fielding, R., Ed., Nottingham, M., Ed., and J. Reschke, Ed., "HTTP Semantics", STD 97, RFC 9110, DOI 10.17487/RFC9110, June 2022, https://www.rfc-editor.org/info/rfc9110.

[RFC1321] Rivest, R., "The MD5 Message-Digest Algorithm", RFC 1321, DOI 10.17487/RFC1321, April 1992, https://www.rfc-editor.org/info/rfc1321.

[RFC1950] Deutsch, P. and J. Gailly, "ZLIB Compressed Data Format Specification version 3.3", RFC 1950, DOI 10.17487/RFC1950, May 1996, https://www.rfc-editor.org/info/rfc1950.

[RFC2119] Bradner, S., "Key words for use in RFCs to Indicate Requirement Levels", BCP 14, RFC 2119, DOI 10.17487/RFC2119, March 1997, https://www.rfc-editor.org/info/rfc2119.

[RFC3174] Eastlake 3rd, D. and P. Jones, "US Secure Hash Algorithm 1 (SHA1)", RFC 3174, DOI 10.17487/RFC3174, September 2001, https://www.rfc-editor.org/info/rfc3174.

[RFC4648] Josefsson, S., "The Base16, Base32, and Base64 Data Encodings", RFC 4648, DOI 10.17487/RFC4648, October 2006, https://www.rfc-editor.org/info/rfc4648.

[RFC5234] Crocker, D., Ed. and P. Overell, "Augmented BNF for Syntax Specifications: ABNF", STD 68, RFC 5234, DOI 10.17487/RFC5234, January 2008, https://www.rfc-editor.org/info/rfc5234.

[RFC6234] Eastlake 3rd, D. and T. Hansen, "US Secure Hash Algorithms (SHA and SHA-based HMAC and HKDF)", RFC 6234, DOI 10.17487/RFC6234, May 2011, https://www.rfc-editor.org/info/rfc6234.

[RFC7405] Kyzivat, P., "Case-Sensitive String Support in ABNF", RFC 7405, DOI 10.17487/RFC7405, December 2014, https://www.rfc-editor.org/info/rfc7405.

[RFC8126] Cotton, M., Leiba, B., and T. Narten, "Guidelines for Writing an IANA Considerations Section in RFCs", BCP 26, RFC 8126, DOI 10.17487/RFC8126, June 2017, https://www.rfc-editor.org/info/rfc8126.

[RFC8174] Leiba, B., "Ambiguity of Uppercase vs Lowercase in RFC 2119 Key Words", BCP 14, RFC 8174, DOI 10.17487/RFC8174, May 2017, https://www.rfc-editor.org/info/rfc8174.

[STRUCTURED-FIELDS] Nottingham, M. and P. Kamp, "Structured Field Values for HTTP", RFC 8941, DOI 10.17487/RFC8941, February 2021, https://www.rfc-editor.org/info/rfc8941.

8.2. Informative References ๐Ÿ“š

okay so these are the "good to know" refs, bestie ๐Ÿซถ they aren't required reading, but they're where the backstory lives ๐Ÿ’…


Appendix A. Resource Representation and Representation Data โœจ

these examples show how representation metadata, content transformations, and methods can change the message and the content ๐ŸŽ€ they're not an exhaustive list, so don't treat them like the full menu ๐Ÿ’…

unless otherwise indicated, the examples are based on the JSON object {"hello": "world"} followed by an LF ๐Ÿ“ when the content has non-printable characters (like when it's encoded), it's shown as a sequence of hex-encoded bytes ๐Ÿค“

say a client wants to upload a JSON object with the PUT method. it can do that using the application/json Content-Type with no content coding at all ๐Ÿฆ‹

PUT /entries/1234 HTTP/1.1
Host: foo.example
Content-Type: application/json
Content-Length: 19

{"hello": "world"}

Figure 1: Request Containing a JSON Object without Any Content Coding

but content coding is super common ๐Ÿ˜ญ the client could upload the same data with a GZIP coding (Section 8.4.1.3 of [HTTP]). note that here the Content-Length is bigger because of the coding overheads ๐Ÿงš

PUT /entries/1234 HTTP/1.1
Host: foo.example
Content-Type: application/json
Content-Encoding: gzip
Content-Length: 39

1F 8B 08 00 88 41 37 64 00 FF
AB 56 CA 48 CD C9 C9 57 B2 52
50 2A CF 2F CA 49 51 AA E5 02
00 D9 E4 31 E7 13 00 00 00

Figure 2: Request Containing a GZIP-Encoded JSON Object

sending GZIP-coded data without saying so in Content-Encoding means the content is malformed ๐Ÿ’€ in that case, the server can reply with an error ๐Ÿ™ˆ

PUT /entries/1234 HTTP/1.1
Host: foo.example
Content-Type: application/json

Content-Length: 39

1F 8B 08 00 88 41 37 64 00 FF
AB 56 CA 48 CD C9 C9 57 B2 52
50 2A CF 2F CA 49 51 AA E5 02
00 D9 E4 31 E7 13 00 00 00

Figure 3: Request Containing Malformed JSON

HTTP/1.1 400 Bad Request

Figure 4: An Error Response for Malformed Content

a Range-Request changes the transferred message content too ๐ŸŒธ in this example, the client is accessing the resource at /entries/1234, which is the JSON object {"hello": "world"} followed by an LF. the client has asked for a preferred content coding and a specific byte range, so it's giving main character energy ๐Ÿ‘‘

GET /entries/1234 HTTP/1.1
Host: foo.example
Accept-Encoding: gzip
Range: bytes=1-7

Figure 5: Request for Partial Content

the server satisfies the request by sending back a partial representation (equivalent to the first 10 bytes of the JSON object shown in whole in Figure 2) โœจ

HTTP/1.1 206 Partial Content
Content-Encoding: gzip
Content-Type: application/json
Content-Range: bytes 0-9/39

1F 8B 08 00 A5 B4 BD 62 02 FF

Figure 6: Partial Response from a GZIP-Encoded Representation

aside from content coding or range requests, the method can also change the transferred message content ๐Ÿฆ‹ for example, the response to a HEAD request doesn't carry content, but this example still includes Content-Length; see Section 8.6 of [HTTP] ๐ŸŽ€

HEAD /entries/1234 HTTP/1.1
Host: foo.example
Accept: application/json
Accept-Encoding: gzip

Figure 7: HEAD Request

HTTP/1.1 200 OK
Content-Type: application/json
Content-Encoding: gzip
Content-Length: 39

Figure 8: Response to HEAD Request (Empty Content)

last one! the semantics of a response can separate the target URI from the enclosed representation ๐ŸŒˆ in the example below, the client sends a POST request aimed at /authors/, but the response has a Content-Location header field saying the enclosed representation refers to the resource at /authors/123. also, Content-Length isn't sent in this example ๐Ÿ™ˆ

POST /authors/ HTTP/1.1
Host: foo.example
Accept: application/json
Content-Type: application/json

{"author": "Camilleri"}

Figure 9: POST Request

HTTP/1.1 201 Created
Content-Type: application/json
Content-Location: /authors/123
Location: /authors/123

{"id": "123", "author": "Camilleri"}

Figure 10: Response with Content-Location Header


Appendix B. Examples of Unsolicited Digest ๐Ÿ”ฎ

these examples show a server replying with a Content-Digest or Repr-Digest field, even though the client never asked for one using Want-Content-Digest or Want-Repr-Digest ๐Ÿ‘€

some examples have JSON objects in the content ๐Ÿ“ for presentation, objects that fit within the line-length limits are shown on a single line in compact notation with no leading space. objects that would go over the limits are shown across multiple lines (one line per key-value pair) with two spaces of leading indentation ๐Ÿ’…

checksum mechanisms defined in this document are media-type agnostic and don't give canonicalization algorithms for specific formats ๐Ÿง  the examples are calculated including any space. while the examples can include both fields, Content-Digest and Repr-Digest can be returned independently ๐Ÿซถ

B.1. Server Returns Full Representation Data ๐ŸŒท

in this example, the message content has complete representation data ๐Ÿ’– so in the response, Content-Digest and Repr-Digest are both computed over the JSON object {"hello": "world"} followed by an LF, which means they have the same value ๐Ÿ˜ญ

GET /items/123 HTTP/1.1
Host: foo.example

Figure 11: GET Request for an Item

NOTE: '\' line wrapping per RFC 8792

HTTP/1.1 200 OK
Content-Type: application/json
Content-Length: 19
Content-Digest: \
  sha-256=:RK/0qy18MlBSVnWgjwz6lZEWjP/lF5HF9bvEF8FabDg=:
Repr-Digest: \
  sha-256=:RK/0qy18MlBSVnWgjwz6lZEWjP/lF5HF9bvEF8FabDg=:

{"hello": "world"}

Figure 12: Response with Identical Repr-Digest and Content-Digest

B.2. Server Returns No Representation Data ๐Ÿงš

in this one, a HEAD request is used to get the checksum of a resource ๐Ÿฆ‹

the response Content-Digest field-value is computed on empty content ๐Ÿซง Repr-Digest is calculated over the JSON object {"hello": "world"} followed by an LF, which isn't shown because there's no content ๐Ÿ™ˆ

HEAD /items/123 HTTP/1.1
Host: foo.example

Figure 13: HEAD Request for an Item

NOTE: '\' line wrapping per RFC 8792

HTTP/1.1 200 OK
Content-Type: application/json
Content-Digest: \
  sha-256=:47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU=:
Repr-Digest: \
  sha-256=:RK/0qy18MlBSVnWgjwz6lZEWjP/lF5HF9bvEF8FabDg=:

Figure 14: Response with Both Content-Digest and Digest (Empty Content)

B.3. Server Returns Partial Representation Data โœ‚๏ธ

Okay so this one is a range request, bestie ๐Ÿฆ‹. The client only asks for a slice of the body, and the server sends back just that part with a 206 Partial Content. ๐Ÿ’–

GET /items/123 HTTP/1.1
Host: foo.example
Range: bytes=10-18

Figure 15: Request for Partial Content

NOTE: '\' line wrapping per RFC 8792

HTTP/1.1 206 Partial Content
Content-Type: application/json
Content-Range: bytes 10-18/19
Content-Digest: \
  sha-256=:jjcgBDWNAtbYUXI37CVG3gRuGOAjaaDRGpIUFsdyepQ=:
Repr-Digest: \
  sha-256=:RK/0qy18MlBSVnWgjwz6lZEWjP/lF5HF9bvEF8FabDg=:

"world"}

Figure 16: Partial Response with Both Content-Digest and Repr-Digest

Now watch this ๐Ÿ‘€ In the response above, the Repr-Digest and Content-Digests values are NOT the same, and that's the whole point ๐ŸŒธ. The Repr-Digest field-value is calculated across the entire JSON object {"hello": "world"} followed by an LF, so it looks like this:

NOTE: '\' line wrapping per RFC 8792

Repr-Digest: \
  sha-256=:RK/0qy18MlBSVnWgjwz6lZEWjP/lF5HF9bvEF8FabDg=:

But since the message content is only bytes 10-18, the Content-Digest field-value is calculated over the sequence "world"} followed by an LF. That gives us this:

NOTE: '\' line wrapping per RFC 8792

Content-Digest: \
  sha-256=:jjcgBDWNAtbYUXI37CVG3gRuGOAjaaDRGpIUFsdyepQ=:

B.4. Client and Server Provide Full Representation Data ๐ŸŽ€

The request carries a Repr-Digest field-value that's calculated on the enclosed representation. It also has an Accept-Encoding: br header field, which basically says "hey, I can handle Brotli" ๐Ÿงš.

The response includes Content-Encoding: br, so the selected representation is Brotli-encoded. That means the Repr-Digest field-value is different from the one in the request. Plot twist ๐Ÿ˜ญ

For presentation purposes, the response body is shown as a sequence of hex-encoded bytes, because it has non-printable characters in it.

NOTE: '\' line wrapping per RFC 8792

PUT /items/123 HTTP/1.1
Host: foo.example
Content-Type: application/json
Accept-Encoding: br
Repr-Digest: \
  sha-256=:RK/0qy18MlBSVnWgjwz6lZEWjP/lF5HF9bvEF8FabDg=:

{"hello": "world"}

Figure 17: PUT Request with Digest

NOTE: '\' line wrapping per RFC 8792

HTTP/1.1 200 OK
Content-Type: application/json
Content-Location: /items/123
Content-Encoding: br
Content-Length: 23
Repr-Digest: \
  sha-256=:d435Qo+nKZ+gLcUHn7GQtQ72hiBVAgqoLsZnZPiTGPk=:

8B 08 80 7B 22 68 65 6C 6C 6F
22 3A 20 22 77 6F 72 6C 64 22
7D 0A 03

Figure 18: Response with Digest of Encoded Response


B.5. Client Provides Full Representation Data and Server Provides No Representation Data ๐Ÿ™ˆ

The request Repr-Digest field-value is calculated on the enclosed content, which is the JSON object {"hello": "world"} followed by an LF.

The response Repr-Digest field-value depends on the representation metadata header fields, including Content-Encoding: br, even when the response doesn't contain any content ๐Ÿ’…. So the metadata still counts, even with an empty body.

NOTE: '\' line wrapping per RFC 8792

PUT /items/123 HTTP/1.1
Host: foo.example
Content-Type: application/json
Content-Length: 19
Accept-Encoding: br
Repr-Digest: \
  sha-256=:RK/0qy18MlBSVnWgjwz6lZEWjP/lF5HF9bvEF8FabDg==:

{"hello": "world"}

HTTP/1.1 204 No Content
Content-Type: application/json
Content-Encoding: br
Repr-Digest: sha-256=:d435Qo+nKZ+gLcUHn7GQtQ72hiBVAgqoLsZnZPiTGPk=:

Figure 19: Empty Response with Digest


B.6. Client and Server Provide Full Representation Data ๐ŸŒˆ

This response has two digest values, using different algorithms โœจ. Two for the price of one, honestly iconic.

For presentation purposes, the response body is shown as a sequence of hex-encoded bytes, because it has non-printable characters.

NOTE: '\' line wrapping per RFC 8792

PUT /items/123 HTTP/1.1
Host: foo.example
Content-Type: application/json
Accept-Encoding: br
Repr-Digest: \
  sha-256=:RK/0qy18MlBSVnWgjwz6lZEWjP/lF5HF9bvEF8FabDg==:

{"hello": "world"}

Figure 20: PUT Request with Digest

NOTE: '\' line wrapping per RFC 8792

HTTP/1.1 200 OK
Content-Type: application/json
Content-Encoding: br
Content-Location: /items/123
Repr-Digest: \
  sha-256=:d435Qo+nKZ+gLcUHn7GQtQ72hiBVAgqoLsZnZPiTGPk=:,\
  sha-512=:db7fdBbgZMgX1Wb2MjA8zZj+rSNgfmDCEEXM8qLWfpfoNY0sCpHAzZbj\
  09X1/7HAb7Od5Qfto4QpuBsFbUO3dQ==:

8B 08 80 7B 22 68 65 6C 6C 6F
22 3A 20 22 77 6F 72 6C 64 22
7D 0A 03

Figure 21: Response with Digest of Encoded Content


B.7. POST Response Does Not Reference the Request URI ๐Ÿ“ฎ

The request Repr-Digest field-value is computed on the enclosed representation (see Section 3.1), which is the JSON object {"title": "New Title"} followed by an LF.

The representation in the response is a multiline JSON object followed by an LF. It refers to the resource identified by Content-Location (see Section 6.4.2 of [HTTP]), so an application can use Repr-Digest together with the resource that Content-Location points to. Ate ๐Ÿ’–

POST /books HTTP/1.1
Host: foo.example
Content-Type: application/json
Accept: application/json
Accept-Encoding: identity
Repr-Digest: sha-256=:mEkdbO7Srd9LIOegftO0aBX+VPTVz7/CSHes2Z27gc4=:

{"title": "New Title"}

Figure 22: POST Request with Digest

HTTP/1.1 201 Created
Content-Type: application/json
Content-Location: /books/123
Location: /books/123
Repr-Digest: sha-256=:uVSlinTTdQUwm2On4k8TJUikGN1bf/Ds8WPX4oe0h9I=:

{
  "id": "123",
  "title": "New Title"
}

Figure 23: Response with Digest of Resource


B.8. POST Response Describes the Request Status ๐Ÿ“Š

The request Repr-Digest field-value is computed on the enclosed representation (see Section 3.1), which is the JSON object {"title": "New Title"} followed by an LF.

This time the representation in the response describes the status of the request, so Repr-Digest is computed on that enclosed representation. It's a multiline JSON object followed by an LF ๐Ÿซถ.

The response Repr-Digest has no explicit relation with the resource referenced by Location. Not the same vibe as the last example, so don't mix them up ๐Ÿ™ƒ.

POST /books HTTP/1.1
Host: foo.example
Content-Type: application/json
Accept: application/json
Accept-Encoding: identity
Repr-Digest: sha-256=:mEkdbO7Srd9LIOegftO0aBX+VPTVz7/CSHes2Z27gc4=:

{"title": "New Title"}

Figure 24: POST Request with Digest

HTTP/1.1 201 Created
Content-Type: application/json
Repr-Digest: sha-256=:yXIGDTN5VrfoyisKlXgRKUHHMs35SNtyC3szSz1dbO8=:
Location: /books/123

{
  "status": "created",
  "id": "123",
  "ts": 1569327729,
  "instance": "/books/123"
}

Figure 25: Response with Digest of Representation


B.9. Digest with PATCH ๐Ÿฉน

This case is analogous to a POST request, where the target resource reflects the target URI. Same energy, different verb ๐Ÿ’œ.

The PATCH request uses the application/merge-patch+json media type defined in [RFC7396]. Repr-Digest is calculated on the content that corresponds to the patch document, which is the JSON object {"title": "New Title"} followed by an LF.

The response Repr-Digest field-value is computed on the complete representation of the patched resource. It's a multiline JSON object followed by an LF.

PATCH /books/123 HTTP/1.1
Host: foo.example
Content-Type: application/merge-patch+json
Accept: application/json
Accept-Encoding: identity
Repr-Digest: sha-256=:mEkdbO7Srd9LIOegftO0aBX+VPTVz7/CSHes2Z27gc4=:

{"title": "New Title"}

Figure 26: PATCH Request with Digest

HTTP/1.1 200 OK
Content-Type: application/json
Repr-Digest: sha-256=:uVSlinTTdQUwm2On4k8TJUikGN1bf/Ds8WPX4oe0h9I=:

{
  "id": "123",
  "title": "New Title"
}

Figure 27: Response with Digest of Representation

Also, a 204 No Content response without content, but with the same Repr-Digest field-value, would have been legit too ๐Ÿ™Œ. In that case, Content-Digest would have been computed on empty content.


B.10. Error Responses ๐Ÿšจ

In error responses, the representation data doesn't necessarily refer to the target resource. Instead, it refers to the representation of the error. Not every response is about the thing you asked for, bestie ๐Ÿ’€.

In the following example, a client sends the same request from Figure 26 to patch the resource at /books/123. But the resource doesn't exist, so the server generates a 404 response with a body that describes the error, following [RFC9457].

The response Repr-Digest field-value is computed on this enclosed representation. It's a multiline JSON object followed by an LF.

HTTP/1.1 404 Not Found
Content-Type: application/problem+json
Repr-Digest: sha-256=:EXB0S2VF2H7ijkAVJkH1Sm0pBho0iDZcvVUHHXTTZSA=:

{
  "title": "Not Found",
  "detail": "Cannot PATCH a non-existent resource",
  "status": 404
}

Figure 28: Response with Digest of Error Representation


B.11. Use with Trailer Fields and Transfer Coding ๐Ÿงต

An origin server sends Repr-Digest as a trailer field. That way it can calculate the digest-value while it's streaming the content, which helps mitigate resource consumption ๐ŸŒท. The Repr-Digest field-value is the same as in Appendix B.1, because Repr-Digest is designed to be independent of the use of one or more transfer codings (see Section 3).

In the response content below, the string "\r\n" stands for the CRLF bytes.

GET /items/123 HTTP/1.1
Host: foo.example

Figure 29: GET Request

NOTE: '\' line wrapping per RFC 8792

HTTP/1.1 200 OK
Content-Type: application/json
Transfer-Encoding: chunked
Trailer: Repr-Digest

8\r\n
{"hello"\r\n
8\r\n
: "world\r\n
3\r\n
"}\n\r\n
0\r\n
Repr-Digest: \
  sha-256=:RK/0qy18MlBSVnWgjwz6lZEWjP/lF5HF9bvEF8FabDg==:\r\n

Figure 30: Chunked Response with Digest


Appendix C. Examples of Want-Repr-Digest Solicited Digest ๐ŸŽ

The following examples show interactions where a client asks for a Repr-Digest using Want-Repr-Digest. The behaviour of Content-Digest and Want-Content-Digest is identical ๐Ÿ“.

Some examples include JSON objects in the content. For presentation purposes, objects that fit completely within the line-length limits are shown on a single line, using compact notation with no leading space. Objects that would go over the line-length limits are shown across multiple lines (one line per key-value pair), with two spaces of leading indentation.

Checksum mechanisms described in this document are media-type agnostic and don't provide canonicalization algorithms for specific formats. Examples are calculated inclusive of any space.

C.1. Server Selects Client's Least Preferred Algorithm ๐Ÿ’…

The client requests a digest and prefers "sha". The server is free to reply with "sha-256" anyway. Rude, but allowed ๐Ÿ˜ญ.

GET /items/123 HTTP/1.1
Host: foo.example
Want-Repr-Digest: sha-256=3, sha=10

Figure 31: GET Request with Want-Repr-Digest

NOTE: '\' line wrapping per RFC 8792

HTTP/1.1 200 OK
Content-Type: application/json
Repr-Digest: \
  sha-256=:RK/0qy18MlBSVnWgjwz6lZEWjP/lF5HF9bvEF8FabDg==:

{"hello": "world"}

Figure 32: Response with Different Algorithm

C.2. Server Selects Algorithm Unsupported by Client ๐ŸŒธ

okay so the client only speaks sha, so that's the only digest it asks for ๐Ÿงš The server is totally not obliged to send back a sha digest, so it just uses a different algorithm instead. no drama, no cap ๐Ÿ’…

GET /items/123 HTTP/1.1
Host: foo.example
Want-Repr-Digest: sha=10

Figure 33: GET Request with Want-Repr-Digest

NOTE: '' line wrapping per RFC 8792

HTTP/1.1 200 OK
Content-Type: application/json
Repr-Digest: \
  sha-512=:YMAam51Jz/jOATT6/zvHrLVgOYTGFy1d6GJiOHTohq4yP+pgk4vf2aCs\
  yRZOtw8MjkM7iw7yZ/WkppmM44T3qg==:

{"hello": "world"}

Figure 34: Response with Unsupported Algorithm

C.3. Server Does Not Support Client Algorithm and Returns an Error ๐Ÿฆ‹

okay this one is a plot twist ๐Ÿ˜ญ Appendix C.2 showed a server quietly ignoring the client's favourite digest algorithm. But a server can also just say "nope" and send back an error with a 4xx or 5xx status code. This spec doesn't lock in any rule for which status code to pick, so the example below is just one possible option โœจ

In this example, the client asks for a sha Repr-Digest, and the server returns an error with problem details [RFC9457] tucked into the content. The problem details list the hashing algorithms the server supports. Again, this is purely an example. This specification does not define any format or requirements for such content ๐Ÿ™ˆ

GET /items/123 HTTP/1.1
Host: foo.example
Want-Repr-Digest: sha=10

Figure 35: GET Request with Want-Repr-Digest

HTTP/1.1 400 Bad Request
Content-Type: application/problem+json

{
  "title": "Bad Request",
  "detail": "Supported hashing algorithms: sha-256, sha-512",
  "status": 400
}

Figure 36: Response Advertising the Supported Algorithms


Appendix D. Sample Digest Values ๐Ÿ”ฅ

this section is basically a digest showcase ๐Ÿ’– Every example uses the same input, the JSON object {"hello": "world"}. Each digest comes from running the hashing algorithm over that input, then running the output bytes through Byte Sequence serialization. For the full scoop, check Section 4.1.8 of [STRUCTURED-FIELDS] โœจ

NOTE: '' line wrapping per RFC 8792

sha-512 -   :WZDPaVn/7XgHaAy8pmojAkGWoRx2UFChF41A2svX+TaPm+\
            AbwAgBWnrIiYllu7BNNyealdVLvRwEmTHWXvJwew==:

sha-256 -   :X48E9qOokqqrvdts8nOJRJN3OWDUoyWxBf7kbu9DBPE=:

md5 -       :Sd/dVLAcvNLSq16eXua5uQ==:

sha -       :07CavjDP4u3/TungoUHJO/Wzr4c=:

unixsum -   :GQU=:

unixcksum - :7zsHAA==:

adler -     :OZkGFw==:

crc32c -    :Q3lHIA==:

Appendix E. Migrating from RFC 3230 ๐Ÿ“

okay, glow-up time ๐ŸŒˆ HTTP digests are computed by applying a hashing algorithm to input data. [RFC3230] called that input data an "instance", which it also defined. The term "instance" has since been replaced by the HTTP semantic term "representation". Some implementations of [RFC3230] got confused and read "instance" as HTTP content. Using content for the Digest field is an error, and it causes interoperability problems between peers that implement [RFC3230] ๐Ÿ˜ญ

[RFC3230] was only ever meant to use what HTTP now calls selected representation data. The semantic concepts of digest and representation are explained alongside the definition of the Repr-Digest field (Section 3) ๐Ÿ’œ

The syntax of Digest and Repr-Digest is different, but the considerations and examples this document gives for Repr-Digest apply equally to Digest. They work on the same input data, so see Sections 3.1, 6 and 6.3 ๐Ÿฆ‹

[RFC3230] could never carry the digest of HTTP message content in the Digest field. Content-Digest now gives us that capability ๐ŸŽ€

[RFC3230] let algorithms define their own output encoding format for use with the Digest field. The result was a mess of formats like base64, hex, or decimal. Thanks to Structured Fields, Content-Digest and Repr-Digest only use a single encoding format now. Appendix D has more explanation and examples โœจ

Acknowledgements ๐Ÿซถ

this document is based on ideas from [RFC3230], so big thanks to Jeff Mogul and Arthur Van Hoff for their amazing work ๐Ÿ‘‘ The original idea of refreshing [RFC3230] came out of an interesting discussion with Mark Nottingham, Jeffrey Yasskin, and Martin Thomson while they were reviewing the MICE content coding.

Thanks to Julian Reschke for his valuable contributions to this document. Thanks also to the following contributors, who helped improve this specification by reporting bugs, asking smart questions, drafting or reviewing text, and evaluating open issues: Mike Bishop, Brian Campbell, Matthew Kerwin, James Manger, Tommy Pauly, Sean Turner, Justin Richer, and Erik Wilde ๐Ÿ’…๐ŸŒธ

Authors' Addresses ๐Ÿ’Œ

Roberto Polli Team Digitale, Italian Government Italy Email: robipolli@gmail.com

Lucas Pardue Cloudflare Email: lucas@lucaspardue.com

๐Ÿ“ฆ where this page comes from