1. Request & test fixture
Authenticated as Tenant A administrator (usr_tnA_admin_01) with active session sid=ses_sample_active_09f2 targeting a Tenant B order record.
PATCH /v1/orders/ord_tnB_0912 HTTP/1.1
Host: staging.example.test
Cookie: sid=ses_sample_active_09f2
Content-Type: application/json
{
"status": "approved"
}
Observed response (200 OK)Handler verifies the caller has the admin role, then runs UPDATE orders SET status = $1 WHERE id = $2. Tenant B's order ord_tnB_0912 is modified across tenant boundaries.
Expected response (404 / 403)Update statement scopes by caller tenant: WHERE id = $2 AND tenant_id = $3. Matches zero rows in tnA_sample_01, returns 404 Not Found, and leaves Tenant B's record unchanged.
2. Recommended fix & regression check
Bind the authenticated session's tenantId directly in the mutation predicate and assert cross-tenant rejection in the route test suite:
// src/routes/orders/update.ts
const result = await db.query(
'UPDATE orders SET status = $1 WHERE id = $2 AND tenant_id = $3 RETURNING id',
[body.status, params.orderId, session.tenantId]
)
if (result.rowCount === 0) return Response.json({ error: 'Not found' }, { status: 404 })
// tests/orders-authorization.test.ts
expect(res.status).toBe(404)
expect(await getOrderStatus('ord_tnB_0912')).toBe('pending')