Fix IDOR for reports
This commit is contained in:
1 parent
a6c909f3df
commit
fda83acdea
2 files changed
+29
-10
No files matched your search
@@ -1,7 +1,7 @@
|
||||
import { parseRequest } from '@/lib/request';
|
||||
import { json, notFound, ok, unauthorized } from '@/lib/response';
|
||||
import { reportSchema } from '@/lib/schema';
|
||||
import { canDeleteWebsite, canUpdateWebsite, canViewReport } from '@/permissions';
|
||||
import { canDeleteReport, canUpdateReport, canViewReport } from '@/permissions';
|
||||
import { deleteReport, getReport, updateReport } from '@/queries/prisma';
|
||||
|
||||
export async function GET(request: Request, { params }: { params: Promise<{ reportId: string }> }) {
|
||||
@@ -41,13 +41,12 @@ export async function POST(
|
||||
return notFound();
|
||||
}
|
||||
|
||||
if (!(await canUpdateWebsite(auth, websiteId))) {
|
||||
if (!(await canUpdateReport(auth, report))) {
|
||||
return unauthorized();
|
||||
}
|
||||
|
||||
const result = await updateReport(reportId, {
|
||||
websiteId,
|
||||
userId: auth.user.id,
|
||||
type,
|
||||
name,
|
||||
description,
|
||||
@@ -70,7 +69,11 @@ export async function DELETE(
|
||||
const { reportId } = await params;
|
||||
const report = await getReport(reportId);
|
||||
|
||||
if (!(await canDeleteWebsite(auth, report.websiteId))) {
|
||||
if (!report) {
|
||||
return notFound();
|
||||
}
|
||||
|
||||
if (!(await canDeleteReport(auth, report))) {
|
||||
return unauthorized();
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user