← Back to the chapter · Next detail →
Technical detail · CoAP Messages: Codes, Tokens, and Options
Outstanding requests and Token protection
In CoAP over UDP, a Token matches a response to a pending request, while the Message ID supports duplicate detection and acknowledgement matching.
Use distinct Tokens for outstanding requests to the same endpoint, a peer identified by its network address and port. Replies can arrive in the opposite order from their requests. Match each response by endpoint and Token. A retransmitted Confirmable (CON) message keeps both its Token and Message ID unchanged. A separate Confirmable response uses its own Message ID, and the client acknowledges that new message using that new ID.
3.11 Token Security Consideration
A Message ID is a 16-bit identifier used within the applicable duplicate-detection lifetime, rather than a permanent request identifier. A Token matches a response but does not authenticate its sender. Avoid predictable Tokens where they could help an attacker guess a pending request. Random generation must also avoid collisions among outstanding requests. Authenticated protection, such as Datagram Transport Layer Security (DTLS), provides peer authentication and message protection; randomness alone provides neither.