mirror of
https://github.com/outline/outline.git
synced 2026-11-24 23:00:18 +03:00
Add validation to prevent arbitrary Owner permission assignment
- Use enum constant instead of string literal in test - Add validation in add_user and add_group endpoints to prevent Owner permission assignment - Owner permission can only be assigned automatically on collection creation Co-authored-by: tommoor <380914+tommoor@users.noreply.github.com>
This commit is contained in:
1 parent
cb54470599
commit
3c658126f4
2 files changed
+20
-2
No files matched your search
@@ -1,5 +1,6 @@
|
||||
import { randomUUID } from "node:crypto";
|
||||
import { randomString } from "@shared/random";
|
||||
import { CollectionPermission } from "@shared/types";
|
||||
import slugify from "@shared/utils/slugify";
|
||||
import {
|
||||
buildUser,
|
||||
@@ -562,6 +563,6 @@ describe("Owner permission", () => {
|
||||
const ownerMembership = membership.find((m) => m.userId === user.id);
|
||||
|
||||
expect(ownerMembership).toBeDefined();
|
||||
expect(ownerMembership?.permission).toBe("owner");
|
||||
expect(ownerMembership?.permission).toBe(CollectionPermission.Owner);
|
||||
});
|
||||
});
|
||||
@@ -43,7 +43,7 @@ import { RateLimiterStrategy } from "@server/utils/RateLimiter";
|
||||
import { collectionIndexing } from "@server/utils/indexing";
|
||||
import pagination from "../middlewares/pagination";
|
||||
import * as T from "./schema";
|
||||
import { InvalidRequestError } from "@server/errors";
|
||||
import { InvalidRequestError, ValidationError } from "@server/errors";
|
||||
|
||||
const router = new Router();
|
||||
|
||||
@@ -215,6 +215,14 @@ router.post(
|
||||
authorize(user, "update", collection);
|
||||
authorize(user, "read", group);
|
||||
|
||||
// Prevent assigning Owner permission via this endpoint
|
||||
// Owner permission is only assigned automatically on collection creation
|
||||
if (permission === CollectionPermission.Owner) {
|
||||
throw ValidationError(
|
||||
"Owner permission can only be assigned automatically on collection creation"
|
||||
);
|
||||
}
|
||||
|
||||
let membership = await GroupMembership.findOne({
|
||||
where: {
|
||||
collectionId: id,
|
||||
@@ -375,6 +383,15 @@ router.post(
|
||||
authorize(actor, "update", collection);
|
||||
authorize(actor, "read", user);
|
||||
|
||||
// Prevent assigning Owner permission via this endpoint
|
||||
// Owner permission is only assigned automatically on collection creation
|
||||
const requestedPermission = permission || user.defaultCollectionPermission;
|
||||
if (requestedPermission === CollectionPermission.Owner) {
|
||||
throw ValidationError(
|
||||
"Owner permission can only be assigned automatically on collection creation"
|
||||
);
|
||||
}
|
||||
|
||||
let membership = await UserMembership.findOne({
|
||||
where: {
|
||||
collectionId: id,
|
||||
|
||||
Reference in new issue
Block a user