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 sendClusterMetadata(): Promise<void> {
  const payload: IClusterMetadataPayload = {
    userLocator: config.INTEGRATION_ID,
    cluster: config.CLUSTER_NAME,
    agentId: config.AGENT_ID,
    version: config.MONITOR_VERSION,
    namespace: config.NAMESPACE,
  };

  try {
    logger.info(
      {
        userLocator: payload.userLocator,
        cluster: payload.cluster,
        agentId: payload.agentId,
      },
      'attempting to send cluster metadata',
    );

    const request: KubernetesUpstreamRequest = {
      method: 'post',
      url: `${upstreamUrl}/api/v1/cluster`,
      payload,
    };

    const { response, attempt } = await reqQueue.push(request);
    if (!isSuccessStatusCode(response.statusCode)) {
      throw new Error(`${response.statusCode} ${response.statusMessage}`);
    }

    logger.info(
      {
        userLocator: payload.userLocator,
        cluster: payload.cluster,
        agentId: payload.agentId,
        attempt,
      },
      'cluster metadata sent upstream successfully',
    );
  } catch (error) {
    logger.error(
      {
        error,
        userLocator: payload.userLocator,
        cluster: payload.cluster,
        agentId: payload.agentId,
      },
      'could not send cluster metadata',
    );
  }
}