From 7fc1f6aacb81dff557bf83478e7ba8a288390a8a Mon Sep 17 00:00:00 2001 From: Tyler James Leonhardt Date: Wed, 25 Jan 2023 12:32:00 -0800 Subject: [PATCH] use better mechanism for base64 decoding with unicode characters (#172445) Fixes #172441 --- extensions/microsoft-authentication/src/browser/buffer.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/extensions/microsoft-authentication/src/browser/buffer.ts b/extensions/microsoft-authentication/src/browser/buffer.ts index 4753622f742..794bb19f579 100644 --- a/extensions/microsoft-authentication/src/browser/buffer.ts +++ b/extensions/microsoft-authentication/src/browser/buffer.ts @@ -8,6 +8,10 @@ export function base64Encode(text: string): string { } export function base64Decode(text: string): string { - const data = atob(text); - return data; + // modification of https://stackoverflow.com/a/38552302 + const replacedCharacters = text.replace(/-/g, '+').replace(/_/g, '/'); + const decodedText = decodeURIComponent(atob(replacedCharacters).split('').map(function (c) { + return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2); + }).join('')); + return decodedText; }