MasterKale / SimpleWebAuthn

WebAuthn, Simplified. A collection of TypeScript-first libraries for simpler WebAuthn integration. Supports modern browsers, Node, Deno, and more.
https://simplewebauthn.dev
MIT License
1.63k stars 137 forks source link

Handle undefined `PublicKeyCredential` in `browserSupportsWebAuthnAutofill` helper #544

Closed clarafitzgerald closed 7 months ago

clarafitzgerald commented 7 months ago

Describe the issue

Currently, calling the browserSupportsWebAuthnAutofill helper on a browser without webauthn support will cause an error since it is trying to evaluate isConditionalMediationAvailable of undefined.

The helper should check whether PublicKeyCredential is defined first and resolve false if it isn't, similar to the platformAuthenticatorIsAvailable helper.

Code Samples + WebAuthn Options and Responses

import {
  browserSupportsWebAuthn,
  browserSupportsWebAuthnAutofill,
  platformAuthenticatorIsAvailable,
} from "@simplewebauthn/browser";

export const getPasskeySupportInfo = async () => {
  const hasWebAuthnSupport = browserSupportsWebAuthn();
  const hasWebAuthnAutofillSupport = await browserSupportsWebAuthnAutofill();
  const hasPlatformAuthenticator = await platformAuthenticatorIsAvailable();

  return {
    hasWebAuthnSupport,
    hasWebAuthnAutofillSupport,
    hasPlatformAuthenticator,
  };
};

Error message:

iOS: undefined is not an object (evaluating 'e.isConditionalMediationAvailable') Android: Cannot read properties of undefined (reading 'isConditionalMediationAvailable')

SimpleWebAuthn Libraries

$ npm list --depth=0 | grep @simplewebauthn
├── @simplewebauthn/browser@9.0.1
├── @simplewebauthn/types@9.0.1
# ...
MasterKale commented 7 months ago

@clarafitzgerald This fix is now available in the recently-published @simplewebauthn/browser@10.0.0 ✌️