Skip to content

[UID component] Wrong UUID v4 generation according to RFC 4122 #42787

Closed
@f2r

Description

@f2r

Symfony version(s) affected: 5.x

Description
According to RFC 4122 "A Universally Unique IDentifier (UUID) URN Namespace", the field "time_hi_and_version" is random generated + the UUID version (the 4 most significants bits contains the version number).

Symfony\Component\Uid\UuidV4 at line 27 use binaries operator to set the 4 most significants bits of byte 7 to "\x40", but it set the 4 less significants bits to "\x0F" at the same time.
"\x00" should produce "\x40" but it produces "\x4F"
Thus, the time_hi that should normally be a value between x000 and xFFF, is, in fact, a value between xF00 and xFFF (reduction of the entropy from 4096 to 256). I'm not a security expert, ans I don't know if it's a security issue.

How to reproduce
UUID v4 is randomly generated, so it's impossible to reproduce it, but code analysis is clear :

if $uuid[6] contains "\x00" this code $uuid[6] = $uuid[6] & "\x0F" | "\x4F"; will produce "\x4F"
& "\x0F" is use to reset MSB to "0" ans | "\x4F" force to "4F"

Possible Solution
It's not "\x4F" but simply "\x40"

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions