From b9642961acb7be0f651e1eb0b9b12bf076463935 Mon Sep 17 00:00:00 2001 From: kric_jspark Date: Fri, 8 May 2026 11:23:54 +0900 Subject: [PATCH] =?UTF-8?q?260508=5F11=5FENH:=20=EC=83=88=EB=A1=9C?= =?UTF-8?q?=EA=B3=A0=EC=B9=A8=20=EC=8B=9C=20=EB=A1=9C=EA=B7=B8=EC=9D=B8=20?= =?UTF-8?q?=ED=92=80=EB=A6=AC=EB=8A=94=20=EB=AC=B8=EC=A0=9C=20=EC=88=98?= =?UTF-8?q?=EC=A0=95=20=EC=A4=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/lib/security.ts | 3 +-- src/store/storage/secure-storage.ts | 33 ++++++++++++++++++++++++----- 2 files changed, 29 insertions(+), 7 deletions(-) diff --git a/src/lib/security.ts b/src/lib/security.ts index 752fdfa..b32b780 100644 --- a/src/lib/security.ts +++ b/src/lib/security.ts @@ -165,8 +165,7 @@ export class Security { } public static encodeBase64(input: WordArray): string { - const base64 = CryptoJS.enc.Base64.stringify(input); - return this.convertToSpecialChars(base64); + return CryptoJS.enc.Base64.stringify(input); } public static decodeBase64(input: string): WordArray { diff --git a/src/store/storage/secure-storage.ts b/src/store/storage/secure-storage.ts index 7f58358..670ace1 100644 --- a/src/store/storage/secure-storage.ts +++ b/src/store/storage/secure-storage.ts @@ -22,9 +22,20 @@ const parseStoredValue = (value: string): StorageValue => { const stringifyStorageValue = (value: StorageValue): string => { const stringifyValue = JSON.stringify(value); - return stringifyValue; + return clientEnv.ENV === "prod" ? Security.encryptBase64(stringifyValue) : stringifyValue; }; +const isPlainJsonValue = (value: string) => { + const trimmed = value.trim(); + return trimmed.startsWith("{") || trimmed.startsWith("["); +}; + +const isLegacyEncryptedStorageValue = (value: string) => + value.includes("\u200b") || value.includes("\u200c"); + +const shouldMigrateStorageValue = (value: string) => + isPlainJsonValue(value) || isLegacyEncryptedStorageValue(value); + export const setLocalStorage = (key: string, value: StorageValue): void => { try { localStorage.setItem(key, stringifyStorageValue(value)); @@ -41,10 +52,16 @@ export const getLocalStorage = (key: string): StorageValue => { } try { - return parseStoredValue(storedValue); + const parsedValue = parseStoredValue(storedValue); + if (parsedValue != null && shouldMigrateStorageValue(storedValue)) { + localStorage.setItem(key, stringifyStorageValue(parsedValue)); + } + return parsedValue; } catch (decryptError) { try { - return JSON.parse(storedValue); + const parsedValue = JSON.parse(storedValue); + localStorage.setItem(key, stringifyStorageValue(parsedValue)); + return parsedValue; } catch (fallbackError) { console.warn("[storage] localStorage parse failed", { key, @@ -84,10 +101,16 @@ export const getSessionStorage = (key: string): StorageValue => { } try { - return parseStoredValue(storedValue); + const parsedValue = parseStoredValue(storedValue); + if (parsedValue != null && shouldMigrateStorageValue(storedValue)) { + sessionStorage.setItem(key, stringifyStorageValue(parsedValue)); + } + return parsedValue; } catch (decryptError) { try { - return JSON.parse(storedValue); + const parsedValue = JSON.parse(storedValue); + sessionStorage.setItem(key, stringifyStorageValue(parsedValue)); + return parsedValue; } catch (fallbackError) { console.warn("[storage] sessionStorage parse failed", { key,