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