Compare commits

..

14 Commits

Author SHA1 Message Date
4a30758d7f 260508_15_ENH: 필요없는 로그 걷어냄 2026-05-08 11:36:20 +09:00
e93f6c8f41 260508_14_ENH: 새로고침 시 로그인 풀리는 문제 수정 중 2026-05-08 11:34:10 +09:00
b73d5d55fb 260508_13_ENH: 새로고침 시 로그인 풀리는 문제 수정 중 2026-05-08 11:30:58 +09:00
4a06fc7e83 260508_12_ENH: 새로고침 시 로그인 풀리는 문제 수정 중 2026-05-08 11:27:20 +09:00
b9642961ac 260508_11_ENH: 새로고침 시 로그인 풀리는 문제 수정 중 2026-05-08 11:23:54 +09:00
e528f6a67e 260508_10_ENH: 새로고침 시 로그인 풀리는 문제 수정 중 2026-05-08 11:12:44 +09:00
e224455dea 260508_09_ENH: 새로고침 시 로그인 풀리는 문제 수정 중 2026-05-08 11:08:22 +09:00
c7b0655ec2 260508_08_ENH: 새로고침 시 로그인 풀리는 문제 수정 중 2026-05-08 11:04:18 +09:00
8c0b19d542 260508_07_ENH: 새로고침 시 로그인 풀리는 문제 수정 중 2026-05-08 10:59:44 +09:00
b3c9a8f6ee 260508_06_ENH: 새로고침 시 로그인 풀리는 문제 수정 중 2026-05-08 10:57:59 +09:00
5fe38e1c90 260508_05_ENH: 새로고침 시 로그인 풀리는 문제 수정 2026-05-08 10:54:18 +09:00
295b914f0f 260508_04_ENH: 새로고침 시 로그인 풀리는 문제 수정 2026-05-08 10:44:58 +09:00
4c4ef662fd 260508_03_ENH: 새로고침 시 로그인 풀리는 문제 수정 2026-05-08 10:32:58 +09:00
b9fa6255b7 260508_02_ENH: 새로고침 시 로그인 풀리는 문제 수정 2026-05-08 10:23:02 +09:00
4 changed files with 50 additions and 82 deletions

View File

