Language: TypeScript
Label: safe
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 sendWorkloadEventsPolicy(
  payload: IWorkloadEventsPolicyPayload,
): Promise<void> {
  try {
    logger.info(
      {
        userLocator: payload.userLocator,
        cluster: payload.cluster,
        agentId: payload.agentId,
      },
      'attempting to send workload auto-import policy',
    );

    const { response, attempt } = await retryRequest(
      'post',
      constructUpstreamRequestUrl('/api/v1/policy'),
      payload,
      upstreamRequestOptions,
    );
    if (!isSuccessStatusCode(response.statusCode)) {
      throw new Error(`${response.statusCode} ${response.statusMessage}`);
    }

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