fix: 修复后端竞态/安全/数据处理问题并移除冗余 outImage 列
首次激活改条件更新消除并发竞态;备份恢复补模型全集与版本校验防清库; 审核列表分页总数、操作日志未捕获 Promise、出库导入重复码、加密密钥可编辑、 溯源码盐以 env 为准、证书按 originKey reconcile、env 加载去重等修复; 新增 parseBigId 防非法入参 500、全局安全响应头、去除 SVG 上传、接入 throttler 限流、 入队失败补偿、hashData 稳定序列化、无效码负缓存、看板已激活口径调整; 移除冗余 TraceCode.outImage 列统一 outImages(迁移 drop_trace_code_out_image)。
This commit is contained in:
@@ -97,10 +97,38 @@ function reviveRow(row: Record<string, any>): Record<string, any> {
|
||||
return out;
|
||||
}
|
||||
|
||||
const BACKUP_FORMAT_VERSION = '0.1.0';
|
||||
|
||||
function isSafeZipPath(path: string): boolean {
|
||||
return !path.includes('\\') && !path.includes('..') && !path.startsWith('/') && !/^[a-z]:/i.test(path);
|
||||
}
|
||||
|
||||
// 恢复前的强校验:确认是 Artveris 备份、版本主号兼容、且 database.json 覆盖全部业务表,
|
||||
// 防止残缺/异构备份包在「先清空全表再按存在的键写回」时把整库清空。
|
||||
function validateBackupPayload(manifest: any, db: unknown): void {
|
||||
if (!manifest || manifest.app !== 'artveris') {
|
||||
throw new BusinessException(ErrorCode.BAD_REQUEST, '不是 Artveris 备份包');
|
||||
}
|
||||
const version = String(manifest.version || '');
|
||||
if (version.split('.')[0] !== BACKUP_FORMAT_VERSION.split('.')[0]) {
|
||||
throw new BusinessException(
|
||||
ErrorCode.BAD_REQUEST,
|
||||
`备份包版本不兼容(备份 ${version || '未知'},当前 ${BACKUP_FORMAT_VERSION})`,
|
||||
);
|
||||
}
|
||||
if (!db || typeof db !== 'object' || Array.isArray(db)) {
|
||||
throw new BusinessException(ErrorCode.BAD_REQUEST, '备份包 database.json 结构无效');
|
||||
}
|
||||
const data = db as Record<string, unknown>;
|
||||
const missing = MODELS.filter((model) => !Array.isArray(data[model]));
|
||||
if (missing.length) {
|
||||
throw new BusinessException(
|
||||
ErrorCode.BAD_REQUEST,
|
||||
`备份包缺少数据表:${missing.join(', ')};已中止恢复以避免清空现有数据`,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
function isSameOrChildPath(parent: string, child: string): boolean {
|
||||
const rel = relative(resolve(parent), resolve(child));
|
||||
return rel === '' || (!!rel && !rel.startsWith('..') && !isAbsolute(rel));
|
||||
@@ -196,7 +224,8 @@ export class BackupService {
|
||||
const dbEntry = zip.getEntry('database.json');
|
||||
if (!manifestEntry || !dbEntry) throw new BusinessException(ErrorCode.BAD_REQUEST, '备份包缺少 manifest.json 或 database.json');
|
||||
const manifest = JSON.parse(manifestEntry.getData().toString('utf8'));
|
||||
if (manifest.app !== 'artveris') throw new BusinessException(ErrorCode.BAD_REQUEST, '不是 Artveris 备份包');
|
||||
const db = JSON.parse(dbEntry.getData().toString('utf8'));
|
||||
validateBackupPayload(manifest, db);
|
||||
|
||||
const fileName = `restore-${dayjs().format('YYYYMMDDHHmmss')}.zip`;
|
||||
const filePath = join(this.backupRoot, fileName);
|
||||
@@ -304,8 +333,11 @@ export class BackupService {
|
||||
|
||||
private async restoreDatabase(zip: AdmZip) {
|
||||
const entry = zip.getEntry('database.json');
|
||||
if (!entry) throw new Error('备份包缺少 database.json');
|
||||
const manifestEntry = zip.getEntry('manifest.json');
|
||||
if (!entry || !manifestEntry) throw new Error('备份包缺少 database.json 或 manifest.json');
|
||||
const db = JSON.parse(entry.getData().toString('utf8'));
|
||||
// 清库前再次校验,纵深防御,避免绕过 preview 直接 commit 的坏包清空数据
|
||||
validateBackupPayload(JSON.parse(manifestEntry.getData().toString('utf8')), db);
|
||||
await this.prisma.$transaction(async (tx) => {
|
||||
for (const model of DELETE_ORDER) {
|
||||
await (tx as any)[model].deleteMany();
|
||||
|
||||
Reference in New Issue
Block a user