[wp-trac] [WordPress Trac] #59239: wp_generate_uuid4 collisions
WordPress Trac
noreply at wordpress.org
Wed Mar 18 23:23:27 UTC 2026
#59239: wp_generate_uuid4 collisions
--------------------------------------------+-----------------------
Reporter: joppuyo | Owner: jorbin
Type: defect (bug) | Status: assigned
Priority: normal | Milestone: 7.0
Component: General | Version:
Severity: normal | Resolution:
Keywords: has-patch needs-testing commit | Focuses:
--------------------------------------------+-----------------------
Comment (by siliconforks):
Replying to [comment:14 jorbin]:
> @siliconforks `mt_rand` is a fallback in the scenario where someone is
using `wp_generate_uuid4` extremely early. If `random_int` would to be
used, the logic in wp_rand would need to be duplicated including, a
fallback for when `random_int` cannot find an appropriate source of
randomness.
Well, I think the safest thing to do in that case would be to just throw
the exception rather than keep handing out bogus UUIDs. But if you really
want to guarantee that `wp_generate_uuid4()` never throws an exception and
always returns something, you could simply
1. Use `wp_rand()` if that function exists
2. If `wp_rand()` is not available, try calling `random_int()`
3. If `random_int()` throws an exception, catch it and fall back to
`mt_rand()`
--
Ticket URL: <https://core.trac.wordpress.org/ticket/59239#comment:15>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list