[NCC-E005955-MMC] zebra-network
: Uncaught Nonce Reuse and Fragile Nonce Cache Eviction
#6339
Labels
A-network
Area: Network protocol updates or fixes
C-audit
Category: Issues arising from audit findings
C-security
Category: Security issues
I-invalid-data
Zebra relies on invalid or untrusted data, or sends invalid data
S-needs-triage
Status: A bug report needs triage
Impact
Failure to check if the nonce cache already contains the new nonce may prevent the self-connection detection from working as intended. Incorrectly evicting an entry from the nonce cache will have the same effect.
Description
The function
negotiate_version()
in zebra-network/src/peer/handshake.rs is used to negotiate the network version used when connecting to a new peer. In order to match outgoing messages with incoming responses, a nonce is included, and cached locally to help identify self-connection attempts:zebra/zebra-network/src/peer/handshake.rs
Lines 584 to 591 in 5a88fe7
It was observed that the return value of the insert function is not checked. This function returns
true
if the value was successfully inserted, andfalse
if the value was already contained in the set. Therefore, nonce reuse could be detected at this step by checking the return value of this function. The above freshly generates each nonce viaNonce::default()
, so the probability of a collision is negligible, but it is nevertheless recommended to check the result of the insert operation as a precaution.Later, in the same function, the following code handles received nonces:
zebra/zebra-network/src/peer/handshake.rs
Lines 677 to 693 in 5a88fe7
If the incoming message contains a nonce currently in the cache, that means it corresponds to a negotiation version message originating from itself, indicating a self-connection attempt. When this occurs, an error is returned and the nonce associated with the request is evicted from the cache.
Earlier, this finding highlighted a potential case where nonces could be re-used without correct detection. If such a nonce is evicted after the first connection attempt then a second connection attempt might succeed. Building on this observation, a malicious party may attempt to replay messages or craft messages containing an observed nonce, thereby
causing the nonce to be evicted incorrectly. Subsequently, a self-connection attempt would not be correctly identified.
Based on the above, it is recommended that the approach to nonce handling in this use case be re-evaluated to ensure the intended security goals are met. It may be safer to cache all nonces for a set duration to ensure that malicious or incorrect behavior cannot force nonce eviction from the cache.
Recommendation
HandshakeError::NonceReuse
as necessary.Location
zebra-network/src/peer/handshake.rs
The text was updated successfully, but these errors were encountered: