fix(order): 关闭按用户 id 撞库档案 id 的订单归属兜底,避免潜在越权读取

- getOrdersForUser/countOrdersForUser 仅按 companions.user_id 关联本人档案,不再使用 companions.id = 用户 id

- 补充回归断言;116 套件/758 用例全绿;线上已验证用户订单仍正常
这个提交包含在:
xcbyy
2026-10-22 11:33:47 +08:00
父节点 ab600e1c82
当前提交 32defce50c
共有 2 个文件被更改,包括 6 次插入 和 4 次删除

查看文件

@@ -1530,12 +1530,12 @@ export class MysqlRepository {
buyer_id = ?
OR expert_id = ?
OR claimed_by = ?
OR companion_name IN (SELECT name FROM companions WHERE user_id = ? OR id = ?)
OR companion_name IN (SELECT name FROM companions WHERE user_id = ?)
)
AND ${statusWhere}
ORDER BY created_at DESC
${limitSql}
`, [uid, uid, uid, uid, uid]);
`, [uid, uid, uid, uid]);
return rows;
}
@@ -1550,10 +1550,10 @@ export class MysqlRepository {
buyer_id = ?
OR expert_id = ?
OR claimed_by = ?
OR companion_name IN (SELECT name FROM companions WHERE user_id = ? OR id = ?)
OR companion_name IN (SELECT name FROM companions WHERE user_id = ?)
)
AND ${statusWhere}
`, [uid, uid, uid, uid, uid]);
`, [uid, uid, uid, uid]);
return Number((rows && rows[0] && rows[0].c) || 0);
}

查看文件

@@ -25,6 +25,8 @@ describe('第十二批读接口数据隔离闸门 (订单 / 我的组局 / 分
expect(block).toContain('buyer_id = ?');
expect(block).toContain('claimed_by = ?');
expect(block).toContain('companion_name IN (SELECT name FROM companions');
// 不得用「用户 id == 档案 id」做兜底归属,避免 id 撞号导致越权看到他人订单
expect(block).not.toContain('WHERE user_id = ? OR id = ?');
});
it('订单列表:管理端全量,普通用户仅本人相关', () => {