fix(mp): Phase 0 基础设施修复 — secureGet 解密 + Storage 一致性
- secureGet: 移除错误的 startsWith 条件,始终尝试 XOR 解密 - request.ts: current_patient_id 读取改用 safeGet,清理改用 secureRemove - health.ts: getTodaySummary 使用 getCachedPatientId 替代直接 Storage - auth.ts: analytics_queue 清理改用明文 Taro.removeStorageSync
This commit is contained in:
@@ -57,16 +57,17 @@ export function secureGet(key: string): string {
|
||||
const raw = Taro.getStorageSync(prefixedKey);
|
||||
if (!raw || typeof raw !== 'string') return '';
|
||||
|
||||
if (raw.startsWith('{') || raw.startsWith('eyJ')) {
|
||||
try {
|
||||
const decoded = fromBase64(raw);
|
||||
if (decoded) {
|
||||
return xorEncrypt(decoded, ENCRYPTION_KEY);
|
||||
}
|
||||
} catch {
|
||||
// fallthrough
|
||||
// 始终尝试 base64 解码 + XOR 解密(secureSet 的写入格式)
|
||||
try {
|
||||
const decoded = fromBase64(raw);
|
||||
if (decoded) {
|
||||
return xorEncrypt(decoded, ENCRYPTION_KEY);
|
||||
}
|
||||
} catch {
|
||||
// fallthrough — 可能是未加密的旧数据
|
||||
}
|
||||
|
||||
// fallback: 兼容未加密的旧数据(明文 JSON/JWT 或其他值)
|
||||
return raw;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user