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,6 +1,6 @@
|
||||
import type { Report } from '@/generated/prisma/client';
|
||||
import type { Auth } from '@/lib/types';
|
||||
import { canViewWebsite } from './website';
|
||||
import { canDeleteWebsite, canUpdateWebsite, canViewWebsite } from './website';
|
||||
|
||||
export async function canViewReport(auth: Auth, report: Report) {
|
||||
if (auth.user?.isAdmin) {
|
||||
@@ -14,18 +14,34 @@ export async function canViewReport(auth: Auth, report: Report) {
|
||||
return !!(await canViewWebsite(auth, report.websiteId));
|
||||
}
|
||||
|
||||
export async function canUpdateReport({ user }: Auth, report: Report) {
|
||||
if (!user) {
|
||||
export async function canUpdateReport(auth: Auth, report: Report) {
|
||||
if (!auth.user) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (user.isAdmin) {
|
||||
if (auth.user.isAdmin) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return user.id === report.userId;
|
||||
if (auth.user.id === report.userId) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return !!(await canUpdateWebsite(auth, report.websiteId));
|
||||
}
|
||||
|
||||
export async function canDeleteReport(auth: Auth, report: Report) {
|
||||
return canUpdateReport(auth, report);
|
||||
if (!auth.user) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (auth.user.isAdmin) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (auth.user.id === report.userId) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return !!(await canDeleteWebsite(auth, report.websiteId));
|
||||
}
|
||||
Reference in new issue
Block a user