aws-samples / aws-samples/sample-code-for-a-secure-vault-using-aws-nitro-enclaves
RUSTSEC-2026-0097: Rand is unsound with a custom logger using `rand::rng()`
- Dominant language
- Rust
- Stars
- 9
- Forks
- 7
- PR merge metrics
- No merged PRs in 30d
Description
> Rand is unsound with a custom logger using `rand::rng()`
| Details | |
| ------------------- | ---------------------------------------------- |
| Status | unsound |
| Package | `rand` |
| Version | `0.9.2` |
| URL | [https://github.com/rust-random/rand/pull/1763](https://github.com/rust-random/rand/pull/1763) |
| Date | 2026-04-09 |
It has been reported (by @lopopolo) that the `rand` library is [unsound](https://rust-lang.github.io/unsafe-code-guidelines/glossary.html#soundness-of-code--of-a-library) (i.e. that safe code using the public API can cause Undefined Behaviour) when all the following conditions are met:
- The `log` and `thread_rng` features are enabled
- A [custom logger](https://docs.rs/log/latest/log/#implementing-a-logger) is defined
- The custom logger accesses `rand::rng()` (previously `rand::thread_rng()`) and calls any `TryRng` (previously `RngCore`) methods on `ThreadRng`
- The `ThreadRng` (attempts to) reseed while called from the custom logger (this happens every 64 kB of generated data)
- Trace-level logging is enabled or warn-level logging is enabled and the random source (the `getrandom` crate) is unable to provide a new seed
`TryRng` (previously `RngCore`) methods for `ThreadRng` use `unsafe` code to cast `*mut BlockRng<ReseedingCore>` to `&mut BlockRng<ReseedingCore>`. When all the above conditions are met this results in an aliased mutable reference, violating the Stacked Borrows rules. Miri is able to detect this violation in sample code. Since construction of [aliased mutable references is Undefined Behaviour](https://doc.rust-lang.org/stable/nomicon/references.html), the behaviour of optimized builds is hard to predict.
Affected versions of `rand` are `>= 0.7, < 0.9.3` and `0.10.0`.
See [advisory page](https://rustsec.org/advisories/RUSTSEC-2026-0097.html) for additional details.
Contributor guide
Research direction
Start by reviewing the rand advisory details and the linked rand pull request #1763. The issue does not name a repository file, test, or entry point, so locate the dependency declaration and determine whether the affected rand versions are used. Done means the repository no longer relies on an affected version, with the dependency checks or security audit confirming the result.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- security
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100