{"record":{"id":"25c63a4ce89c08b5","repo":"mozilla/pdf.js","slug":"no-password-given","errorCode":null,"errorMessage":"No password given","messagePattern":"No password given","errorType":"exception","errorClass":"PasswordException","httpStatus":null,"severity":"error","filePath":"src/core/crypto.js","lineNumber":1216,"sourceCode":"    }\n    if (!encryptionKey) {\n      if (!password) {\n        if (\n          this.algorithm >= 4 &&\n          isName(this.stmf, \"Identity\") &&\n          isName(this.strf, \"Identity\")\n        ) {\n          const effCF = this.cf?.get(this.eff.name);\n          const authEvent = effCF?.get(\"AuthEvent\");\n\n          if (isName(authEvent, \"EFOpen\")) {\n            // For EFOpen with Identity as default stream/string filters, defer\n            // password prompting until an EmbeddedFile stream is actually read.\n            this.encryptionKey = null;\n            return;\n          }\n        }\n        throw new PasswordException(\n          \"No password given\",\n          PasswordResponses.NEED_PASSWORD\n        );\n      }\n      // Attempting use the password as an owner password\n      const decodedPassword = this.#decodeUserPassword(\n        passwordBytes,\n        ownerPassword,\n        revision,\n        keyLength\n      );\n      encryptionKey = this.#prepareKeyData(\n        fileIdBytes,\n        decodedPassword,\n        ownerPassword,\n        userPassword,\n        flags,\n        revision,","sourceCodeStart":1198,"sourceCodeEnd":1234,"githubUrl":"https://github.com/mozilla/pdf.js/blob/5903d58d58e4dd9ce6ffa3834aea8480f06b4ada/src/core/crypto.js#L1198-L1234","documentation":"PasswordException with NEED_PASSWORD code, thrown when no encryption key could be derived and no password was supplied—and the deferred-password EFOpen/Identity case does not apply. PDF.js needs a password to derive the encryption key and none was passed to getDocument({password}).","triggerScenarios":"Calling getDocument on a user/owner-password-protected PDF without passing the password option; the document requires a password but the UI has not yet prompted the user.","commonSituations":"Forgetting to pass the password; a user-facing viewer that has not yet shown the password dialog; chained loads where the password lives elsewhere.","solutions":["Pass the password: getDocument({ url, password }).","Inspect the loadingTask promise rejection, check err.code === PasswordResponses.NEED_PASSWORD (value 1), then prompt the user and call pdfDocument.updatePassword(pwd).","For UIs, listen to the 'passwordrequest' event and surface a dialog."],"exampleFix":"// before\nconst doc = await getDocument({ url }).promise;\n\n// after — prompt on NEED_PASSWORD and retry\nlet task = getDocument({ url });\ntry {\n  const doc = await task.promise;\n} catch (e) {\n  if (e.name === 'PasswordException' && e.code === 1) {\n    const pwd = await promptUserForPassword();\n    doc = await task.promise.catch(async () => {\n      await task.destroy();\n      return (task = getDocument({ url, password: pwd })).promise;\n    });\n  }\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"let task = getDocument({ url });\ntry {\n  return await task.promise;\n} catch (e) {\n  if (e.name === 'PasswordException' && e.code === PasswordResponses.NEED_PASSWORD) {\n    const pwd = await promptUserForPassword();\n    await task.destroy();\n    return await getDocument({ url, password: pwd }).promise;\n  }\n  throw e;\n}","preventionTips":["Always handle the NEED_PASSWORD code in your getDocument rejection handler.","Use loadingTask.onPassword callback for interactive viewers rather than throwing.","Avoid hard-coded empty passwords; treat undefined password as 'prompt'."],"tags":["encryption","pdf-security","password","authentication"],"backgroundTag":null,"analyzedSha":"5903d58d58e4dd9ce6ffa3834aea8480f06b4ada","analyzedAt":"2026-08-13T02:28:27.364Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}