-
Type: Improvement
-
Resolution: Fixed
-
Priority: Major - P3
-
Affects Version/s: None
-
Component/s: None
-
None
BSON has multiple options that dictate serialization behavior. The current default flags are:
bson.serialize
/** * Serialize a Javascript object. * * @param {Object} object the Javascript object to serialize. * @param {Boolean} [options.checkKeys] the serializer will check if keys are valid. * @param {Boolean} [options.serializeFunctions=false] serialize the javascript functions **(default:false)**. * @param {Boolean} [options.ignoreUndefined=true] ignore undefined fields **(default:true)**. * @param {Number} [options.minInternalBufferSize=1024*1024*17] minimum size of the internal temporary serialization buffer **(default:1024*1024*17)**. * @return {Buffer} returns the Buffer object containing the serialized object. * @api public */
bson.deserialize
/** * Deserialize data as BSON. * * @param {Buffer} buffer the buffer containing the serialized set of BSON documents. * @param {Object} [options.evalFunctions=false] evaluate functions in the BSON document scoped to the object deserialized. * @param {Object} [options.cacheFunctions=false] cache evaluated functions for reuse. * @param {Object} [options.cacheFunctionsCrc32=false] use a crc32 code for caching, otherwise use the string of the function. * @param {Object} [options.promoteLongs=true] when deserializing a Long will fit it into a Number if it's smaller than 53 bits * @param {Object} [options.promoteBuffers=false] when deserializing a Binary will return it as a node.js Buffer instance. * @param {Object} [options.promoteValues=false] when deserializing will promote BSON values to their Node.js closest equivalent types. * @param {Object} [options.fieldsAsRaw=null] allow to specify if there what fields we wish to return as unserialized raw buffer. * @param {Object} [options.bsonRegExp=false] return BSON regular expressions as BSONRegExp instances. * @return {Object} returns the deserialized Javascript Object. * @api public */
These fields are currently NOT respected when using Client Side Encryption. This is especially problematic for AutoEncryption, which is supposed to be a seamless experience with no noticeable difference in experience. The two main problems are:
1. If serialization options are not respected, then we run the risk of corrupting user data on inserts / updates, and corrupting queries when doing reads. This includes both encrypted fields and unencrypted fields that are on the same document as an encrypted field.
2. If deserialization options are not respected, there can be a degree of client-side data loss w.r.t. type promotion of various number types. For example a user passing promoteLongs: false is expecting to get back a Long object instead of a promoted number.
3. If deserialization options are not respected, it makes for a confusing API experience.
4. (minor) the lack of deserialization option respect is blocking NODE-2052