I'm developing a RESTful API using MongoDB as the backend. The easiest thing to do programmatically would be to simply use MongoDB's _id field in the URI, such as:


I know that the ObjectID is based in part on the creation timestamp. Is there anything else an attacker could gain from knowledge of the ObjectID?

2 Answers 2


According to Mongo's documentation, the following is used to construct an ObjectId:

ObjectId is a 12-byte BSON type, constructed using:

  a 4-byte value representing the seconds since the Unix epoch,
  a 3-byte machine identifier,
  a 2-byte process id, and
  a 3-byte counter, starting with a random value.

So to answer your question,

Is there anything else an attacker could gain from knowledge of the ObjectID?

I would say that it seems like in addition to the time stamp they could also determine the machine identifier, the process id and your counter value.

Make sure that you are protecting yourself against direct object reference attacks (which you should be doing anyway).

  • Could any of this information be used for an attack?
    – Ben
    Jul 23, 2014 at 0:08
  • I suppose if you had a shell injection vulnerability they could kill your mongo process or something. But they would probably be able to do that without knowing the exact process ID also. Jul 23, 2014 at 0:13
  • It seems like they removed the machine identifier bit in one of their later releases.
    – tyteen4a03
    Nov 20, 2018 at 15:28

MongoDB OID's are predictable. So if you have access restrictions you need to inforce, such as not allowing person A from Group 1 access to similarly classed objects belonging to persons in Group 2, then you will need to make sure you're application enforces these rules for all points of access.

A disastrous strategy, for example, would be to store an OID for a user in the browser, possibly acquired and stored after authZ, and use it for authN, since all that would be needed to change you're identity in the server would be to twiddle the browser-stored OID to match someone else's.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .