{"record":{"id":"c5ffcccd9f50edfa","repo":"usebruno/bruno","slug":"decrypt-failed-unrecognized-string-format","errorCode":null,"errorMessage":"Decrypt failed: unrecognized string format","messagePattern":"Decrypt failed: unrecognized string format","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/bruno-electron/src/utils/encryption.js","lineNumber":131,"sourceCode":"      return `$${AES256_ALGO}:${encryptedString}`;\n    } catch (err) {\n      // Any error indicates the passkey is unusable; return empty string\n      return '';\n    }\n  }\n\n  if (safeStorage && safeStorage.isEncryptionAvailable()) {\n    const encryptedString = safeStorageEncrypt(str);\n    return `$${ELECTRONSAFESTORAGE_ALGO}:${encryptedString}`;\n  }\n\n  const encryptedString = aes256Encrypt(str);\n  return `$${AES256_ALGO}:${encryptedString}`;\n}\n\nfunction decryptString(str, passkey = null) {\n  if (typeof str !== 'string') {\n    throw new Error('Decrypt failed: unrecognized string format');\n  }\n  if (str.length === 0) {\n    return '';\n  }\n\n  // Find the index of the first colon\n  const colonIndex = str.indexOf(':');\n\n  if (colonIndex === -1) {\n    throw new Error('Decrypt failed: unrecognized string format');\n  }\n\n  // Extract algo and encryptedString based on the colon index\n  const algo = str.substring(1, colonIndex);\n  const encryptedString = str.substring(colonIndex + 1);\n\n  if ([ELECTRONSAFESTORAGE_ALGO, AES256_ALGO].indexOf(algo) === -1) {\n    throw new Error('Decrypt failed: Invalid algo');","sourceCodeStart":113,"sourceCodeEnd":149,"githubUrl":"https://github.com/usebruno/bruno/blob/9bdd81c7bdc57006e5f5ebffb79321a8d979f712/packages/bruno-electron/src/utils/encryption.js#L113-L149","documentation":"Thrown by decryptString when typeof str !== 'string'. This is the input-type guard at the top of the function, before any format parsing. It fires when the caller hands in null, undefined, a Buffer, a number, or an object instead of a string.","triggerScenarios":"Calling decryptString(null), decryptString(undefined), or decryptString(someBuffer) — typically because a missing DB/config value was forwarded without a presence check, or a Buffer was not first converted to a string.","commonSituations":"Optional secret field not populated in storage and passed through unguarded; refactor changed the stored type from string to Buffer/JSON; value loaded from a column that returned null.","solutions":["Null/empty-check before calling decryptString (empty string short-circuits to '' inside the function, so coerce null/undefined to '').","If you hold a Buffer, call .toString('hex') or the appropriate encoding first.","Prefer decryptStringSafe which returns {success:false} instead of throwing on bad input."],"exampleFix":"// before\nconst plain = decryptString(maybeMissing);\n\n// after\nconst plain = (typeof maybeMissing === 'string' && maybeMissing.length)\n  ? decryptString(maybeMissing)\n  : '';\n// or simply:\nconst { value } = decryptStringSafe(maybeMissing ?? '');","handlingStrategy":"type-guard","validationCode":"function decryptStringOrEmpty(str) {\n  if (typeof str !== 'string') return '';\n  if (str.length === 0) return '';\n  return decryptString(str);\n}","typeGuard":"function isEncryptedString(value) {\n  return typeof value === 'string';\n}","tryCatchPattern":"const { success, value } = decryptStringSafe(typeof stored === 'string' ? stored : '');\nreturn success ? value : '';","preventionTips":["Coerce null/undefined to '' before calling decryptString.","Convert Buffers to strings with the correct encoding first.","Prefer decryptStringSafe in all read paths."],"tags":["encryption","type-guard","null-handling"],"backgroundTag":null,"analyzedSha":"9bdd81c7bdc57006e5f5ebffb79321a8d979f712","analyzedAt":"2026-08-13T04:09:25.751Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}