diff --git a/server/src/db/repository.ts b/server/src/db/repository.ts index b6db6a9..96f768b 100644 --- a/server/src/db/repository.ts +++ b/server/src/db/repository.ts @@ -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); } diff --git a/server/tests/read-scope.spec.ts b/server/tests/read-scope.spec.ts index b6b7bcc..b4c73fa 100644 --- a/server/tests/read-scope.spec.ts +++ b/server/tests/read-scope.spec.ts @@ -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('订单列表:管理端全量,普通用户仅本人相关', () => {