Skip to content

Commit 037f03e

Browse files
cursor[bot]cursoragentvitaliimelnychuk
authored
Fix privilege escalation allowing granted users to delete collections (#12)
* fix: prevent granted users from renaming or deleting collections Co-authored-by: Vitalii Melnychuk <vitaliimelnychuk@users.noreply.github.com> * test: mock prisma dependency in collection access test --------- Co-authored-by: Cursor Agent <cursoragent@cursor.com> Co-authored-by: Vitalii Melnychuk <vitaliimelnychuk@users.noreply.github.com>
1 parent 2dae961 commit 037f03e

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { describe, expect, it, vi } from "vitest";
2+
3+
vi.mock("@/lib/prisma", () => ({
4+
prisma: {},
5+
}));
6+
7+
import { canRenameOrDeleteCollection } from "./collections";
8+
9+
describe("canRenameOrDeleteCollection", () => {
10+
it("allows owners and creators", () => {
11+
expect(canRenameOrDeleteCollection({ kind: "owner" })).toBe(true);
12+
expect(canRenameOrDeleteCollection({ kind: "creator" })).toBe(true);
13+
});
14+
15+
it("denies granted users and non-members", () => {
16+
expect(canRenameOrDeleteCollection({ kind: "grant" })).toBe(false);
17+
expect(canRenameOrDeleteCollection({ kind: "none" })).toBe(false);
18+
});
19+
});

src/server/access/collections.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ export type CollectionAccessState =
1313
export function canRenameOrDeleteCollection(
1414
state: CollectionAccessState,
1515
): boolean {
16-
return state.kind !== "none";
16+
// Restrict destructive collection-level operations to owner/creator.
17+
return state.kind === "owner" || state.kind === "creator";
1718
}
1819

1920
export async function loadCollectionAccessState(params: {

0 commit comments

Comments
 (0)