Language: TypeScript
Label: vulnerable
CWE: CWE-20 \u2014 Improper Input Validation
The product receives input or data, but it does
        not validate or incorrectly validates that the input has the
        properties that are required to process the data safely and
        correctly.

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 } });
    }),