Skip to content

CWE-362: Concurrent Execution using Shared Resource with Improper Synchronization ('Race Condition')

ClassLikelihood of exploit: Medium

The product contains a concurrent code sequence that requires temporary, exclusive access to a shared resource, but a timing window exists in which the shared resource can be modified by another code sequence operating concurrently.

A race condition occurs within concurrent environments, and it is effectively a property of a code sequence. Depending on the context, a code sequence may be in the form of a function call, a small number of instructions, a series of program invocations, etc. A race condition violates these properties, which are closely related: Exclusivity - the code sequence is given exclusive access to the shared resource, i.e., no other code sequence can modify properties of the shared resource before the original sequence has completed execution. Atomicity - the code sequence is behaviorally atomic, i.e., no other thread or process can concurrently execute the same sequence of instructions (or a subset) against the same resource. A race condition exists when an "interfering code sequence" can still access the shared resource, violating exclusivity. The interfering code sequence could be "trusted" or "untrusted." A trusted interfering code sequence occurs within the product; it cannot be modified by the attacker, and it can only be invoked indirectly. An untrusted interfering code sequence can be authored directly by the attacker, and typically it is external to the vulnerable product.

Consequences

  • Availability: DoS: Resource Consumption (CPU), DoS: Resource Consumption (Memory), DoS: Resource Consumption (Other)
  • Availability: DoS: Crash, Exit, or Restart, DoS: Instability
  • Confidentiality, Integrity: Read Files or Directories, Read Application Data
  • Access Control: Execute Unauthorized Code or Commands, Gain Privileges or Assume Identity, Bypass Protection Mechanism

How to prevent it

  • Architecture and Design: In languages that support it, use synchronization primitives. Only wrap these around critical code to minimize the impact on performance.
  • Architecture and Design: Use thread-safe capabilities such as the data access abstraction in Spring.
  • Architecture and Design: Minimize the usage of shared resources in order to remove as much complexity as possible from the control flow and to reduce the likelihood of unexpected conditions occurring. Additionally, this will minimize the amount of synchronization necessary and may even help to reduce the likelihood of a denial of service where an attacker may be able to repeatedly trigger a critical section (CWE-400).
  • Implementation: When using multithreading and operating on shared variables, only use thread-safe functions.
  • Implementation: Use atomic operations on shared variables. Be wary of innocent-looking constructs such as "x++". This may appear atomic at the code layer, but it is actually non-atomic at the instruction layer, since it involves a read, followed by a computation, followed by a write.
  • Implementation: Use a mutex if available, but be sure to avoid related weaknesses such as CWE-412.
  • Implementation: Avoid double-checked locking (CWE-609) and other implementation errors that arise when trying to avoid the overhead of synchronization.
  • Implementation: Disable interrupts or signals over critical parts of the code, but also make sure that the code does not go into a large or infinite loop.
  • Implementation: Use the volatile type modifier for critical variables to avoid unexpected compiler optimization or reordering. This does not necessarily solve the synchronization problem, but it can help.
  • Architecture and Design, Operation: Run your code using the lowest privileges that are required to accomplish the necessary tasks [REF-76]. If possible, create isolated accounts with limited privileges that are only used for a single task. That way, a successful attack will not immediately give the attacker access to the rest of the software or its environment. For example, database applications rarely need to run as the database administrator, especially in day-to-day operations.

Recent advisories

  • GHSA-5wjr-9356-4wc8 — Tokio: Race condition in `tokio::time::Interval`
  • GHSA-44jh-23m7-hpcf — @better-auth/drizzle-adapter: Concurrent requests can exceed rate limits on PostgreSQL
  • GHSA-494h-xx7x-5frh — Microsoft Security Advisory CVE-2026-70183 - ASP.NET Core Security Feature Bypass Vulnerability
  • GO-2026-6617 — HTTP/2 server crash due to HPACK encoder race in net/http
  • GHSA-xvgh-hmx8-9xxf — Backstage: Improper task state validation in Scaffolder backend
  • GHSA-pr7f-p5mw-fc87 — vLLM: Incomplete CVE-2025-62164 remediation can be bypassed by concurrent prompt parts
  • GHSA-2hw9-mc66-jc2q — Wasmtime: Preemption and traps during bulk operations enable breaking internal VM state
  • GHSA-9h85-g7w3-rh49 — ViewComponent: Reused Component Instances Retain Stale Render Context
  • GHSA-hvrm-45r6-mjfj — hono/jsx does not isolate context per request, leading to cross-request data disclosure
  • GHSA-7w99-5wm4-3g79 — @better-auth/oauth-provider's OAuth authorization-code grant allows concurrent redemption when two token requests race the find-then-delete primitive
  • GHSA-392p-2q2v-4372 — Better Auth: OAuth refresh-token rotation forks the token family on concurrent redemption
  • GHSA-4vgr-h27g-cf9p — SurrealDB: HTTP RPC Session Race Condition Allows Privilege Escalation
  • GHSA-7fq5-7wr8-rjwj — OliveTin has a Concurrent Template Parsing Race Condition which Leads to Cross-Request Command Contamination
  • GHSA-chgr-c6px-7xpp — PyO3 has a missing `Sync` bound on `PyCFunction::new_closure` closures
  • GHSA-8m7c-hf24-5g47 — NocoDB: OAuth Authorization Code Race Condition

All advisories for CWE-362

Is this in your code?

MergeHarbor checks every repository's dependencies against this database, ranks what matters by exploitability and reachability, routes it to the owning team and opens the fix pull request.

Check your repos with MergeHarbor