{"record":{"id":"c292eaa1f31d15da","repo":"gchq/CyberChef","slug":"err-c292ea","errorCode":null,"errorMessage":"${err}","messagePattern":"\\$\\{err\\}","errorType":"exception","errorClass":"OperationError","httpStatus":null,"severity":"error","filePath":"src/core/operations/ParseObjectIDTimestamp.mjs","lineNumber":41,"sourceCode":"        this.module = \"Serialise\";\n        this.description = \"Parse timestamp from MongoDB/BSON ObjectID hex string.\";\n        this.infoURL = \"https://docs.mongodb.com/manual/reference/method/ObjectId.getTimestamp/\";\n        this.inputType = \"string\";\n        this.outputType = \"string\";\n        this.args = [];\n    }\n\n    /**\n     * @param {string} input\n     * @param {Object[]} args\n     * @returns {string}\n     */\n    run(input, args) {\n        try {\n            const objectId = new ObjectId(input);\n            return objectId.getTimestamp().toISOString();\n        } catch (err) {\n            throw new OperationError(err);\n        }\n    }\n\n}\n\nexport default ParseObjectIDTimestamp;\n","sourceCodeStart":23,"sourceCodeEnd":48,"githubUrl":"https://github.com/gchq/CyberChef/blob/4290ea753912378913b1f3f54e0fc5720afeda5d/src/core/operations/ParseObjectIDTimestamp.mjs#L23-L48","documentation":"The operation constructs a BSON ObjectId from the input string and extracts its embedded timestamp. The bson library's ObjectId constructor throws if the input is not a valid 24-character hex string (12 bytes). This catch wraps that error as an OperationError.","triggerScenarios":"new ObjectId(input) rejects because the input is not exactly 24 hexadecimal characters. Causes include: wrong length (too short or too long), non-hex characters (letters beyond a-f), empty string, or a buffer of the wrong size.","commonSituations":"User enters a short hex string, a GUID/UUID instead of a MongoDB ObjectId, a decimal number, or text. User pastes an ObjectId with trailing whitespace or a newline. User enters an ObjectId from a system that uses a different format (e.g., a Firebase push ID).","solutions":["Provide a valid 24-character hexadecimal MongoDB ObjectId (e.g., 507f1f77bcf86cd799439011)","Trim any whitespace, newlines, or surrounding quotes from the input","If the input is a different ID format, convert it to a BSON ObjectId first"],"exampleFix":"// before: \"507f1f77\" (too short)\n// after:  \"507f1f77bcf86cd799439011\" (24 hex chars)","handlingStrategy":"validation","validationCode":"// Pre-check: validate MongoDB ObjectId format\nconst OID_RE = /^[0-9a-fA-F]{24}$/;\nif (!OID_RE.test(input.trim())) {\n  throw new Error(\"Input must be a 24-character hex MongoDB ObjectId.\");\n}","typeGuard":"function isObjectId(s) {\n  return /^[0-9a-fA-F]{24}$/.test(s);\n}","tryCatchPattern":"try {\n  const result = chef.parseObjectIDTimestamp(input);\n} catch (e) {\n  if (/argument|hex|length/i.test(e.message)) {\n    console.error(\"Provide a valid 24-char hex ObjectId like 507f1f77bcf86cd799439011\");\n  } else { throw e; }\n}","preventionTips":["Trim whitespace and quotes from the ObjectId string","Verify the input is exactly 24 hexadecimal characters","Do not pass UUIDs, decimal numbers, or other ID formats"],"tags":["mongodb","bson","objectid","parsing","validation"],"backgroundTag":null,"analyzedSha":"4290ea753912378913b1f3f54e0fc5720afeda5d","analyzedAt":"2026-08-13T06:05:50.210Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}