Language: TypeScript
Label: vulnerable
CWE: CWE-918 \u2014 Server-Side Request Forgery (SSRF)
The web server receives a URL or similar request from an upstream component and retrieves the contents of this URL, but it does not sufficiently ensure that the request is being sent to the expected destination.

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