Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Donate link: https://scanfully.com
Tags: monitoring, site health, broken links, user activity, activity log
Requires at least: 6.0
Tested up to: 7.1.3
Stable tag: 1.10.0
Stable tag: 1.11.0
License: GPLv3 or later
License URI: https://www.gnu.org/licenses/gpl-3.0.html
Requires PHP: 7.4
Expand Down Expand Up @@ -67,13 +67,13 @@ Connect supported AI apps through [MCP](https://docs.scanfully.com/account/mcp/)

Protect your Scanfully account with authenticator-based two-factor sign-in, including when you use a social sign-in provider.

= WooCommerce checkout monitoring: beta =
= WooCommerce checkout monitoring =

A working homepage does not tell you whether a shopper can reach checkout.

For accounts with beta access, Scanfully can test a configured purchase flow through the product, cart, and checkout steps. Tests stop at the payment step without completing a payment. Review the failed step and available screenshots when a test fails.
With the WooCommerce add-on on a site, Scanfully can test a configured purchase flow through the product, cart, and checkout steps. Tests stop at the payment step without completing a payment. Review the failed step and available screenshots when a test fails.

See the [WooCommerce monitoring documentation](https://docs.scanfully.com/woocommerce/) for requirements and beta access.
See the [WooCommerce monitoring documentation](https://docs.scanfully.com/woocommerce/) for requirements and pricing.

= How the plugin and service work together =

Expand Down Expand Up @@ -109,7 +109,7 @@ Yes. This plugin connects your site to Scanfully's external monitoring service.

= Where do I connect my site? =

Open Settings > Scanfully in WordPress and click "Connect your Scanfully account". Authorize the connection in Scanfully. You will then return to WordPress with your site connected.
Open Settings > Scanfully in WordPress and click "Connect your Scanfully account". In Scanfully, pick the site, choose what Scanfully may do on it, and approve the connection. You will then return to WordPress with your site connected. To change what Scanfully may do later, click "Change what Scanfully may do" and approve again.

= Can I monitor several WordPress sites? =

Expand All @@ -129,7 +129,9 @@ Use the [Scanfully documentation](https://docs.scanfully.com/) or email [support

== External services ==

This plugin connects to the Scanfully service at [scanfully.com](https://scanfully.com/) and its API at `api.scanfully.com`. It does not send monitoring data until you connect your site. Starting the connection passes your site URL and return URL to Scanfully.
This plugin connects to the Scanfully service at [scanfully.com](https://scanfully.com/) and its API at `api.scanfully.com`. It does not send monitoring data until you connect your site. Starting the connection passes your site URL and return URL to Scanfully's authorization server, where you choose what Scanfully may do on the site; reading site data is always included. The plugin then holds tokens that work for this site only.

When Scanfully asks the plugin to sync, it signs the request, and the plugin checks the signature against Scanfully's public keys, which it fetches from `api.scanfully.com` and keeps for a day. This uses PHP's OpenSSL extension.

Once connected, the plugin sends the following data to provide monitoring, diagnostics, and WordPress activity context:

Expand All @@ -151,6 +153,13 @@ Read Scanfully's [terms and conditions](https://docs.scanfully.com/general/terms

== Changelog ==

= 1.11.0: November 12, 2026 =
* Added: connecting a site goes through Scanfully's authorization server, where you pick the site and choose what Scanfully may do on it
* Added: "Change what Scanfully may do" on the settings page changes those permissions later, and cancelling keeps the current connection
* Changed: an existing connection moves to the new connection by itself, without reconnecting
* Security: when Scanfully asks the site to sync, it signs the request, and the plugin checks the signature against Scanfully's public keys
* Changed: the readme describes WooCommerce checkout monitoring as an add-on instead of a beta

= 1.10.0: November 2, 2026 =
* Added: the plugin tells Scanfully when it is deactivated, disconnected or deleted, and by whom, so Scanfully can say why a site stopped reporting
* Added: when Scanfully asks the plugin to sync, the plugin answers with its version and how its last requests to Scanfully went
Expand Down
4 changes: 2 additions & 2 deletions scanfully.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*
* @wordpress-plugin
* Plugin Name: Scanfully
* Version: 1.10.0
* Version: 1.11.0
* Plugin URI: https://scanfully.com/wp-plugin
* Description: Scanfully is your favorite WordPress performance and health monitoring tool.
* Author: Scanfully
Expand Down Expand Up @@ -68,7 +68,7 @@ function Scanfully(): \Scanfully\Main { // phpcs:ignore WordPress.NamingConventi
function () {
// meta.
define( 'SCANFULLY_PLUGIN_FILE', __FILE__ );
define( 'SCANFULLY_VERSION', '1.10.0' );
define( 'SCANFULLY_VERSION', '1.11.0' );

// boot.
require __DIR__ . '/vendor/autoload.php';
Expand Down
23 changes: 23 additions & 0 deletions src/Connect/Buttons.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,29 @@ public static function connect(): void {
<?php
}

/**
* Change what Scanfully may do: a new connection request, on whose page
* in Scanfully the admin chooses again. Approving it replaces the current
* connection; cancelling keeps it.
*
* @return void
*/
public static function change_access(): void {
$url = add_query_arg(
[
'page' => 'scanfully',
'scanfully-change-access' => 1,
'scanfully-change-access-nonce' => wp_create_nonce( 'scanfully-change-access' ),
],
admin_url( 'options-general.php' )
);
?>
<a href="<?php echo esc_url( $url ); ?>" class="scanfully-connect-button scanfully-connect-button-dashboard">
<span><?php esc_html_e( 'Change what Scanfully may do', 'scanfully' ); ?></span>
</a>
<?php
}

/**
* Disconnect button
*
Expand Down
195 changes: 166 additions & 29 deletions src/Connect/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,18 @@ public static function catch_connect_requests(): void {
self::handle_reconnect();
}

// handle connect success return request.
// a new connection request that keeps the current one until approved.
if ( isset( $_GET['scanfully-change-access'] ) ) {
self::handle_change_access();
}

// the OAuth server's answer to a connection request.
if ( isset( $_GET[ OAuth::CALLBACK_PARAM ] ) ) {
self::handle_oauth_answer();
}

// the answer of the legacy connect page, to a request started before
// this version.
if ( isset( $_GET['scanfully-connect-success'] ) ) {
self::handle_request_connect_success();
}
Expand Down Expand Up @@ -90,22 +101,9 @@ private static function handle_connect_start(): void {
wp_die( 'You do not have permission to do this.' );
}

// build the connect URL and redirect.
// Use home_url() instead of get_site_url() for Bedrock compatibility.
// home_url() returns the public-facing URL, while site_url() returns
// the WordPress installation URL (which may be in a subdirectory).
$connect_url = add_query_arg(
[
'redirect_uri' => rawurlencode( Page::get_page_url() ),
'site' => rawurlencode( home_url() ),
'state' => self::generate_state(),
'code_challenge' => self::code_challenge( self::generate_code_verifier() ),
'code_challenge_method' => 'S256',
],
Main::get_connect_url()
);

wp_redirect( $connect_url );
// the admin approves on Scanfully's OAuth server what Scanfully may do
// on this site, and comes back with a code.
wp_redirect( OAuth::authorize_url() ); // phpcs:ignore WordPress.Security.SafeRedirect.wp_redirect_wp_redirect -- Scanfully's own OAuth server, on another host.
exit;
}

Expand Down Expand Up @@ -136,6 +134,25 @@ private static function handle_disconnect_start(): void {
exit;
}

/**
* Handle a request to change what Scanfully may do: a new connection
* request, while the current connection keeps working. Scanfully ends it
* when the admin approves the new one; a cancel leaves it as it was.
*
* @return void
*/
private static function handle_change_access(): void {
if ( ! isset( $_GET['scanfully-change-access-nonce'] ) || ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_GET['scanfully-change-access-nonce'] ) ), 'scanfully-change-access' ) ) {
wp_die( 'Invalid Scanfully nonce' );
}
if ( ! self::user_has_access() ) {
wp_die( 'You do not have permission to do this.' );
}

wp_redirect( OAuth::authorize_url() ); // phpcs:ignore WordPress.Security.SafeRedirect.wp_redirect_wp_redirect -- Scanfully's own OAuth server, on another host.
exit;
}

/**
* Handle a reconnect request: disconnect the current account and immediately start a new connect flow.
*
Expand All @@ -156,22 +173,103 @@ private static function handle_reconnect(): void {
self::revoke_tokens();
OptionsController::clear();

// build the connect URL and redirect directly into the connect flow.
$connect_url = add_query_arg(
[
'redirect_uri' => rawurlencode( Page::get_page_url() ),
'site' => rawurlencode( home_url() ),
'state' => self::generate_state(),
'code_challenge' => self::code_challenge( self::generate_code_verifier() ),
'code_challenge_method' => 'S256',
],
Main::get_connect_url()
// straight into a new connection, where the admin can choose again
// what Scanfully may do.
wp_redirect( OAuth::authorize_url() ); // phpcs:ignore WordPress.Security.SafeRedirect.wp_redirect_wp_redirect -- Scanfully's own OAuth server, on another host.
exit;
}

/**
* Handle the OAuth server's answer: an error (the admin cancelled), or a
* code to exchange for the site's tokens.
*
* @return void
*/
private static function handle_oauth_answer(): void {
if ( ! self::user_has_access() ) {
wp_die( 'You do not have permission to do this.' );
}

// the state is single use: deleted before comparing, and an empty
// value never matches. It also ends a cancelled request.
$expected_state = self::get_state();
$given_state = isset( $_GET['state'] ) ? sanitize_text_field( wp_unslash( $_GET['state'] ) ) : '';
self::delete_state();
$verifier = self::get_code_verifier();
self::delete_code_verifier();

if ( isset( $_GET['error'] ) ) {
$error = sanitize_key( wp_unslash( $_GET['error'] ) );
self::print_notice( 'access_denied' === $error ? __( 'The connection was cancelled.', 'scanfully' ) : __( 'An unknown error occurred.', 'scanfully' ), 'error' );
return;
}
if ( '' === $expected_state || '' === $given_state || ! hash_equals( $expected_state, $given_state ) ) {
wp_die( 'Invalid Scanfully connect state' );
}
// the answer names who issued it (RFC 9207): Scanfully's own server only.
if ( isset( $_GET['iss'] ) && untrailingslashit( esc_url_raw( wp_unslash( $_GET['iss'] ) ) ) !== untrailingslashit( Main::get_oauth_url() ) ) {
wp_die( 'Invalid Scanfully connect issuer' );
}
if ( ! isset( $_GET['code'] ) || '' === $verifier ) {
wp_die( 'Invalid Scanfully connect parameters' );
}

$tokens = OAuth::exchange_code( sanitize_text_field( wp_unslash( $_GET['code'] ) ), $verifier );
// the site ID ends up in API URL paths, so only allow plain ID characters.
if ( empty( $tokens ) || 1 !== preg_match( '/^[A-Za-z0-9_-]{1,64}\z/', (string) $tokens['site_id'] ) ) {
wp_die( 'Could not complete Scanfully connection: invalid response from the Scanfully API. Please try again or contact support.' );
}

$now = gmdate( self::DATE_FORMAT );
OptionsController::set_options(
new Options( true, $tokens['site_id'], $tokens['access_token'], $tokens['refresh_token'], gmdate( self::DATE_FORMAT, strtotime( $tokens['expires'] ) ), '', $now )
);
self::store_grant( $tokens['scopes'] );
self::schedule_first_syncs();

wp_redirect( $connect_url );
wp_redirect( add_query_arg( [ 'scanfully-connect-done' => '1' ], Page::get_page_url() ) );
exit;
}

/**
* Remember what Scanfully may do on the site, and that the connection
* lives on the OAuth server.
*
* @param string[] $scopes The granted scopes.
*
* @return void
*/
public static function store_grant( array $scopes ): void {
OptionsController::set_option( 'scopes', implode( ' ', $scopes ) );
OptionsController::set_option( 'flow', 'oauth' );
}

/**
* The scopes of the site's connection; for a connection from before this
* version, what it always allowed.
*
* @return string[]
*/
public static function granted_scopes(): array {
$scopes = array_values( array_filter( explode( ' ', OptionsController::get_option( 'scopes' ) ) ) );

return [] === $scopes ? [ OAuth::SCOPE_READ ] : $scopes;
}

/**
* Run the first syncs at once, so the dashboard does not wait for the next job.
*
* @return void
*/
private static function schedule_first_syncs(): void {
as_schedule_single_action( time(), \Scanfully\Cron\Controller::ACTION_SYNC_DIRECTORIES, [], 'scanfully' );
as_schedule_single_action( time(), \Scanfully\Cron\Controller::ACTION_SYNC_SITE_HEALTH, [], 'scanfully' );
if ( \Scanfully\WooCheckout\Controller::is_woocommerce_active() ) {
// fetches the probe secret, which is cleared on disconnect.
as_schedule_single_action( time(), \Scanfully\Cron\Controller::ACTION_SYNC_WOOCHECKOUT_CONFIG, [], 'scanfully' );
}
}

/**
* Catch the request that is returned from the connect process on success.
*
Expand Down Expand Up @@ -371,12 +469,51 @@ private static function exchange_authorization_code( string $code, string $site,
/**
* Use the refresh token to get a new access and refresh token
*
* @param string $refresh_token The refresh token.
* @param string $site The Scanfully site ID.
* @param bool $legacy_fallback Whether an API without the plugin's
* client gets the refresh on the legacy route.
*
* @return array
*/
public static function refresh_access_token( string $refresh_token, string $site, bool $legacy_fallback = true ): array {
if ( false === get_transient( self::OAUTH_UNAVAILABLE_TRANSIENT ) ) {
$tokens = OAuth::refresh( $refresh_token, $site );
if ( ! empty( $tokens ) ) {
self::store_grant( $tokens['scopes'] );
return $tokens;
}
// a connection that has not moved yet keeps the legacy route when
// the OAuth server refuses it (the API could not move it yet).
if ( null !== $tokens && ( 'oauth' === OptionsController::get_option( 'flow' ) || ! $legacy_fallback ) ) {
return $tokens;
}
// an API that does not connect sites on its OAuth server yet: the
// OAuth server again tomorrow.
set_transient( self::OAUTH_UNAVAILABLE_TRANSIENT, 1, DAY_IN_SECONDS );
}
if ( ! $legacy_fallback ) {
return [];
}

return self::refresh_on_legacy_route( $refresh_token, $site );
}

/**
* Transient set while the API's OAuth server does not take the plugin's client.
*/
public const OAUTH_UNAVAILABLE_TRANSIENT = 'scanfully_oauth_unavailable';

/**
* Refresh the tokens on the legacy connect route, for an API without the
* plugin's client on its OAuth server.
*
* @param string $refresh_token The refresh token.
* @param string $site The Scanfully site ID.
*
* @return array
*/
public static function refresh_access_token( string $refresh_token, string $site ): array {
private static function refresh_on_legacy_route( string $refresh_token, string $site ): array {

// request arguments for the requests.
$request_args = [
Expand Down
Loading
Loading