Ticket #413 (closed defect: fixed)

Opened 3 years ago

Last modified 3 years ago

Querying malformed ObjectId fails to return

Reported by: simon.haines@… Owned by: jaymccarthy
Priority: trivial Milestone:
Component: jaymccarthy/mongodb.plt Keywords: bson objectid
Cc: Version: (1 11)
Racket Version:

Description

When querying a malicious or badly-formed ObjectId, mongo-collection-find fails to return. Perhaps it is waiting to decode more bytes?

To reproduce:

(define q (make-hasheq))
(hash-set! q '_id (string->bson-objectid "test"))
(mongo-collection-find coll q)

The BSON ObjectId datatype is 12 bytes, so a simple test in bson/shared.rkt should fix this:

(define (string->bson-objectid s)
  (let ([b (base64-decode (string->bytes/utf-8 s))])
    (if (= 12 (bytes-length b))
        (make-bson-objectid b)
        (error 'string->bson-objectid "bad object id"))))

This is (similar to) the workaround I'm using in my code. I imagine (though have not confirmed) the error might be exposed through the dispatch operator as well (when typing in random URLs).

Change History

Changed 3 years ago by jaymccarthy

  • status changed from new to closed
  • resolution set to fixed

I'm about to release a new version with this fixed.

Note: See TracTickets for help on using tickets.