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

ObjectID constructor accepts invalid String

    • Type: Icon: Bug Bug
    • Resolution: Works as Designed
    • Priority: Icon: Unknown Unknown
    • None
    • Affects Version/s: 4.13.0
    • Component/s: BSON
    • Labels:
      None
    • 0
    • 2
    • Not Needed
    • Not Needed

      What problem are you facing?

      ObjectId constructor accepts invalid Strings as long as they have 12 bytes length.

      What driver and relevant dependency versions are you using?

      Node 16, Mongo driver v4.13.0, BSON 4.7.0

      Steps to reproduce?

      // the constructor will not throw an error and
      // it will create an invalid ObjectID
      const id = new ObjectId(`I'm 12 bytes`)
      console.log(id) 
      
      const valid = ObjectId.isValid(`I'm 12 bytes`)
      console.log(id) // prints true

            Assignee:
            neal.beeken@mongodb.com Neal Beeken
            Reporter:
            nyx@scvsoft.com Matias M
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: