gchq/CyberChef · error · OperationError
${err}
Error message
${err} What it means
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.
Source
Thrown at src/core/operations/ParseObjectIDTimestamp.mjs:41
this.module = "Serialise";
this.description = "Parse timestamp from MongoDB/BSON ObjectID hex string.";
this.infoURL = "https://docs.mongodb.com/manual/reference/method/ObjectId.getTimestamp/";
this.inputType = "string";
this.outputType = "string";
this.args = [];
}
/**
* @param {string} input
* @param {Object[]} args
* @returns {string}
*/
run(input, args) {
try {
const objectId = new ObjectId(input);
return objectId.getTimestamp().toISOString();
} catch (err) {
throw new OperationError(err);
}
}
}
export default ParseObjectIDTimestamp;
View on GitHub (pinned to 4290ea7539)
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
Example fix
// before: "507f1f77" (too short) // after: "507f1f77bcf86cd799439011" (24 hex chars)
Defensive patterns
Strategy: validation
Validate before calling
// Pre-check: validate MongoDB ObjectId format
const OID_RE = /^[0-9a-fA-F]{24}$/;
if (!OID_RE.test(input.trim())) {
throw new Error("Input must be a 24-character hex MongoDB ObjectId.");
} Type guard
function isObjectId(s) {
return /^[0-9a-fA-F]{24}$/.test(s);
} Try / catch
try {
const result = chef.parseObjectIDTimestamp(input);
} catch (e) {
if (/argument|hex|length/i.test(e.message)) {
console.error("Provide a valid 24-char hex ObjectId like 507f1f77bcf86cd799439011");
} else { throw e; }
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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).
Related errors
- Byte length must be a positive integer
- More than 4 blocks.
- Badly formatted IPv6 address.
- Invalid input. Enter either a CIDR range (e.g. 10.0.0.0/24)
- Invalid IPv6 address
AI-assisted analysis of gchq/CyberChef@4290ea7539 (2026-08-13).
Data as JSON: /api/errors/c292eaa1f31d15da.
Report an issue: GitHub.