Bug Report: Review Submission Does Not Verify entityId Existence
Description
The POST /api/reviews endpoint stores a review referencing an entityId
(model ID) without first checking whether that entity exists in the models
table. This allows any authenticated user to create orphaned reviews for
non-existent or deleted models, corrupting the reviews dataset and causing
runtime errors in any query that JOINs reviews to models.
Steps to Reproduce
- Authenticate with a valid GitHub OAuth session.
- Submit a review for a non-existent model ID:
curl -X POST /api/reviews -H "Cookie: <session>" -d '{"entityId": "00000000-0000-0000-0000-000000000000", "rating": 5}'
- Observe the response is 201 Created.
- Query the reviews table: an orphaned review exists with no corresponding model.
Root Cause
The API handler calls prisma.review.create() directly without a preceding
prisma.model.findUnique() check or a foreign key constraint at the database level.
Impact
Orphaned reviews cause JOIN queries to fail silently, inflate model counts,
and allow manipulation of the leaderboard rankings through phantom reviews.
Proposed Fix
Verify entity existence before creating the review:
const entity = await prisma.aIModel.findUnique({ where: { id: entityId } });
if (!entity) {
return NextResponse.json({ error: "Model not found" }, { status: 404 });
}
await prisma.review.create({ data: { entityId, rating, comment, userId } });
Also add a database-level foreign key: entityId UUID REFERENCES ai_models(id) ON DELETE CASCADE.
Bug Report: Review Submission Does Not Verify entityId Existence
Description
The
POST /api/reviewsendpoint stores a review referencing anentityId(model ID) without first checking whether that entity exists in the models
table. This allows any authenticated user to create orphaned reviews for
non-existent or deleted models, corrupting the reviews dataset and causing
runtime errors in any query that JOINs reviews to models.
Steps to Reproduce
Root Cause
The API handler calls
prisma.review.create()directly without a precedingprisma.model.findUnique()check or a foreign key constraint at the database level.Impact
Orphaned reviews cause JOIN queries to fail silently, inflate model counts,
and allow manipulation of the leaderboard rankings through phantom reviews.
Proposed Fix
Verify entity existence before creating the review:
Also add a database-level foreign key:
entityId UUID REFERENCES ai_models(id) ON DELETE CASCADE.