From 502d8ed729502a73ebf93ad0937100df6577f417 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20B=C3=A4rtschi?= <19628374+m-baertschi@users.noreply.github.com> Date: Wed, 18 Sep 2024 14:11:22 +0200 Subject: [PATCH] fix wrong buffer conversion for Uint8Array (#8787) If the BufferSource is already an Uint8Array which is a view of a subset of the underlying ArrayBuffer then accessing .buffer caused the whole backing buffer to be returned. Fix this by just returning the original Uint8Array as-is. Co-authored-by: Justin Baur <19896123+justindbaur@users.noreply.github.com> --- libs/common/src/platform/services/fido2/fido2-utils.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/libs/common/src/platform/services/fido2/fido2-utils.ts b/libs/common/src/platform/services/fido2/fido2-utils.ts index 13c9762135..c3c3eba246 100644 --- a/libs/common/src/platform/services/fido2/fido2-utils.ts +++ b/libs/common/src/platform/services/fido2/fido2-utils.ts @@ -17,8 +17,10 @@ export class Fido2Utils { return Fido2Utils.fromB64ToArray(Fido2Utils.fromUrlB64ToB64(str)); } - static bufferSourceToUint8Array(bufferSource: BufferSource) { - if (Fido2Utils.isArrayBuffer(bufferSource)) { + static bufferSourceToUint8Array(bufferSource: BufferSource): Uint8Array { + if (bufferSource instanceof Uint8Array) { + return bufferSource; + } else if (Fido2Utils.isArrayBuffer(bufferSource)) { return new Uint8Array(bufferSource); } else { return new Uint8Array(bufferSource.buffer);