Language: TypeScript
Label: vulnerable
CWE: CWE-770 \u2014 Allocation of Resources Without Limits or Throttling
The product allocates a reusable resource or group of resources on behalf of an actor without imposing any restrictions on the size or number of resources that can be allocated, in violation of the intended security policy for that actor.

Code:
        _id: new ObjectId(input.id)
      });

      if (!contentGroup) throw errors.notFound("contentGroup");

      if (contentGroup.ancestors.length > 0) {
        const ancestor = await contentGroupsCollection.findOne({
          _id: contentGroup.ancestors[contentGroup.ancestors.length - 1]
        });

        if (!ancestor) throw errors.notFound("contentGroup");

        const newDescendants = [...ancestor.descendants];

        newDescendants.splice(
          newDescendants.findIndex((newDescendantId) => {
            return newDescendantId.equals(contentGroup._id);
          }),
          1
        );
        newDescendants.splice(input.index, 0, contentGroup._id);
        await contentGroupsCollection.updateOne(
          { _id: ancestor._id },
          { $set: { descendants: newDescendants } }
        );
      } else {
        const workspace = await workspacesCollection.findOne({
          _id: ctx.auth.workspaceId
        });

        if (!workspace) throw errors.notFound("workspace");

        const newContentGroups = [...workspace.contentGroups];

        newContentGroups.splice(
          newContentGroups.findIndex((newContentGroupId) => {
            return newContentGroupId.equals(contentGroup._id);
          }),
          1
        );
        newContentGroups.splice(input.index, 0, contentGroup._id);
        await workspacesCollection.updateOne(
          { _id: ctx.auth.workspaceId },
          { $set: { contentGroups: newContentGroups } }
        );
      }

      publishEvent(ctx, `${ctx.auth.workspaceId}`, {
        action: "reorder",
        data: input
      });
    }),