Uploaded image for project: 'Node.js Driver'
  1. Node.js Driver
  2. NODE-4960

BSON UUID validation is opinionated about requiring specifically a UUID version 4

    • 2
    • 2
    • Not Needed
    • Not Needed
    • Hide

      1. What would you like to communicate to the user about this feature?
      2. Would you like the user to see examples of the syntax and/or executable code and its output?
      3. Which versions of the driver/connector does this apply to?

      Show
      1. What would you like to communicate to the user about this feature? 2. Would you like the user to see examples of the syntax and/or executable code and its output? 3. Which versions of the driver/connector does this apply to?

      When creating a UUID in js-bson, regex validation is performed that specifically requires a version 4 UUID format.

      https://github.com/mongodb/js-bson/blob/d9f0eaa243ceeba8dd82e9c3b07fd8bca10cfc44/src/uuid_utils.ts#L6

      The regex used:

      const VALIDATION_REGEX =
        /^(?:[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|[0-9a-f]{12}4[0-9a-f]{3}[89ab][0-9a-f]{15})$/i;
      

      Why v4 and not a more generic format?   
      Notice specifically in the regext that "4" is required, as is "[89ab]"
      e.g. 00000000-0000-4000-8000-000000000000
       
      This means that a .NET Guid.Empty string value of "00000000-0000-0000-0000-000000000000" served to the js-bson is invalid and an error is thrown when one attempts to construct a UUID with it.


      Node Team Notes:

      AC

      • Reduce the strictness of the regexp to allow any sequence of hex digits with or without dashes
      • Remove bitwise validation from the isUint8Array section of UUID.isValid(uuid)
      • Clarify documentation that new UUID() returns a version 4 UUID
      • Add a test verifying that a UUID can be created from a sequence of bytes and from a string that are not version 4 

            Assignee:
            neal.beeken@mongodb.com Neal Beeken
            Reporter:
            adammcraven@gmail.com Adam Craven
            Bailey Pearson
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated:
              Resolved: