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:
            ...(ancestorContentGroup && {
              ancestors: [...ancestorContentGroup.ancestors, ancestorContentGroup._id]
            })
          }
        }
      );

      if (ancestorContentGroup) {
        const descendants = await contentGroupsCollection
          .find({
            ancestors: contentGroup._id
          })
          .toArray();

        await contentGroupsCollection.bulkWrite([
          {
            updateOne: {
              filter: { _id: contentGroup.ancestors[contentGroup.ancestors.length - 1] },
              update: { $pull: { descendants: contentGroupId } }
            }
          },
          {
            updateOne: {
              filter: { _id: ancestorContentGroup._id },
              update: { $push: { descendants: contentGroupId } }
            }
          },
          ...descendants.map((descendant) => {
            const descendantAncestors = [
              ...ancestorContentGroup.ancestors,
              ...descendant.ancestors.slice(
                descendant.ancestors.findIndex((_id) => contentGroup._id.equals(_id))
              )
            ];

            return {
              updateOne: {
                filter: { _id: descendant._id },
                update: { $set: { ancestors: descendantAncestors } }
              }
            };
          })
        ]);
      }

      runGitSyncHook(ctx, "contentGroupUpdated", {
        contentGroup,
        ancestor: "ancestor" in input ? input.ancestor : undefined,
        name: "name" in input ? input.name : undefined
      });
      publishEvent(ctx, `${ctx.auth.workspaceId}`, { action: "update", data: { id, ...update } });
    }),