Skip to content

425 Too Early (HTTP Status Code 425)

Updated: at 09:12 AM

HTTP Status Code 425 means “Too Early,” and it is a relatively new status code officially added to the HTTP specification in 2019. This status code is primarily used to handle specific situations related to TLS (Transport Layer Security) 1.3 early data (also known as 0-RTT data).

Definition

425 Too Early indicates that the server is unwilling to risk processing a request that may be replayed.

Background

Main Uses

Use Cases

Client Handling

Upon receiving a 425 response, the client should:

Server Implementation

Here is a simplified example illustrating how the server handles early data requests:

const https = require("https");
const fs = require("fs");

const options = {
  key: fs.readFileSync("server-key.pem"),
  cert: fs.readFileSync("server-cert.pem"),
  allowEarlyData: true,
  maxEarlyData: 16384, // 16KB max early data
};

https
  .createServer(options, (req, res) => {
    if (req.socket.isEarlyData) {
      // Check if the request is suitable for early data processing
      if (isSensitiveOperation(req)) {
        res.writeHead(425, { "Content-Type": "application/json" });
        res.end(
          JSON.stringify({
            error: "Too Early",
            message:
              "This request cannot be processed with early data. Please retry with a full TLS handshake.",
          })
        );
        return;
      }
    }

    // Process the request normally
    res.writeHead(200, { "Content-Type": "text/plain" });
    res.end("Hello, secure world!");
  })
  .listen(443);

function isSensitiveOperation(req) {
  // Implement logic to determine if the operation is sensitive
  // For example, check if it's a financial transaction
  return req.url.startsWith("/api/financial/");
}

This example illustrates a basic HTTPS server that checks whether a request uses early data and returns a 425 status code for sensitive operations.

Security Considerations

Performance Impact

Best Practices

Relationship to Other Status Codes

Client Implementation Considerations

Understanding and correctly using the 425 Too Early status code is crucial for building secure and high-performance modern HTTPS applications. It provides a way to balance security and performance, especially when leveraging the new features of TLS 1.3.