fix(security): missing authorization check for changes to notebook widget (#2832)
This commit is contained in:
@@ -3,9 +3,10 @@ import SuperJSON from "superjson";
|
|||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
|
|
||||||
import { eq } from "@homarr/db";
|
import { eq } from "@homarr/db";
|
||||||
import { items } from "@homarr/db/schema";
|
import { boards, items } from "@homarr/db/schema";
|
||||||
|
|
||||||
import { createTRPCRouter, protectedProcedure } from "../../trpc";
|
import { createTRPCRouter, protectedProcedure } from "../../trpc";
|
||||||
|
import { throwIfActionForbiddenAsync } from "../board/board-access";
|
||||||
|
|
||||||
export const notebookRouter = createTRPCRouter({
|
export const notebookRouter = createTRPCRouter({
|
||||||
updateContent: protectedProcedure
|
updateContent: protectedProcedure
|
||||||
@@ -17,6 +18,8 @@ export const notebookRouter = createTRPCRouter({
|
|||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
.mutation(async ({ ctx, input }) => {
|
.mutation(async ({ ctx, input }) => {
|
||||||
|
await throwIfActionForbiddenAsync(ctx, eq(boards.id, input.boardId), "modify");
|
||||||
|
|
||||||
const item = await ctx.db.query.items.findFirst({
|
const item = await ctx.db.query.items.findFirst({
|
||||||
where: eq(items.id, input.itemId),
|
where: eq(items.id, input.itemId),
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -67,6 +67,10 @@ import type { WidgetComponentProps } from "../definition";
|
|||||||
|
|
||||||
import "./notebook.css";
|
import "./notebook.css";
|
||||||
|
|
||||||
|
import { useSession } from "@homarr/auth/client";
|
||||||
|
import { constructBoardPermissions } from "@homarr/auth/shared";
|
||||||
|
import { useRequiredBoard } from "@homarr/boards/context";
|
||||||
|
|
||||||
const iconProps = {
|
const iconProps = {
|
||||||
size: 30,
|
size: 30,
|
||||||
stroke: 1.5,
|
stroke: 1.5,
|
||||||
@@ -81,8 +85,11 @@ export function Notebook({ options, isEditMode, boardId, itemId }: WidgetCompone
|
|||||||
const [content, setContent] = useState(options.content);
|
const [content, setContent] = useState(options.content);
|
||||||
const [toSaveContent, setToSaveContent] = useState(content);
|
const [toSaveContent, setToSaveContent] = useState(content);
|
||||||
|
|
||||||
// TODO: Add check for user permissions
|
const board = useRequiredBoard();
|
||||||
const enabled = !isEditMode;
|
const { data: session } = useSession();
|
||||||
|
const { hasChangeAccess } = constructBoardPermissions(board, session);
|
||||||
|
|
||||||
|
const enabled = !isEditMode && hasChangeAccess;
|
||||||
const [isEditing, setIsEditing] = useState(false);
|
const [isEditing, setIsEditing] = useState(false);
|
||||||
|
|
||||||
const { primaryColor } = useMantineTheme();
|
const { primaryColor } = useMantineTheme();
|
||||||
|
|||||||
Reference in New Issue
Block a user