From 041647396364201b72f3f1f1235ea67440f60ebc Mon Sep 17 00:00:00 2001 From: Chris Portscheller Date: Fri, 4 Dec 2026 09:08:59 -0600 Subject: [PATCH] feat(cloud): hourly check-in with WebDecoy Cloud A site with an API key now tells WebDecoy once an hour that it is installed and which plugin, WordPress and PHP version it runs. A correct install on a quiet site sends no detections, so it used to look the same as a broken one. Nothing about visitors is sent. Skipped while WebDecoy asks clients to back off, unscheduled when the key is removed, and cleared on deactivate and uninstall. --- includes/class-webdecoy-activator.php | 1 + includes/class-webdecoy-checkin.php | 87 +++++++++++++++++++++++++++ tests/CheckinTest.php | 38 ++++++++++++ uninstall.php | 2 + webdecoy.php | 10 +++ 5 files changed, 138 insertions(+) create mode 100644 includes/class-webdecoy-checkin.php create mode 100644 tests/CheckinTest.php diff --git a/includes/class-webdecoy-activator.php b/includes/class-webdecoy-activator.php index 08f8c4b..f517a60 100644 --- a/includes/class-webdecoy-activator.php +++ b/includes/class-webdecoy-activator.php @@ -352,6 +352,7 @@ public static function uninstall(): void wp_clear_scheduled_hook('webdecoy_sync_blocked_ips'); wp_clear_scheduled_hook('webdecoy_flush_violations'); wp_clear_scheduled_hook('webdecoy_flush_ai_referrals'); + wp_clear_scheduled_hook('webdecoy_checkin'); wp_clear_scheduled_hook('webdecoy_sync_entitlements'); wp_clear_scheduled_hook('webdecoy_sync_actor_feed'); } diff --git a/includes/class-webdecoy-checkin.php b/includes/class-webdecoy-checkin.php new file mode 100644 index 0000000..5141e54 --- /dev/null +++ b/includes/class-webdecoy-checkin.php @@ -0,0 +1,87 @@ + 'wordpress_plugin', + 'version' => $version !== '' ? $version : 'unknown', + 'runtime' => $runtime, + ]; + } + + /** Send one check-in. Failures are ignored: the next hour tries again. */ + public static function send(string $apiKey): void + { + if ($apiKey === '' || !function_exists('wp_remote_post')) { + return; + } + if (class_exists('WebDecoy_Detection_Sender') && WebDecoy_Detection_Sender::backing_off()) { + return; + } + $wp = function_exists('get_bloginfo') ? (string) get_bloginfo('version') : ''; + $body = self::payload(defined('WEBDECOY_VERSION') ? WEBDECOY_VERSION : '', $wp, PHP_VERSION); + WebDecoy_HTTP::post(self::ENDPOINT, [ + // phpcs:ignore WordPressVIPMinimum.Performance.RemoteRequestTimeout.timeout_timeout -- WebDecoy_HTTP caps this to 3 seconds on VIP; retains the non-VIP caller budget. + 'timeout' => 5, + 'blocking' => false, + 'headers' => [ + 'Content-Type' => 'application/json', + 'Authorization' => 'Bearer ' . $apiKey, + ], + 'body' => (string) wp_json_encode($body), + ]); + } +} diff --git a/tests/CheckinTest.php b/tests/CheckinTest.php new file mode 100644 index 0000000..3af27f0 --- /dev/null +++ b/tests/CheckinTest.php @@ -0,0 +1,38 @@ + 'wordpress_plugin', 'version' => '2.17.5', 'runtime' => 'wordpress 6.7.1; php 8.2.12'], + WebDecoy_Checkin::payload('2.17.5', '6.7.1', '8.2.12') + ); +}); + +$t('reduces an unusual PHP version to what the endpoint accepts', function () use ($same, $true) { + $p = WebDecoy_Checkin::payload('2.17.5', '6.7.1', '8.2.12-1+ubuntu22.04.1+deb.sury.org+1 (cli) '); + $true(strlen($p['runtime']) <= 64, 'runtime fits the column'); + $same(1, preg_match('/^[0-9A-Za-z .;:+_-]{0,64}$/', $p['runtime']), 'runtime uses only accepted characters'); +}); + +$t('never sends an empty version', function () use ($same) { + $same('unknown', WebDecoy_Checkin::payload('', '6.7.1', '8.2.12')['version']); +}); diff --git a/uninstall.php b/uninstall.php index a099f8e..29b23b1 100644 --- a/uninstall.php +++ b/uninstall.php @@ -69,6 +69,7 @@ wp_clear_scheduled_hook('webdecoy_sync_entitlements'); wp_clear_scheduled_hook('webdecoy_sync_actor_feed'); wp_clear_scheduled_hook('webdecoy_flush_ai_referrals'); + wp_clear_scheduled_hook('webdecoy_checkin'); } // Delete all transients with webdecoy_ prefix @@ -132,6 +133,7 @@ wp_clear_scheduled_hook('webdecoy_sync_entitlements'); wp_clear_scheduled_hook('webdecoy_sync_actor_feed'); wp_clear_scheduled_hook('webdecoy_flush_ai_referrals'); + wp_clear_scheduled_hook('webdecoy_checkin'); // Delete transients for this site // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- Explicit uninstall cleanup of plugin-owned tables/transients; mutation cannot use a cached result. diff --git a/webdecoy.php b/webdecoy.php index 2555c7c..6028483 100644 --- a/webdecoy.php +++ b/webdecoy.php @@ -995,6 +995,7 @@ private function init_hooks(): void // Traffic page when connected. Wired on // plugins_loaded because its class is loaded there by load_includes(). add_action('plugins_loaded', [$this, 'register_ai_referrals'], 20); + add_action('plugins_loaded', [$this, 'register_checkin'], 20); // Load text domain @@ -1082,6 +1083,7 @@ public function load_includes(): void require_once WEBDECOY_PLUGIN_DIR . 'includes/class-webdecoy-detection-sender.php'; require_once WEBDECOY_PLUGIN_DIR . 'includes/class-webdecoy-browser-report.php'; require_once WEBDECOY_PLUGIN_DIR . 'includes/class-webdecoy-ai-referrals.php'; + require_once WEBDECOY_PLUGIN_DIR . 'includes/class-webdecoy-checkin.php'; require_once WEBDECOY_PLUGIN_DIR . 'includes/class-webdecoy-crawler-visits.php'; require_once WEBDECOY_PLUGIN_DIR . 'includes/class-webdecoy-detection-summary.php'; require_once WEBDECOY_PLUGIN_DIR . 'includes/class-webdecoy-robots-txt.php'; @@ -1458,6 +1460,14 @@ public function register_ai_referrals(): void WebDecoy_AI_Referrals::register((string) ($this->options['api_key'] ?? '')); } + /** + * Register the hourly check-in with WebDecoy Cloud, when an API key is set. + */ + public function register_checkin(): void + { + WebDecoy_Checkin::register((string) ($this->options['api_key'] ?? '')); + } + /** * Register the WordPress-native query/REST traps (author enumeration), * wired to record synthetic tripwire violations.