/ HTTP Headers

Digest

The HTTP Digest header is a security feature that allows clients and servers to verify the integrity of data transmitted in HTTP messages. It calculates and includes a cryptographic hash of the message content, which can be validated by the receiving party to ensure that the data has not been tampered with during transit.

Overview of the Digest Header

The Digest header is defined in RFC 3230 and updated by RFC 5843. It can be used in both HTTP requests and responses, and its primary purpose is to provide end-to-end integrity checks for the message content. The Digest header is particularly useful in scenarios where data corruption or tampering is a concern, such as in financial transactions or secure communications.

The Digest header consists of one or more comma-separated values, each representing a digest algorithm and its corresponding hash value. The general syntax for the Digest header is:

Digest = "Digest" ":" 1#(algorithm "=" encoded-hash)

Where algorithm is the name of the digest algorithm used (e.g., sha-256md5), and encoded-hash is the Base64-encoded hash value.

Supported Digest Algorithms

The Digest header supports multiple digest algorithms, including but not limited to:

  • md5: The MD5 message-digest algorithm
  • sha: The SHA-1 hash function
  • sha-256: The SHA-256 hash function
  • sha-512: The SHA-512 hash function
  • sha3: The SHA-3 hash function
  • blake2: The BLAKE2 hash function

It’s important to note that some of these algorithms, such as md5 and sha, are considered insecure and should not be used in security-sensitive applications. It is recommended to use more secure algorithms like sha-256sha-512, or sha3.

Example of Digest Header in HTTP Request and Response

Here is an example of an HTTP request and response using the Digest header to ensure data integrity.

HTTP Request

POST /api/v1/transaction HTTP/1.1
Host: example.com
Content-Type: application/json
Content-Length: 71
Digest: sha-256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU=

{
  "amount": 100,
  "from": "user1@example.com",
  "to": "user2@example.com"
}

In this example, the client sends an HTTP POST request to the /api/v1/transaction endpoint with a JSON payload. The Digest header is included with the sha-256 algorithm and its corresponding hash value.

HTTP Response

HTTP/1.1 201 Created
Date: Tue, 01 Feb 2022 10:30:00 GMT
Content-Type: application/json
Content-Length: 50
Digest: sha-256=3I42H3S6NNFQ2MSVX7XZKYAYSCX5QBYJ

{
  "status": "success",
  "transaction_id": "12345"
}

In the response, the server acknowledges the successful creation of the transaction and includes the Digest header with the sha-256 algorithm and its corresponding hash value.

Summary

The HTTP Digest header is a valuable tool for ensuring the integrity of data transmitted in HTTP messages. By including a cryptographic hash of the message content, clients and servers can validate that the data has not been tampered with during transit.

When implementing the Digest header, it is important to choose secure algorithms such as sha-256sha-512, or sha3 and avoid using insecure ones like md5 and sha. With proper implementation, the Digest header can provide an additional level of security and trust in your HTTP communications.

Was this helpful?

Thanks for your feedback!