@@ -1,7 +1,7 @@
import CryptoJS from "crypto-js"; import CryptoJS from "crypto-js";
const KEY = CryptoJS.enc.Utf8.parse("kr!-Kfp@-fr0nT-CrypT0-Key-STR"); const KEY = CryptoJS.enc.Utf8.parse("kr!-Kfp@-fr0nT-CrypT0-Key-STR!!!");
const IV = CryptoJS.enc.Utf8.parse("kr!-Kfp@-IVST"); const IV = CryptoJS.enc.Utf8.parse("kr!-Kfp@Dash-IV!");
export type WordArray = CryptoJS.lib.WordArray; export type WordArray = CryptoJS.lib.WordArray;
@@ -143,17 +143,16 @@ export class Security {
} }
public static encodeBase64Url(input: WordArray): string { public static encodeBase64Url(input: WordArray): string {
const base64url = CryptoJS.enc.Base64url.stringify(input); return CryptoJS.enc.Base64url.stringify(input);
return this.convertToSpecialChars(base64url);
} }
public static decodeBase64Url(input: string): WordArray { public static decodeBase64Url(input: string): WordArray {
try { if (this.hasSpecialChars(input)) {
const base64url = this.convertFromSpecialChars(input); const base64url = this.convertFromSpecialChars(input);
return CryptoJS.enc.Base64url.parse(base64url); return CryptoJS.enc.Base64url.parse(base64url);
} catch {
return CryptoJS.enc.Base64url.parse(input);
} }
return CryptoJS.enc.Base64url.parse(input);
} }
public static encodeBase64Utf8(input: string): string { public static encodeBase64Utf8(input: string): string {
@@ -165,17 +164,20 @@ export class Security {
} }
public static encodeBase64(input: WordArray): string { public static encodeBase64(input: WordArray): string {
const base64 = CryptoJS.enc.Base64.stringify(input); return CryptoJS.enc.Base64.stringify(input);
return this.convertToSpecialChars(base64);
} }
public static decodeBase64(input: string): WordArray { public static decodeBase64(input: string): WordArray {
try { if (this.hasSpecialChars(input)) {
const base64 = this.convertFromSpecialChars(input); const base64 = this.convertFromSpecialChars(input);
return CryptoJS.enc.Base64.parse(base64); return CryptoJS.enc.Base64.parse(base64);
} catch {
return CryptoJS.enc.Base64.parse(input);
} }
return CryptoJS.enc.Base64.parse(input);
}
private static hasSpecialChars(input: string): boolean {
return input.includes("\u200b") || input.includes("\u200c");
} }
public static encodeHex(input: WordArray): string { public static encodeHex(input: WordArray): string {

View File

@@ -1,71 +1,50 @@
import { Security } from "@/lib/security"; import { Security } from "@/lib/security";
import {clientEnv} from "@/lib/env.client"; import { clientEnv } from "@/lib/env.client";
type StorageValue = any; // 요청대로 any 유지 type StorageValue = any;
// --- 내부 헬퍼 함수들 --- const parseStorageValue = (value: string): StorageValue => {
if (!value || value.trim() === "") {
const getDecryptedValue = (value: string): StorageValue => {
try {
if (!value || value.trim() === "") {
return null;
}
const decryptValue = clientEnv.ENV ==="prod" ? Security.decryptBase64(value) : value;
if (!decryptValue || decryptValue.trim() === "") {
return null;
}
return JSON.parse(decryptValue);
} catch (error) {
// 손상된 데이터인 경우 null 반환
return null; return null;
} }
const rawValue = clientEnv.ENV === "prod" ? Security.decryptBase64(value) : value;
if (!rawValue || rawValue.trim() === "") {
return null;
}
return JSON.parse(rawValue);
}; };
const getEncryptedValue = (value: StorageValue): string => { const stringifyStorageValue = (value: StorageValue): string => {
const stringifyValue = JSON.stringify(value); const rawValue = JSON.stringify(value);
return clientEnv.ENV ==="prod" ? Security.encryptBase64(stringifyValue) : stringifyValue; return clientEnv.ENV === "prod" ? Security.encryptBase64(rawValue) : rawValue;
}; };
// --- LocalStorage 함수들 ---
export const setLocalStorage = (key: string, value: StorageValue): void => { export const setLocalStorage = (key: string, value: StorageValue): void => {
try { try {
const encryptValue = getEncryptedValue(value); localStorage.setItem(key, stringifyStorageValue(value));
localStorage.setItem(key, encryptValue); } catch {}
} catch (error) {
// 필요하면 로깅 추가
}
}; };
export const getLocalStorage = (key: string): StorageValue => { export const getLocalStorage = (key: string): StorageValue => {
try { try {
const encryptValue: string | null = localStorage.getItem(key); const value = localStorage.getItem(key);
if (encryptValue === null || encryptValue === "") { if (value === null || value === "") {
return null; return null;
} }
let value: StorageValue = null;
try { try {
// 암호화된 값 복호화 시도 return parseStorageValue(value);
value = getDecryptedValue(encryptValue); } catch {
} catch (decryptError) {
// 복호화 실패 시 평문으로 파싱 시도 (fallback)
try { try {
value = JSON.parse(encryptValue); return JSON.parse(value);
} catch (fallbackError) { } catch {
// 완전히 실패한 경우 저장된 데이터 제거
localStorage.removeItem(key); localStorage.removeItem(key);
return null; return null;
} }
} }
} catch {
return value;
} catch (error) {
return null; return null;
} }
}; };
@@ -78,43 +57,30 @@ export const clearLocalStorage = (): void => {
localStorage.clear(); localStorage.clear();
}; };
// --- SessionStorage 함수들 ---
// 세션스토리지는 테스트/실제 서버 모두 암호화 없음
export const setSessionStorage = (key: string, value: StorageValue): void => { export const setSessionStorage = (key: string, value: StorageValue): void => {
try { try {
const encryptValue = getEncryptedValue(value); sessionStorage.setItem(key, stringifyStorageValue(value));
sessionStorage.setItem(key, encryptValue); } catch {}
} catch (error) {
// 필요하면 로깅 추가
}
}; };
export const getSessionStorage = (key: string): StorageValue => { export const getSessionStorage = (key: string): StorageValue => {
try { try {
const encryptValue: string | null = sessionStorage.getItem(key); const value = sessionStorage.getItem(key);
if (encryptValue === null || encryptValue === "") { if (value === null || value === "") {
return null; return null;
} }
let value: StorageValue = null;
try { try {
// 암호화된 값 복호화 시도 return parseStorageValue(value);
value = getDecryptedValue(encryptValue); } catch {
} catch (decryptError) {
// 복호화 실패 시 평문으로 파싱 시도 (fallback)
try { try {
value = JSON.parse(encryptValue); return JSON.parse(value);
} catch (fallbackError) { } catch {
// 완전히 실패한 경우 저장된 데이터 제거 sessionStorage.removeItem(key);
localStorage.removeItem(key);
return null; return null;
} }
} }
} catch {
return value;
} catch (error) {
return null; return null;
} }
}; };