Language: TypeScript
Label: vulnerable
CWE: CWE-287 \u2014 Improper Authentication
When an actor claims to have a given identity, the product does not prove or insufficiently proves that the claim is correct.

Code:
export async function deleteWorkload(
  payload: IDeleteWorkloadPayload,
): Promise<void> {
  try {
    const { workloadLocator, agentId } = payload;
    const { userLocator, cluster, namespace, type, name } = workloadLocator;
    const query = `userLocator=${userLocator}&cluster=${cluster}&namespace=${namespace}&type=${type}&name=${name}&agentId=${agentId}`;
    const request: KubernetesUpstreamRequest = {
      method: 'delete',
      url: `${upstreamUrl}/api/v1/workload?${query}`,
      payload,
    };

    const { response, attempt } = await reqQueue.push(request);
    // TODO: Remove this check, the upstream no longer returns 404 in such cases
    if (response.statusCode === 404) {
      logger.info(
        { payload },
        'attempted to delete a workload the Upstream service could not find',
      );
      return;
    }
    if (!isSuccessStatusCode(response.statusCode)) {
      throw new Error(`${response.statusCode} ${response.statusMessage}`);
    } else {
      logger.info(
        { workloadLocator: payload.workloadLocator, attempt },
        'workload deleted successfully',
      );
    }
  } catch (error) {
    logger.error(
      { error, payload },
      'could not send delete a workload from the upstream',
    );
  }
}