{"record":{"id":"e7e4c0b2accadd3f","repo":"usebruno/bruno","slug":"getrandomvalues-invalid-typed-array-object","errorCode":null,"errorMessage":"getRandomValues: Invalid typed array object","messagePattern":"getRandomValues: Invalid typed array object","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"packages/bruno-js/src/sandbox/quickjs/shims/lib/utils.js","lineNumber":26,"sourceCode":"\nfunction deserializeTypedArray(obj) {\n  // Allowed typed array constructors for crypto operations\n  const allowedConstructors = new Set([\n    'Int8Array',\n    'Uint8Array',\n    'Uint8ClampedArray',\n    'Int16Array',\n    'Uint16Array',\n    'Int32Array',\n    'Uint32Array',\n    'Float32Array',\n    'Float64Array',\n    'BigInt64Array',\n    'BigUint64Array'\n  ]);\n\n  if (!obj || typeof obj !== 'object') {\n    throw new TypeError('getRandomValues: Invalid typed array object');\n  }\n\n  if (typeof obj.type !== 'string' || !allowedConstructors.has(obj.type)) {\n    throw new TypeError(`getRandomValues: Invalid or unsupported typed array type: ${obj.type}`);\n  }\n\n  if (!obj.array || typeof obj.length !== 'number') {\n    throw new TypeError('getRandomValues: Invalid typed array properties');\n  }\n\n  const ctor = globalThis[obj.type];\n  if (typeof ctor !== 'function') {\n    throw new TypeError(`getRandomValues: Constructor ${obj.type} is not available`);\n  }\n\n  return new ctor(obj.array, 0, obj.length);\n}\n","sourceCodeStart":8,"sourceCodeEnd":44,"githubUrl":"https://github.com/usebruno/bruno/blob/9bdd81c7bdc57006e5f5ebffb79321a8d979f712/packages/bruno-js/src/sandbox/quickjs/shims/lib/utils.js#L8-L44","documentation":"Thrown by deserializeTypedArray (QuickJS crypto shim utils) when the serialized value passed to crypto.getRandomValues is not a non-null object. The deserializer expects a shape like { type, array, length } produced by serializeTypedArray; anything else (null, undefined, number, string) fails this first guard.","triggerScenarios":"Calling crypto.getRandomValues(null), crypto.getRandomValues(undefined), crypto.getRandomValues(123), or crypto.getRandomValues('abc') inside a QuickJS-sandboxed script.","commonSituations":"A variable that was supposed to hold a typed array is undefined because an earlier step failed; a function default parameter leaked through; the wrong argument was passed (e.g. a plain number instead of a Uint8Array).","solutions":["Pass an actual typed array: `crypto.getRandomValues(new Uint8Array(16))`.","Guard the call site: `if (!(arr instanceof Uint8Array)) throw new TypeError('arr must be a typed array')`.","Initialize the variable before the call so it is never undefined."],"exampleFix":"// before\nlet iv;\ncrypto.getRandomValues(iv); // iv is undefined\n\n// after\nconst iv = new Uint8Array(12);\ncrypto.getRandomValues(iv);","handlingStrategy":"type-guard","validationCode":"function fillRandom(v) {\n  if (!(v && typeof v === 'object')) throw new TypeError('expected typed array');\n  return crypto.getRandomValues(v);\n}","typeGuard":"const isTypedArray = (v) => v != null && typeof v === 'object' && ArrayBuffer.isView(v) && !(v instanceof DataView);","tryCatchPattern":"try { crypto.getRandomValues(maybeArr); }\ncatch (err) {\n  if (/Invalid typed array object/.test(err.message)) {\n    crypto.getRandomValues(new Uint8Array(16));\n  } else throw err;\n}","preventionTips":["Always construct a typed array before calling getRandomValues.","Guard against undefined from failed upstream steps."],"tags":["bruno-js","quickjs","sandbox","crypto","webcrypto","validation","type-guard"],"backgroundTag":null,"analyzedSha":"9bdd81c7bdc57006e5f5ebffb79321a8d979f712","analyzedAt":"2026-08-13T04:09:25.751Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}