flawopen.com/bola-idor/Javascript
Eliminate BOLA (CWE-639) / IDOR vulnerabilities in Node.js, Express, and Prisma by binding database lookups directly to authenticated tenant session context.
Imagine checking into Room 204 at a hotel and receiving a valid keycard. But you discover that if you scratch out '204' on the door handle and write '205', the lock clicks open and allows you to rummage through another guest's luggage. The hotel confirmed you were a registered guest (authentication), but never checked whether your key matched Room 205 (object authorization). In BOLA/IDOR, an attacker changes an ID in an API request and accesses another user's private records.
Authentication vs. AuthorizationBOLA (OWASP API #1)Tenant BindingUser logs in and receives a valid session or JWT.
User changes URL parameter from /api/documents/100 to /api/documents/101.
Express handler queries Prisma with only the document ID.
Server returns document belonging to another organization.
// VULNERABLE: Queries document by user-supplied ID alone
app.get('/api/documents/:id', authenticateJWT, async (req, res) => {
// Vulnerable: trusts req.params.id without verifying organization ownership
const document = await prisma.document.findUnique({
where: { id: req.params.id }
});
if (!document) {
return res.status(404).json({ error: 'Document not found' });
}
// Attacker accesses documents belonging to any tenant!
res.json(document);
});
// HARDENED: Scopes query strictly to authenticated user's tenant organization
app.get('/api/documents/:id', authenticateJWT, async (req, res) => {
// Defense-in-depth: findFirst filters by BOTH document ID and authenticated tenant
const document = await prisma.document.findFirst({
where: {
id: req.params.id,
organizationId: req.user.organizationId
}
});
if (!document) {
// Return 404 rather than 403 to prevent object enumeration
return res.status(404).json({ error: 'Document not found' });
}
res.json(document);
});