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