Skip to content

Open-source status page, incident response and uptime monitoring

fix: enforce workspace ownership checks across tRPC mutation endpoints (#1898)

Maximilian Kasked204b5205d48
diff --git a/packages/api/src/router/maintenance.ts b/packages/api/src/router/maintenance.ts
index d70cae931..57e47aa20 100644
--- a/packages/api/src/router/maintenance.ts
+++ b/packages/api/src/router/maintenance.ts
@@ -112,7 +112,7 @@ export const maintenanceRouter = createTRPCRouter({
});
}
- // Check if the user has access to the monitors
+ // Check if the user has access to the page components
if (opts.input.pageComponents?.length) {
const whereConditions: SQL[] = [
eq(pageComponent.workspaceId, opts.ctx.workspace.id),
diff --git a/packages/api/src/router/pageComponent.ts b/packages/api/src/router/pageComponent.ts
index 2776b2120..084b3f272 100644
--- a/packages/api/src/router/pageComponent.ts
+++ b/packages/api/src/router/pageComponent.ts
@@ -3,6 +3,7 @@ import { z } from "zod";
import { type SQL, and, asc, desc, eq, inArray, sql } from "@openstatus/db";
import {
monitor,
+ page,
pageComponent,
pageComponentGroup,
selectMaintenanceSchema,
@@ -135,6 +136,25 @@ export const pageComponentRouter = createTRPCRouter({
)
.mutation(async (opts) => {
await opts.ctx.db.transaction(async (tx) => {
+ // Verify the page belongs to the current workspace
+ const ownedPage = await tx
+ .select({ id: page.id })
+ .from(page)
+ .where(
+ and(
+ eq(page.id, opts.input.pageId),
+ eq(page.workspaceId, opts.ctx.workspace.id),
+ ),
+ )
+ .get();
+
+ if (!ownedPage) {
+ throw new TRPCError({
+ code: "FORBIDDEN",
+ message: "You don't have access to this page.",
+ });
+ }
+
const pageComponentLimit = opts.ctx.workspace.limits["page-components"];
// Get existing state
diff --git a/packages/api/src/router/statusReport.ts b/packages/api/src/router/statusReport.ts
index bd21b4d78..a5124bc63 100644
--- a/packages/api/src/router/statusReport.ts
+++ b/packages/api/src/router/statusReport.ts
@@ -78,9 +78,10 @@ export const statusReportRouter = createTRPCRouter({
});
}
+ const { id, statusReportId, ...updateFields } = statusReportUpdateInput;
const currentStatusReportUpdate = await opts.ctx.db
.update(statusReportUpdate)
- .set({ ...statusReportUpdateInput, updatedAt: new Date() })
+ .set({ ...updateFields, updatedAt: new Date() })
.where(eq(statusReportUpdate.id, statusReportUpdateInput.id))
.returning()
.get();