diff --git a/server/src/db/repository.ts b/server/src/db/repository.ts index 96f768b..6fdbb3a 100644 --- a/server/src/db/repository.ts +++ b/server/src/db/repository.ts @@ -4261,11 +4261,11 @@ export class MysqlRepository { duration_hours as durationHours, amount, location, status, created_at as createdAt FROM orders WHERE buyer_id = ? - OR expert_id = ? OR claimed_by = ? - OR companion_name IN (SELECT name FROM companions WHERE user_id = ? OR id = ?) + OR expert_id IN (SELECT id FROM companions WHERE user_id = ?) + OR companion_name IN (SELECT name FROM companions WHERE user_id = ?) ORDER BY created_at DESC - `, [id, id, id, id, id]); + `, [id, id, id, id]); // 资金流水(按 user_id 精确归属) const [financeRecords]: any = await pool.query(` diff --git a/server/tests/read-scope.spec.ts b/server/tests/read-scope.spec.ts index b4c73fa..03634c7 100644 --- a/server/tests/read-scope.spec.ts +++ b/server/tests/read-scope.spec.ts @@ -29,6 +29,10 @@ describe('第十二批读接口数据隔离闸门 (订单 / 我的组局 / 分 expect(block).not.toContain('WHERE user_id = ? OR id = ?'); }); + it('订单归属不得把用户 id 当作大神档案 id 兜底(防 id 撞号越权)', () => { + expect(repoCode).not.toContain('user_id = ? OR id = ?'); + }); + it('订单列表:管理端全量,普通用户仅本人相关', () => { const block = routeBlock("app.get('/api/orders',", 1800); expect(block).toContain('isVerifiedAdminRequest(req)'); diff --git a/server/tests/user-detail-scope.spec.ts b/server/tests/user-detail-scope.spec.ts index 7c61d7e..266ba6e 100644 --- a/server/tests/user-detail-scope.spec.ts +++ b/server/tests/user-detail-scope.spec.ts @@ -13,7 +13,9 @@ describe('第五十一批用户360画像关联闸门', () => { const start = repoCode.indexOf('async getUserDetail('); expect(start).toBeGreaterThan(-1); const block = repoCode.slice(start, start + 3000); - expect(block).toContain('OR companion_name IN (SELECT name FROM companions WHERE user_id = ? OR id = ?)'); + expect(block).toContain('OR expert_id IN (SELECT id FROM companions WHERE user_id = ?)'); + expect(block).toContain('OR companion_name IN (SELECT name FROM companions WHERE user_id = ?)'); + expect(block).not.toContain('user_id = ? OR id = ?'); expect(block).not.toContain('WHERE client_name = ? OR companion_name = ?'); });