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 sendRuntimeData(
  payload: IRuntimeDataPayload,
): Promise<void> {
  const logContext = {
    userLocator: payload.target.userLocator,
    cluster: payload.target.cluster,
    agentId: payload.target.agentId,
    identity: payload.identity,
  };

  try {
    logger.info(logContext, 'attempting to send runtime data');

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

    const { response, attempt } = await reqQueue.push(request);

    if (!isSuccessStatusCode(response.statusCode)) {
      throw new Error(`${response.statusCode} ${response.statusMessage}`);
    }

    logger.info(
      {
        attempt,
        ...logContext,
      },
      'runtime data sent upstream successfully',
    );
  } catch (error) {
    logger.error(
      {
        error,
        ...logContext,
      },
      'could not send runtime data',
    );
  }
}