fix(miniprogram): 小程序审计修复 — 安全加固+功能链路+输入验证
安全修复: - H1: Token 刷新竞态条件 → Singleton Promise 模式防止并发刷新 - H4: 移除 store 中的 token 明文状态,统一走 secure storage - H5: 登录/绑定手机号添加 loading 防重复点击保护 - H6: Analytics 改用 request.ts 统一请求层,不再绕过认证 - M1: logout 清理所有残留数据(openid/tenant_id/analytics_queue) - M2/M7: 敏感数据(user/openid/tenant_id)统一走加密存储 - M3: 移除开发日志中的请求体打印 - M4: secure-storage 解密失败返回 null 而非空串 功能修复: - F1: 今日体征概览 API 支持 patient_id 查询参数(后端+前端) - F2: 积分商城对无患者档案用户展示引导 UI - M6: daily-monitoring 添加 Zod 数值范围验证 清理: - L4: 移除 devLogin 开发辅助函数
This commit is contained in:
@@ -18,7 +18,7 @@ function encrypt(plaintext: string): string {
|
||||
return CryptoJS.AES.encrypt(plaintext, ENCRYPTION_KEY).toString();
|
||||
}
|
||||
|
||||
function decrypt(ciphertext: string): string {
|
||||
function decrypt(ciphertext: string): string | null {
|
||||
if (!ENCRYPTION_KEY) {
|
||||
if (process.env.NODE_ENV === 'production') {
|
||||
throw new Error('[secure-storage] TARO_APP_ENCRYPTION_KEY 未设置,生产环境禁止明文读取');
|
||||
@@ -27,9 +27,11 @@ function decrypt(ciphertext: string): string {
|
||||
}
|
||||
try {
|
||||
const bytes = CryptoJS.AES.decrypt(ciphertext, ENCRYPTION_KEY);
|
||||
return bytes.toString(CryptoJS.enc.Utf8);
|
||||
const result = bytes.toString(CryptoJS.enc.Utf8);
|
||||
if (!result) return null;
|
||||
return result;
|
||||
} catch {
|
||||
return '';
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,7 +43,8 @@ export function secureSet(key: string, value: string): void {
|
||||
export function secureGet(key: string): string {
|
||||
const raw = Taro.getStorageSync(key);
|
||||
if (!raw || typeof raw !== 'string') return '';
|
||||
return decrypt(raw);
|
||||
const result = decrypt(raw);
|
||||
return result ?? '';
|
||||
}
|
||||
|
||||
export function secureRemove(key: string): void {
|
||||
|
||||
Reference in New Issue
Block a user