Skip to content

Commit

Permalink
Merge pull request #11 from dodobrands/demo-bugfix
Browse files Browse the repository at this point in the history
[Demo] Explicit check on return type from getAuthenticatorData and getPublicKey
  • Loading branch information
vanbukin authored Mar 23, 2024
2 parents cb6a939 + 7f26ab1 commit 7624ace
Showing 1 changed file with 23 additions and 6 deletions.
29 changes: 23 additions & 6 deletions demo/WebAuthn.Net.Demo.Mvc/wwwroot/js/lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,9 @@ const Alerts = {
registerSuccess: () => alert("User registered!"),
usernameInputEmpty: () => alert("Username input is empty"),
credentialsGetApiNull: () => alert("navigator.credentials.get returned null"),
credentialsCreateApiNull: () => alert("navigator.credentials.create returned null")
credentialsCreateApiNull: () => alert("navigator.credentials.create returned null"),
getAuthenticatorDataInvalid: () => alert("Invalid data from getAuthenticatorData() method. Expected arraybuffer"),
getPublicKeyInvalid: () => alert("Invalid data from getPublicKey() method. Expected arraybuffer")
};

// API
Expand All @@ -127,12 +129,27 @@ const API = {
const clientExtensionResults = newCredential.getClientExtensionResults ?
(newCredential.getClientExtensionResults() ?? {}) : {};

const authenticatorData = newCredential.response.getAuthenticatorData ?
coerceToBase64Url(newCredential.response.getAuthenticatorData()) : undefined;
let authenticatorData;
if (newCredential.response.getAuthenticatorData) {
const authData = newCredential.response.getAuthenticatorData();
const isValid = authData instanceof ArrayBuffer;
if (!isValid) {
Alerts.getAuthenticatorDataInvalid();
return;
}
authenticatorData = coerceToBase64Url(authData);
}

const responsePublicKey = newCredential.response.getPublicKey ?
newCredential.response.getPublicKey() : undefined;
const publicKey = responsePublicKey ? coerceToBase64Url(responsePublicKey) : undefined;
let publicKey;
if (newCredential.response.getPublicKey) {
const responsePublicKey = newCredential.response.getPublicKey();
const isValid = responsePublicKey instanceof ArrayBuffer;
if (!isValid) {
Alerts.getPublicKeyInvalid();
return;
}
publicKey = coerceToBase64Url(responsePublicKey);
}

const transports = newCredential.response.getTransports ?
newCredential.response.getTransports() : undefined;
Expand Down

0 comments on commit 7624ace

Please sign in to comment.