{"record":{"id":"b6db52558b474f96","repo":"phacility/phabricator","slug":"credential-has-no-public-key","errorCode":null,"errorMessage":"Credential has no public key!","messagePattern":"Credential has no public key!","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"src/applications/passphrase/controller/PassphraseCredentialPublicController.php","lineNumber":29,"sourceCode":"      ->setViewer($viewer)\n      ->withIDs(array($id))\n      ->requireCapabilities(\n        array(\n          PhabricatorPolicyCapability::CAN_VIEW,\n        ))\n      ->executeOne();\n    if (!$credential) {\n      return new Aphront404Response();\n    }\n\n    $type = PassphraseCredentialType::getTypeByConstant(\n      $credential->getCredentialType());\n    if (!$type) {\n      throw new Exception(pht('Credential has invalid type \"%s\"!', $type));\n    }\n\n    if (!$type->hasPublicKey()) {\n      throw new Exception(pht('Credential has no public key!'));\n    }\n\n    $view_uri = '/'.$credential->getMonogram();\n\n    $public_key = $type->getPublicKey($viewer, $credential);\n\n    $body = id(new PHUIFormLayoutView())\n      ->appendChild(\n        id(new AphrontFormTextAreaControl())\n          ->setLabel(pht('Public Key'))\n          ->setReadOnly(true)\n          ->setValue($public_key));\n\n    return $this->newDialog()\n      ->setWidth(AphrontDialogView::WIDTH_FORM)\n      ->setTitle(pht('Public Key (%s)', $credential->getMonogram()))\n      ->appendChild($body)\n      ->addCancelButton($view_uri, pht('Done'));","sourceCodeStart":11,"sourceCodeEnd":47,"githubUrl":"https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/passphrase/controller/PassphraseCredentialPublicController.php#L11-L47","documentation":"Thrown by PassphraseCredentialPublicController when the credential's type implementation returns false from hasPublicKey(). Only key-like types (SSH keys, certificates) can expose a public component; password, token, and other secret types have no public view at all, so the /K<id>/public page rejects them before calling getPublicKey().","triggerScenarios":"Navigating to /K<id>/public for a password, API-token, or other non-key credential; templates or menus that unconditionally link the 'Public Key' action for every credential.","commonSituations":"UI code assuming every credential has a public view; scripts scraping the public-key page for all credentials in an install; users hand-entering the URL.","solutions":["Only render/expose the public-key link when $type->hasPublicKey() is true.","For non-key credentials, use the appropriate workflow (secret reveal under high security, or the type's own views).","Hide the action in menus and object lists rather than letting the page throw."],"exampleFix":"// before\n$items[] = id(new PHUIListItemView())\n  ->setHref('/K'.$credential->getID().'/public')\n  ->setName(pht('Public Key'));\n\n// after\n$type = $credential->getImplementation();\nif ($type && $type->hasPublicKey()) {\n  $items[] = id(new PHUIListItemView())\n    ->setHref('/K'.$credential->getID().'/public')\n    ->setName(pht('Public Key'));\n}","handlingStrategy":"validation","validationCode":"$type = PassphraseCredentialType::getTypeByConstant(\n  $credential->getCredentialType());\nif (!$type || !$type->hasPublicKey()) {\n  // do not link or route to /K<id>/public\n}","typeGuard":"function credential_has_public_key($credential) {\n  $type = $credential->getImplementation();\n  return $type !== null && $type->hasPublicKey();\n}","tryCatchPattern":"try {\n  $public_key = $type->getPublicKey($viewer, $credential);\n} catch (Exception $ex) {\n  // wrong credential kind: prompt for a key-type credential\n}","preventionTips":["Render the 'Public Key' action only when hasPublicKey() is true.","Filter credential pickers by provides type so users never select key-incompatible credentials for key workflows.","Teach users that password/token credentials intentionally have no public view."],"tags":["phabricator","passphrase","credentials","public-key","validation"],"backgroundTag":"unsupported-credential-operation","analyzedSha":"5720a38cfe95b00ca4be5016dd0d2f3195f4fa04","analyzedAt":"2026-08-21T05:07:25.672Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}