From 69d2862fe5c6fe6594203636e189eb8687e7d22d Mon Sep 17 00:00:00 2001 From: Todd Martin <106564991+trmartin4@users.noreply.github.com> Date: Mon, 6 Nov 2023 09:40:06 -0500 Subject: [PATCH] Added separate function for GUID validation for passkeys (#6806) --- .../src/vault/services/fido2/guid-utils.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/libs/common/src/vault/services/fido2/guid-utils.ts b/libs/common/src/vault/services/fido2/guid-utils.ts index 66e6cbb1d7..92c69c29eb 100644 --- a/libs/common/src/vault/services/fido2/guid-utils.ts +++ b/libs/common/src/vault/services/fido2/guid-utils.ts @@ -7,14 +7,12 @@ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.*/ -import { Utils } from "../../../platform/misc/utils"; - /** Private array used for optimization */ const byteToHex = Array.from({ length: 256 }, (_, i) => (i + 0x100).toString(16).substring(1)); /** Convert standard format (XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX) UUID to raw 16 byte array. */ export function guidToRawFormat(guid: string) { - if (!Utils.isGuid(guid)) { + if (!isValidGuid(guid)) { throw TypeError("GUID parameter is invalid"); } @@ -83,13 +81,15 @@ export function guidToStandardFormat(bufferSource: BufferSource) { ).toLowerCase(); // Consistency check for valid UUID. If this throws, it's likely due to one - // of the following: - // - One or more input array values don't map to a hex octet (leading to - // "undefined" in the uuid) - // - Invalid input values for the RFC `version` or `variant` fields - if (!Utils.isGuid(guid)) { + // or more input array values not mapping to a hex octet (leading to "undefined" in the uuid) + if (!isValidGuid(guid)) { throw TypeError("Converted GUID is invalid"); } return guid; } + +// Perform format validation, without enforcing any variant restrictions as Utils.isGuid does +function isValidGuid(guid: string): boolean { + return RegExp(/^[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/, "i").test(guid); +}