All database queries must include appropriate user scoping to prevent unauthorized data access and Insecure Direct Object Reference (IDOR) vulnerabilities. Every query should filter results based on the authenticated user's context using `emailAccountId`, `userId`, or equivalent identifiers in WHERE clauses.
All database queries must include appropriate user scoping to prevent unauthorized data access and Insecure Direct Object Reference (IDOR) vulnerabilities. Every query should filter results based on the authenticated user’s context using emailAccountId
, userId
, or equivalent identifiers in WHERE clauses.
Why it matters: Without proper user scoping, attackers could potentially access or modify data belonging to other users by manipulating input parameters or request data.
Implementation:
// ❌ VULNERABLE: Missing user scoping
const schedule = await prisma.schedule.findUnique({
where: { id: scheduleId }
});
// ✅ SECURE: Properly scoped to authenticated user
const schedule = await prisma.schedule.findUnique({
where: { id: scheduleId, emailAccountId }
});
Security checks:
findUnique
, findFirst
, and any query that returns specific recordsEnter the URL of a public GitHub repository