Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Demo] Explicit check on return type from getAuthenticatorData and getPublicKey #11

Merged
merged 4 commits into from
Mar 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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