Skip to content

S10:2023 - Race Condition

Overview

Data indicates that Race Conditions in Snap security are relatively unexplored, with our dataset capturing only a few instances of security-relevant findings for this category. Anticipating the existence of more issues, we aim to raise awareness by featuring this as #10 in the Snap Security Top 10.

Description

Imagine your browser as an operating system, with browser tabs symbolizing asynchronous threads. Consider the implications when a single or multiple dApp's attempt to communicate with the Snap simultaneously. Due to the asynchronity it is unclear which call gets handled first. This can lead to:

  • Unpredictable outcomes.
  • Data being overwritten (e.g. dApps updating counters, settings).
  • Objects not being initialized correctly.

The main problem areas being:

  • Inconsistent handling of state transitions.
  • Lack of synchronization mechanisms leading to undefined states/behaviours.
  • Absence of locks on sensitive data.
  • Time of Check / Time of Use violations.

Common scenarios include multiple dApps or processes attempting to access or modify shared resources concurrently or in an unpredictable sequence, potentially resulting in unintended consequences such as transaction errors, data inconsistencies, or even security breaches.

How to Prevent

  • Implement robust synchronization mechanisms.

  • Implement consistent error-handling mechanisms to gracefully handle unexpected situations that may arise due to race conditions, preventing the Snap from entering an unstable or insecure state.

  • Conduct thorough code reviews to identify and address potential race conditions. Encourage developers to follow best practices for concurrent programming and to use tools that can detect such issues.

  • Include comprehensive tests for concurrency scenarios in the extension's testing suite. Simulate multiple simultaneous transactions or actions to identify and rectify race conditions during development.

Example Misuse Scenarios