Rust Crate 'rand' Security Alert: Unsoundness in ThreadRNG with Custom Loggers [GHSA-cq8v-f236-94qc]
A critical security vulnerability has been disclosed in the widely used Rust crate `rand`, designated GHSA-cq8v-f236-94qc. The flaw is a soundness issue, meaning safe Rust code using the library's public API can trigger undefined behavior (UB), a severe class of bug that can lead to crashes or security exploits. The vulnerability is triggered under a specific but plausible configuration: when the `log` and `thread_rng` features are enabled, a custom logger is defined, and that logger accesses `rand::rng()` (formerly `rand::thread_rng()`) and calls `TryRng` methods on the `ThreadRng` handle.
The core of the unsoundness occurs when the `ThreadRng` attempts to reseed itself while being called from within the custom logger's context. This interaction creates a scenario where safe code violates Rust's memory safety guarantees. The issue was reported by GitHub user @lopopolo and is addressed in version 0.9 of the `rand` crate. The update moves the dependency from the vulnerable 0.8 series to the patched 0.9 release.
This alert necessitates immediate attention from developers and maintainers of Rust projects. Any codebase using `rand` as a development dependency with the specified feature flags and custom logging implementations is potentially exposed. The fix is contained in the minor version update, and the advisory strongly recommends upgrading to `rand` 0.9 to mitigate the risk of undefined behavior stemming from this library-level soundness violation.