Automattic\WooCommerce\Internal\PushNotifications\Controllers
PushNotificationRestController::log_authorization_failure
Records a refused loopback request, but only when the body looks like one of ours.
The route is public until authorization passes, so logging every refused request would let anyone write to the store's log by POSTing here. A stripped header or an expired token still arrives with our body; a scanner never does.
The body check alone is not enough, since the source is public and the route is unauthenticated, so the line is also rate limited store-wide. A genuine incident still records a line a minute and a flood costs one.
Method of the class: PushNotificationRestController{}
No Hooks.
Returns
void. Nothing (null).
Usage
// private - for code of main (parent) class only $result = $this->log_authorization_failure( $request, $reason ): void;
- $request(WP_REST_Request) (required)
- The request object.
- $reason(string) (required)
- One of the AuthorizationFailureReason constants.
PushNotificationRestController::log_authorization_failure() PushNotificationRestController::log authorization failure code WC 11.3.0
private function log_authorization_failure( WP_REST_Request $request, string $reason ): void {
$body = json_decode( $request->get_body(), true );
if ( ! is_array( $body ) || ! array_key_exists( 'notifications', $body ) ) {
return;
}
if ( WC_Rate_Limiter::retried_too_soon( self::AUTH_FAILURE_LOG_RATE_LIMIT_ID ) ) {
return;
}
WC_Rate_Limiter::set_rate_limit( self::AUTH_FAILURE_LOG_RATE_LIMIT_ID, self::AUTH_FAILURE_LOG_RATE_LIMIT_SECONDS );
wc_get_container()->get( NotificationStepLogger::class )->log_unattributed_failure(
'loopback_started',
'auth_failed',
'warning',
sprintf( 'Loopback request refused: %s', self::AUTH_FAILURE_MESSAGES[ $reason ] ),
array(
'reason' => $reason,
'notifications' => is_array( $body['notifications'] ) ? count( $body['notifications'] ) : 0,
)
);
}