1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-22 19:23:52 +00:00

Improve WebAuthn error detection for invalid data (#946)

This commit is contained in:
Oscar Hinton
2021-04-23 21:07:15 +02:00
committed by GitHub
parent 2392d34ed8
commit d71d0d9af6
3 changed files with 18 additions and 22 deletions

View File

@@ -27,6 +27,20 @@ export function b64Decode(str: string) {
}).join(''));
}
export function parseWebauthnJson(jsonString: string) {
const json = JSON.parse(jsonString);
const challenge = json.challenge.replace(/-/g, '+').replace(/_/g, '/');
json.challenge = Uint8Array.from(atob(challenge), c => c.charCodeAt(0));
json.allowCredentials.forEach((listItem: any) => {
const fixedId = listItem.id.replace(/\_/g, '/').replace(/\-/g, '+');
listItem.id = Uint8Array.from(atob(fixedId), c => c.charCodeAt(0));
});
return json;
}
// From https://github.com/abergs/fido2-net-lib/blob/b487a1d47373ea18cd752b4988f7262035b7b54e/Demo/wwwroot/js/helpers.js#L34
// License: https://github.com/abergs/fido2-net-lib/blob/master/LICENSE.txt
function coerceToBase64Url(thing: any) {