A CoAP server receiving a request is, in general, not able to verify when the request was sent by the CoAP client. This remains true even if the request was protected with a security protocol, such as DTLS. This makes CoAP requests vulnerable to certain delay attacks that are particularly perilous in the case of actuators [
COAP-ATTACKS]. Some attacks can be mitigated by establishing fresh session keys, e.g., performing a DTLS handshake for each request, but, in general, this is not a solution suitable for constrained environments, for example, due to increased message overhead and latency. Additionally, if there are proxies, fresh DTLS session keys between the server and the proxy do not say anything about when the client made the request. In a general hop-by-hop setting, freshness may need to be verified in each hop.
A straightforward mitigation of potential delayed requests is that the CoAP server rejects a request the first time it appears and asks the CoAP client to prove that it intended to make the request at this point in time.
This document defines the Echo option, a lightweight challenge-response mechanism for CoAP that enables a CoAP server to verify the freshness of a request. A fresh request is one whose age has not yet exceeded the freshness requirements set by the server. The freshness requirements are application specific and may vary based on resource, method, and parameters outside of CoAP, such as policies. The Echo option value is a challenge from the server to the client included in a CoAP response and echoed back to the server in one or more CoAP requests.
This mechanism is not only important in the case of actuators, or other use cases where the CoAP operations require freshness of requests, but also in general for synchronizing state between a CoAP client and server, cryptographically verifying the aliveness of the client or forcing a client to demonstrate reachability at its claimed network address. The same functionality can be provided by echoing freshness indicators in CoAP payloads, but this only works for methods and response codes defined to have a payload. The Echo option provides a convention to transfer freshness indicators that works for all methods and response codes.
The Echo option is elective, safe to forward, not part of the cache-key, and not repeatable (see
Table 1, which extends Table 4 of [
RFC 7252]).
No. |
C |
U |
N |
R |
Name |
Format |
Length |
Default |
252 |
|
|
x |
|
Echo |
opaque |
1-40 |
(none) |
Table 1: Echo Option Summary
C=Critical, U=Unsafe, N=NoCacheKey, R=Repeatable
The Echo option value is generated by a server, and its content and structure are implementation specific. Different methods for generating Echo option values are outlined in
Appendix A. Clients and intermediaries
MUST treat an Echo option value as opaque and make no assumptions about its content or structure.
When receiving an Echo option in a request, the server
MUST be able to verify that the Echo option value (a) was generated by the server or some other party that the server trusts and (b) fulfills the freshness requirements of the application. Depending on the freshness requirements, the server may verify exactly when the Echo option value was generated (time-based freshness) or verify that the Echo option was generated after a specific event (event-based freshness). As the request is bound to the Echo option value, the server can determine that the request is not older than the Echo option value.
When the Echo option is used with OSCORE [
RFC 8613], it
MAY be an Inner or Outer option, and the Inner and Outer values are independent. OSCORE servers
MUST only produce Inner Echo options unless they are merely testing for reachability of the client (the same as proxies may do). The Inner option is encrypted and integrity protected between the endpoints, whereas the Outer option is not protected by OSCORE. As always with OSCORE, Outer options are visible to (and may be acted on by) all proxies and are visible on all links where no additional encryption (like TLS between client and proxy) is used.
The Echo option
MAY be included in any request or response (see
Section 2.4 for different applications).
The application decides under what conditions a CoAP request to a resource is required to be fresh. These conditions can, for example, include what resource is requested, the request method and other data in the request, and conditions in the environment, such as the state of the server or the time of the day.
If a certain request is required to be fresh, the request does not contain a fresh Echo option value, and the server cannot verify the freshness of the request in some other way, the server
MUST NOT process the request further and
SHOULD send a 4.01 (Unauthorized) response with an Echo option. The server
MAY include the same Echo option value in several different response messages and to different clients. Examples of this could be time-based freshness (when several responses are sent closely after each other) or event-based freshness (with no event taking place between the responses).
The server may use request freshness provided by the Echo option to verify the aliveness of a client or to synchronize state. The server may also include the Echo option in a response to force a client to demonstrate reachability at its claimed network address. Note that the Echo option does not bind a request to any particular previous response but provides an indication that the client had access to the previous response at the time when it created the request.
Upon receiving a 4.01 (Unauthorized) response with the Echo option, the client
SHOULD resend the original request with the addition of an Echo option with the received Echo option value. The client
MAY send a different request compared to the original request. Upon receiving any other response with the Echo option, the client
SHOULD echo the Echo option value in the next request to the server. The client
MAY include the same Echo option value in several different requests to the server or discard it at any time (especially to avoid tracking; see
Section 6).
A client
MUST only send Echo option values to endpoints it received them from (where, as defined in
Section 1.2 of
RFC 7252, the security association is part of the endpoint). In OSCORE processing, that means sending Echo option values from Outer options (or from non-OSCORE responses) back in Outer options and sending those from Inner options in Inner options in the same security context.
Upon receiving a request with the Echo option, the server determines if the request is required to be fresh. If not, the Echo option
MAY be ignored. If the request is required to be fresh and the server cannot verify the freshness of the request in some other way, the server
MUST use the Echo option to verify that the request is fresh. If the server cannot verify that the request is fresh, the request is not processed further, and an error message
MAY be sent. The error message
SHOULD include a new Echo option.
One way for the server to verify freshness is to bind the Echo option value to a specific point in time and verify that the request is not older than a certain threshold T. The server can verify this by checking that (t1 - t0) < T, where t1 is the request receive time and t0 is the time when the Echo option value was generated. An example message flow over DTLS is shown
Figure 1.
Client Server
| |
+------>| Code: 0.03 (PUT)
| PUT | Token: 0x41
| | Uri-Path: lock
| | Payload: 0 (Unlock)
| |
|<------+ Code: 4.01 (Unauthorized)
| 4.01 | Token: 0x41
| | Echo: 0x00000009437468756c687521 (t0 = 9, +MAC)
| |
| ... | The round trips take 1 second, time is now t1 = 10.
| |
+------>| Code: 0.03 (PUT)
| PUT | Token: 0x42
| | Uri-Path: lock
| | Echo: 0x00000009437468756c687521 (t0 = 9, +MAC)
| | Payload: 0 (Unlock)
| |
| | Verify MAC, compare t1 - t0 = 1 < T => permitted.
| |
|<------+ Code: 2.04 (Changed)
| 2.04 | Token: 0x42
| |
Another way for the server to verify freshness is to maintain a cache of values associated to events. The size of the cache is defined by the application. In the following, we assume the cache size is 1, in which case, freshness is defined as "no new event has taken place". At each event, a new value is written into the cache. The cache values
MUST be different or chosen in a way so the probability for collisions is negligible. The server verifies freshness by checking that e0 equals e1, where e0 is the cached value when the Echo option value was generated, and e1 is the cached value at the reception of the request. An example message flow over DTLS is shown in
Figure 2.
Client Server
| |
+------>| Code: 0.03 (PUT)
| PUT | Token: 0x41
| | Uri-Path: lock
| | Payload: 0 (Unlock)
| |
|<------+ Code: 4.01 (Unauthorized)
| 4.01 | Token: 0x41
| | Echo: 0x05 (e0 = 5, number of total lock
| | operations performed)
| |
| ... | No alterations happen to the lock state, e1 has the
| | same value e1 = 5.
| |
+------>| Code: 0.03 (PUT)
| PUT | Token: 0x42
| | Uri-Path: lock
| | Echo: 0x05
| | Payload: 0 (Unlock)
| |
| | Compare e1 = e0 => permitted.
| |
|<------+ Code: 2.04 (Changed)
| 2.04 | Token: 0x42
| | Echo: 0x06 (e2 = 6, to allow later locking
| | without more round trips)
| |
When used to serve freshness requirements (including client aliveness and state synchronizing), the Echo option value
MUST be integrity protected between the intended endpoints, e.g., using DTLS, TLS, or an OSCORE Inner option [
RFC 8613]. When used to demonstrate reachability at a claimed network address, the Echo option
SHOULD be a Message Authentication Code (MAC) of the claimed address but
MAY be unprotected. Combining different Echo applications can necessitate different choices; see
Appendix A, item 2 for an example.
An Echo option
MAY be sent with a successful response, i.e., even though the request satisfied any freshness requirements on the operation. This is called a "preemptive" Echo option value and is useful when the server anticipates that the client will need to demonstrate freshness relative to the current response in the near future.
A CoAP-to-CoAP proxy
MAY set an Echo option on responses, both on forwarded ones that had no Echo option or ones generated by the proxy (from cache or as an error). If it does so, it
MUST remove the Echo option it recognizes as one generated by itself on follow-up requests. When it receives an Echo option in a response, it
MAY forward it to the client (and, not recognizing it as its own in future requests, relay it in the other direction as well) or process it on its own. If it does so, it
MUST ensure that the client's request was generated (or is regenerated) after the Echo option value used to send to the server was first seen. (In most cases, this means that the proxy needs to ask the client to repeat the request with a new Echo option value.)
The CoAP server side of CoAP-to-HTTP proxies
MAY request freshness, especially if they have reason to assume that access may require it (e.g., because it is a PUT or POST); how this is determined is out of scope for this document. The CoAP client side of HTTP-to-CoAP proxies
MUST respond to Echo challenges itself if the proxy knows from the recent establishing of the connection that the HTTP request is fresh. Otherwise, it
MUST NOT repeat an unsafe request and
SHOULD respond with a 503 (Service Unavailable) with a Retry-After value of 0 seconds and terminate any underlying Keep-Alive connection. If the HTTP request arrived in early data, the proxy
SHOULD use a 425 (Too Early) response instead (see [
RFC 8470]). The proxy
MAY also use other mechanisms to establish freshness of the HTTP request that are not specified here.
Unless otherwise noted, all these applications require a security protocol to be used and the Echo option to be protected by it.
-
Actuation requests often require freshness guarantees to avoid accidental or malicious delayed actuator actions. In general, all unsafe methods (e.g., POST, PUT, and DELETE) may require freshness guarantees for secure operation.
-
The same Echo option value may be used for multiple actuation requests to the same server, as long as the total time since the Echo option value was generated is below the freshness threshold.
-
For actuator applications with low delay tolerance, to avoid additional round trips for multiple requests in rapid sequence, the server may send preemptive Echo option values in successful requests, irrespectively of whether or not the request contained an Echo option. The client then uses the Echo option with the new value in the next actuation request, and the server compares the receive time accordingly.
-
A server may use the Echo option to synchronize properties (such as state or time) with a requesting client. A server MUST NOT synchronize a property with a client that is not the authority of the property being synchronized. For example, if access to a server resource is dependent on time, then the server MUST NOT synchronize time with a client requesting access unless the client is a time authority for the server.
Note that the state to be synchronized is not carried inside the Echo option. Any explicit state information needs to be carried along in the messages the Echo option value is sent in; the Echo mechanism only provides a partial order on the messages' processing.
-
If a server reboots during operation, it may need to synchronize state or time before continuing the interaction. For example, with OSCORE, it is possible to reuse a partly persistently stored security context by synchronizing the Partial IV (sequence number) using the Echo option, as specified in Section 7.5 of RFC 8613.
-
A device joining a CoAP group communication [GROUP-COAP] protected with OSCORE [GROUP-OSCORE] may be required to initially synchronize its replay window state with a client by using the Echo option in a unicast response to a multicast request. The client receiving the response with the Echo option includes the Echo option value in a subsequent unicast request to the responding server.
-
An attacker can perform a denial-of-service attack by putting a victim's address in the source address of a CoAP request and sending the request to a resource with a large amplification factor. The amplification factor is the ratio between the size of the request and the total size of the response(s) to that request. A server that provides a large amplification factor to an unauthenticated peer SHOULD mitigate amplification attacks, as described in Section 11.3 of RFC 7252. One way to mitigate such attacks is for the server to respond to the alleged source address of the request with an Echo option in a short response message (e.g., 4.01 (Unauthorized)), thereby requesting the client to verify its source address. This needs to be done only once per endpoint and limits the range of potential victims from the general Internet to endpoints that have been previously in contact with the server. For this application, the Echo option can be used in messages that are not integrity protected, for example, during discovery. (This is formally recommended in Section 2.6.)
-
In the presence of a proxy, a server will not be able to distinguish different origin client endpoints, i.e., the client from which a request originates. Following from the recommendation above, a proxy that provides a large amplification factor to unauthenticated peers SHOULD mitigate amplification attacks. The proxy SHOULD use the Echo option to verify origin reachability, as described in Section 2.3. The proxy MAY forward safe requests immediately to have a cached result available when the client's repeated request arrives.
-
Amplification mitigation is a trade-off between giving leverage to an attacker and causing overhead. An amplification factor of 3 (i.e., don't send more than three times the number of bytes received until the peer's address is confirmed) is considered acceptable for unconstrained applications in RFC 9000, Section 8.
When that limit is applied and no further context is available, a safe default is sending initial responses no larger than 136 bytes in CoAP serialization. (The number is assuming Ethernet, IP, and UDP headers of 14, 40, and 8 bytes, respectively, with 4 bytes added for the CoAP header. Triple that minus the non-CoAP headers gives the 136 bytes.) Given the token also takes up space in the request, responding with 132 bytes after the token is safe as well.
-
When an Echo response is sent to mitigate amplification, it MUST be sent as a piggybacked or Non-confirmable response, never as a separate one (which would cause amplification due to retransmission).
-
A server may want to use the request freshness provided by the Echo option to verify the aliveness of a client. Note that, in a deployment with hop-by-hop security and proxies, the server can only verify aliveness of the closest proxy.
Use cases for the Echo option can be characterized by several criteria that help determine the required properties of the Echo option value. These criteria apply both to those listed in
Section 2.4 and any novel applications. They provide rationale for the statements in the former and guidance for the latter.
The property a client demonstrates by sending an Echo option value is that the request was sent after a certain point in time or after some event happened on the server.
When events are counted, they form something that can be used as a monotonic but very non-uniform time line. With highly regular events and low-resolution time, the distinction between time-based and event-based freshness can be blurred: "no longer than a month ago" is similar to "since the last full moon".
In an extreme form of event-based freshness, the server can place an event whenever an Echo option value is used. This makes the Echo option value effectively single use.
Event-based and time-based freshness can be combined in a single Echo option value, e.g., by encrypting a timestamp with a key that changes with every event to obtain semantics in the style of "usable once but only for 5 minutes".
Information conveyed to the server in the request Echo option value has different authority depending on the application. Understanding who or what is the authoritative source of that information helps the server implementor decide the necessary protection of the Echo option value.
If all that is conveyed to the server is information that the client is authorized to provide arbitrarily (which is another way of saying that the server has to trust the client on whatever the Echo option is being used for), then the server can issue Echo option values that do not need to be protected on their own. They still need to be covered by the security protocol that covers the rest of the message, but the Echo option value can be just short enough to be unique between this server and client.
For example, the client's OSCORE Sender Sequence Number (as used in
RFC 8613,
Appendix B.1.2) is such information.
In most other cases, there is information conveyed for which the server is the authority ("the request must not be older than five minutes" is counted on the server's clock, not the client's) or which even involve the network (as when performing amplification mitigation). In these cases, the Echo option value itself needs to be protected against forgery by the client, e.g., by using a sufficiently large, random value or a MAC, as described in
Appendix A, items 1 and 2.
For some applications, the server may be able to trust the client to also act as the authority (e.g., when using time-based freshness purely to mitigate request delay attacks); these need careful case-by-case evaluation.
To issue Echo option values without integrity protection of its own, the server needs to trust the client to never produce requests with attacker-controlled Echo option values. The provisions of
Section 2.3 (saying that an Echo option value may only be sent as received from the same server) allow that. The requirement stated there for the client to treat the Echo option value as opaque holds for these applications like for all others.
When the client is the sole authority over the synchronized property, the server can still use time or events to issue new Echo option values. Then, the request's Echo option value not so much proves the indicated freshness to the server but reflects the client's intention to indicate reception of responses containing that value when sending the later ones.
Note that a single Echo option value can be used for multiple purposes (e.g., to both get the sequence number information and perform amplification mitigation). In this case, the stricter protection requirements apply.
For meaningful results, the Echo option needs to be used in combination with a security protocol in almost all applications.
When the information extracted by the server is only about a part of the system outside of any security protocol, then the Echo option can also be used without a security protocol (in case of OSCORE, as an Outer option).
The only known application satisfying this requirement is network address reachability, where unprotected Echo option values are used both by servers (e.g., during setup of a security context) and proxies (which do not necessarily have a security association with their clients) for amplification mitigation.
This section updates the amplification mitigation requirements for servers in [
RFC 7252] to recommend the use of the Echo option to mitigate amplification attacks. The requirements for clients are not updated.
Section 11.3 of
RFC 7252 is updated by adding the following text:
A CoAP server
SHOULD mitigate potential amplification attacks by responding to unauthenticated clients with 4.01 (Unauthorized) including an Echo option, as described in item 3 in
Section 2.4 of RFC 9175.