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.
Метод класса: PushNotificationRestController{}
Хуков нет.
Возвращает
void. Ничего (null).
Использование
// private - только в коде основоного (родительского) класса $result = $this->log_authorization_failure( $request, $reason ): void;
- $request(WP_REST_Request) (обязательный)
- The request object.
- $reason(строка) (обязательный)
- One of the AuthorizationFailureReason constants.
Код PushNotificationRestController::log_authorization_failure() PushNotificationRestController::log authorization failure 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,
)
);
}