Commit 0222c9af1d6 for woocommerce

commit 0222c9af1d6545f0c056e6f0610d053844373161
Author: Luigi Teschio <gigitux@gmail.com>
Date:   Mon Nov 23 17:22:08 2026 +0100

    Tighten WooCommerce.com request signing and install access (#71272)

    * Tighten WooCommerce.com request signing and install access

    Forwardport of 514-gh-Automattic/woocommerce.

    Source PR head: 8ec6d02bb7878c114e915ed5d0d7786555476590

    * Add return type doc and mock the subscriptions request in tests

    - Add @return bool to get_install_permission(), as in the 11.3.1 release commit.
    - Mock pre_http_request in WC_Helper_Admin_Test so it no longer reaches woocommerce.com.

    Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

    * Mock the subscriptions request before connecting in the helper admin test

    Updating the helper auth option refreshes subscription notes, which fetches subscriptions from WooCommerce.com, so the mock has to be in place first.

    Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

    ---------

    Co-authored-by: Michal Iwanow <4765119+mcliwanow@users.noreply.github.com>
    Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

diff --git a/plugins/woocommerce/client/admin/client/activity-panel/activity-panel.js b/plugins/woocommerce/client/admin/client/activity-panel/activity-panel.js
index 9e1c8c5d655..43b8be67806 100644
--- a/plugins/woocommerce/client/admin/client/activity-panel/activity-panel.js
+++ b/plugins/woocommerce/client/admin/client/activity-panel/activity-panel.js
@@ -279,7 +279,7 @@ export const ActivityPanel = ( { isEmbedded, query } ) => {
 			// and resetting its DropdownMenu's internal isOpen state.
 			component: HeaderAccount,
 			options: { page: 'wc-admin' },
-			visible: isHomescreen,
+			visible: isHomescreen && currentUserCan( 'manage_woocommerce' ),
 		};

 		const previewSite = {
diff --git a/plugins/woocommerce/client/admin/client/marketplace/components/my-subscriptions/table/actions/install.tsx b/plugins/woocommerce/client/admin/client/marketplace/components/my-subscriptions/table/actions/install.tsx
index 3e6bfa5659b..d0514b34eaa 100644
--- a/plugins/woocommerce/client/admin/client/marketplace/components/my-subscriptions/table/actions/install.tsx
+++ b/plugins/woocommerce/client/admin/client/marketplace/components/my-subscriptions/table/actions/install.tsx
@@ -6,7 +6,9 @@ import { Button } from '@wordpress/components';
 import { dispatch, useSelect } from '@wordpress/data';
 import { useContext } from '@wordpress/element';
 import { __, sprintf } from '@wordpress/i18n';
+import { removeQueryArgs } from '@wordpress/url';
 import { recordEvent } from '@woocommerce/tracks';
+import { useUser } from '@woocommerce/data';

 /**
  * Internal dependencies
@@ -36,6 +38,7 @@ interface InstallProps {

 export default function Install( props: InstallProps ) {
 	const { loadSubscriptions } = useContext( SubscriptionsContext );
+	const { currentUserCan } = useUser();

 	const loading: boolean = useSelect(
 		( select ) => {
@@ -168,7 +171,14 @@ export default function Install( props: InstallProps ) {
 						product_zip_slug: props.subscription.zip_slug,
 						product_id: props.subscription.product_id,
 						product_current_version: props.subscription.version,
-						product_install_url: url,
+						product_install_url: url
+							? removeQueryArgs(
+									url,
+									'token',
+									'signature',
+									'product-key'
+								)
+							: url,
 					} );

 					stopInstall();
@@ -183,6 +193,10 @@ export default function Install( props: InstallProps ) {
 		}
 	};

+	if ( ! currentUserCan( 'install_plugins' ) ) {
+		return null;
+	}
+
 	return (
 		<Button
 			variant={ props.variant ?? 'link' }
diff --git a/plugins/woocommerce/client/admin/client/marketplace/components/my-subscriptions/table/actions/test/install.test.tsx b/plugins/woocommerce/client/admin/client/marketplace/components/my-subscriptions/table/actions/test/install.test.tsx
new file mode 100644
index 00000000000..f5ef1c411c6
--- /dev/null
+++ b/plugins/woocommerce/client/admin/client/marketplace/components/my-subscriptions/table/actions/test/install.test.tsx
@@ -0,0 +1,77 @@
+/**
+ * External dependencies
+ */
+import { fireEvent, render, screen, waitFor } from '@testing-library/react';
+import { recordEvent } from '@woocommerce/tracks';
+import { useUser } from '@woocommerce/data';
+
+jest.mock( '@woocommerce/tracks', () => ( { recordEvent: jest.fn() } ) );
+
+jest.mock( '@woocommerce/data', () => ( {
+	useUser: jest.fn(),
+} ) );
+
+jest.mock( '../../../../../utils/functions', () => ( {
+	...jest.requireActual( '../../../../../utils/functions' ),
+	addNotice: jest.fn(),
+	removeNotice: jest.fn(),
+	getInstallUrl: jest.fn( () =>
+		Promise.resolve(
+			'https://woocommerce.com/install/?product-key=k&token=t&signature=s&utm_source=helper'
+		)
+	),
+} ) );
+
+/**
+ * Internal dependencies
+ */
+import Install from '../install';
+import { Subscription } from '../../../types';
+
+const subscription = {
+	product_key: 'product-key',
+	product_name: 'Product Add-Ons',
+	product_id: 18618,
+	zip_slug: 'woocommerce-product-addons',
+	version: '8.0.0',
+	is_installable: false,
+} as unknown as Subscription;
+
+function mockCanInstall( canInstall: boolean ) {
+	( useUser as jest.Mock ).mockReturnValue( {
+		currentUserCan: () => canInstall,
+	} );
+}
+
+describe( 'Install', () => {
+	it( 'renders nothing for users who cannot install plugins', () => {
+		mockCanInstall( false );
+		const { container } = render(
+			<Install subscription={ subscription } />
+		);
+
+		expect( container ).toBeEmptyDOMElement();
+	} );
+
+	it( 'leaves the credentials out of the tracked install URL', async () => {
+		mockCanInstall( true );
+		const open = jest.spyOn( window, 'open' ).mockImplementation();
+		render( <Install subscription={ subscription } /> );
+
+		fireEvent.click( screen.getByRole( 'button', { name: 'Install' } ) );
+
+		await waitFor( () =>
+			expect( recordEvent ).toHaveBeenCalledWith(
+				'marketplace_product_install_url',
+				expect.objectContaining( {
+					product_install_url:
+						'https://woocommerce.com/install/?utm_source=helper',
+				} )
+			)
+		);
+		expect( open ).toHaveBeenCalledWith(
+			'https://woocommerce.com/install/?product-key=k&token=t&signature=s&utm_source=helper',
+			'_self'
+		);
+	} );
+} );
diff --git a/plugins/woocommerce/client/admin/client/marketplace/components/woo-update-manager-plugin/install-woo-connect-modal.tsx b/plugins/woocommerce/client/admin/client/marketplace/components/woo-update-manager-plugin/install-woo-connect-modal.tsx
index 07f86642a60..4091b082b15 100644
--- a/plugins/woocommerce/client/admin/client/marketplace/components/woo-update-manager-plugin/install-woo-connect-modal.tsx
+++ b/plugins/woocommerce/client/admin/client/marketplace/components/woo-update-manager-plugin/install-woo-connect-modal.tsx
@@ -72,14 +72,17 @@ export default function InstallWooConnectModal( props: ConnectProps ) {
 								{ __( 'Upload plugin', 'woocommerce' ) }
 							</Button>
 						) }
-					{ ! isManualInstall && (
-						<Button
-							href={ wccomSettings?.wooUpdateManagerInstallUrl }
-							variant="primary"
-						>
-							{ __( 'Install', 'woocommerce' ) }
-						</Button>
-					) }
+					{ ! isManualInstall &&
+						wccomSettings?.wooUpdateManagerInstallUrl && (
+							<Button
+								href={
+									wccomSettings?.wooUpdateManagerInstallUrl
+								}
+								variant="primary"
+							>
+								{ __( 'Install', 'woocommerce' ) }
+							</Button>
+						) }
 				</ButtonGroup>
 			</Modal>
 		);
diff --git a/plugins/woocommerce/client/admin/client/marketplace/components/woo-update-manager-plugin/plugin-install-notice.tsx b/plugins/woocommerce/client/admin/client/marketplace/components/woo-update-manager-plugin/plugin-install-notice.tsx
index c1509a29e27..5366d5e28ae 100644
--- a/plugins/woocommerce/client/admin/client/marketplace/components/woo-update-manager-plugin/plugin-install-notice.tsx
+++ b/plugins/woocommerce/client/admin/client/marketplace/components/woo-update-manager-plugin/plugin-install-notice.tsx
@@ -54,16 +54,17 @@ export default function PluginInstallNotice( props: { selectedTab: string } ) {
 						) }
 					></span>
 					<div className="components-notice__buttons">
-						{ ! isManualInstall && (
-							<Button
-								href={
-									wccomSettings?.wooUpdateManagerInstallUrl
-								}
-								variant="secondary"
-							>
-								{ __( 'Install', 'woocommerce' ) }
-							</Button>
-						) }
+						{ ! isManualInstall &&
+							wccomSettings?.wooUpdateManagerInstallUrl && (
+								<Button
+									href={
+										wccomSettings?.wooUpdateManagerInstallUrl
+									}
+									variant="secondary"
+								>
+									{ __( 'Install', 'woocommerce' ) }
+								</Button>
+							) }
 						<Button
 							href={ WOO_CONNECT_PLUGIN_DOWNLOAD_URL }
 							variant={ isManualInstall ? 'secondary' : 'link' }
diff --git a/plugins/woocommerce/includes/admin/helper/class-wc-helper-admin.php b/plugins/woocommerce/includes/admin/helper/class-wc-helper-admin.php
index 10756430f60..969d0ac3824 100644
--- a/plugins/woocommerce/includes/admin/helper/class-wc-helper-admin.php
+++ b/plugins/woocommerce/includes/admin/helper/class-wc-helper-admin.php
@@ -49,11 +49,25 @@ class WC_Helper_Admin {
 	/**
 	 * Pushes settings onto the WooCommerce Admin global settings object (wcSettings).
 	 *
+	 * Users who can't manage WooCommerce get only the defaults the marketplace client needs.
+	 *
 	 * @param mixed $settings The settings object we're amending.
 	 *
 	 * @return mixed $settings
 	 */
 	public static function add_marketplace_settings( $settings ) {
+		if ( ! current_user_can( 'manage_woocommerce' ) ) {
+			$settings['wccomHelper'] = array(
+				'isConnected'               => false,
+				'storeCountry'              => wc_get_base_location()['country'],
+				'installedProducts'         => array(),
+				'wooUpdateManagerInstalled' => WC_Woo_Update_Manager_Plugin::is_plugin_installed(),
+				'wooUpdateManagerActive'    => WC_Woo_Update_Manager_Plugin::is_plugin_active(),
+				'trackingAllowed'           => 'yes' === get_option( 'woocommerce_allow_tracking' ),
+			);
+			return $settings;
+		}
+
 		if ( ! WC_Helper::is_site_connected() && isset( $_GET['connect'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
 			wp_safe_redirect( self::get_connection_url() );
 			exit;
@@ -86,7 +100,7 @@ class WC_Helper_Admin {
 			'mySubscriptionsTabLoaded'      => WC_Helper_Options::get( 'my_subscriptions_tab_loaded' ),
 			'wooUpdateManagerInstalled'     => WC_Woo_Update_Manager_Plugin::is_plugin_installed(),
 			'wooUpdateManagerActive'        => WC_Woo_Update_Manager_Plugin::is_plugin_active(),
-			'wooUpdateManagerInstallUrl'    => WC_Woo_Update_Manager_Plugin::generate_install_url(),
+			'wooUpdateManagerInstallUrl'    => current_user_can( 'install_plugins' ) ? WC_Woo_Update_Manager_Plugin::generate_install_url() : '',
 			'wooUpdateManagerManualInstall' => WC_Woo_Update_Manager_Plugin::needs_manual_install(),
 			'wooUpdateManagerUploadUrl'     => current_user_can( 'install_plugins' ) ? network_admin_url( 'plugin-install.php?tab=upload' ) : '',
 			'wooUpdateManagerPluginSlug'    => WC_Woo_Update_Manager_Plugin::WOO_UPDATE_MANAGER_SLUG,
diff --git a/plugins/woocommerce/includes/admin/helper/class-wc-helper-subscriptions-api.php b/plugins/woocommerce/includes/admin/helper/class-wc-helper-subscriptions-api.php
index 5d3b497da3c..72eef3e9dd4 100644
--- a/plugins/woocommerce/includes/admin/helper/class-wc-helper-subscriptions-api.php
+++ b/plugins/woocommerce/includes/admin/helper/class-wc-helper-subscriptions-api.php
@@ -136,7 +136,7 @@ class WC_Helper_Subscriptions_API {
 			array(
 				'methods'             => 'GET',
 				'callback'            => array( __CLASS__, 'install_url' ),
-				'permission_callback' => array( __CLASS__, 'get_permission' ),
+				'permission_callback' => array( __CLASS__, 'get_install_permission' ),
 				'args'                => array(
 					'product_key' => array(
 						'required' => true,
@@ -155,6 +155,16 @@ class WC_Helper_Subscriptions_API {
 		return current_user_can( 'manage_woocommerce' );
 	}

+	/**
+	 * Install links are only for users who can install plugins.
+	 *
+	 * @since 11.3.1
+	 * @return bool
+	 */
+	public static function get_install_permission() {
+		return self::get_permission() && current_user_can( 'install_plugins' );
+	}
+
 	/**
 	 * Fetch subscriptions from WooCommerce.com and serve them
 	 * as JSON.
diff --git a/plugins/woocommerce/includes/wccom-site/class-wc-wccom-site.php b/plugins/woocommerce/includes/wccom-site/class-wc-wccom-site.php
index 076bf0604ae..4ef23ae43b4 100644
--- a/plugins/woocommerce/includes/wccom-site/class-wc-wccom-site.php
+++ b/plugins/woocommerce/includes/wccom-site/class-wc-wccom-site.php
@@ -29,7 +29,6 @@ class WC_WCCOM_Site {
 		self::includes();

 		add_action( 'woocommerce_wccom_install_products', array( 'WC_WCCOM_Site_Installer', 'install' ) );
-		add_filter( 'determine_current_user', array( __CLASS__, 'authenticate_wccom' ), 14 );
 		add_filter( 'rest_authentication_errors', array( __CLASS__, 'authentication_fallback' ) );
 		add_action( 'woocommerce_rest_api_get_rest_namespaces', array( __CLASS__, 'register_rest_namespace' ) );
 	}
@@ -45,10 +44,13 @@ class WC_WCCOM_Site {
 	}

 	/**
-	 * Authenticate WooCommerce.com request.
+	 * Authenticate a WooCommerce.com request to the wccom-site REST API.
+	 *
+	 * Called from authentication_fallback() once WordPress has resolved the route. Returns the connected user,
+	 * or false with the reason added to the wccom_auth_error filter.
 	 *
 	 * @since 3.7.0
-	 * @param int|false $user_id User ID.
+	 * @param int|false $user_id Current user id if already set; always false from the only caller.
 	 * @return int|WP_User|false
 	 */
 	public static function authenticate_wccom( $user_id ) {
@@ -136,17 +138,16 @@ class WC_WCCOM_Site {
 	}

 	/**
-	 * Authenticate a WooCommerce.com request that carries `rest_route`.
+	 * Authenticate a WooCommerce.com request once WordPress has resolved its REST route.
 	 *
-	 * WordPress determines the current user before it parses the request, so `authenticate_wccom()` leaves
-	 * these requests alone during `determine_current_user` and they are authenticated here instead.
+	 * Only requests WordPress dispatches to the wccom-site namespace are authenticated, whatever the URL looked like.
 	 *
 	 * @since 11.3.0
 	 * @param WP_Error|null|bool $error Error from another authentication handler, null if none.
 	 * @return WP_Error|null|bool
 	 */
 	public static function authentication_fallback( $error ) {
-		if ( ! empty( $error ) || 0 !== get_current_user_id() || ! isset( $_REQUEST['rest_route'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
+		if ( ! empty( $error ) || 0 !== get_current_user_id() ) {
 			return $error;
 		}

@@ -192,8 +193,7 @@ class WC_WCCOM_Site {
 	/**
 	 * Check if this is a request to WCCOM Site REST API.
 	 *
-	 * Before WordPress parses the request only the URL path is checked. Requests carrying `rest_route`
-	 * return false until then, and `authentication_fallback()` authenticates them once the route is resolved.
+	 * Only the route WordPress resolved counts, so this is false until WordPress is dispatching the request as REST.
 	 *
 	 * @since 3.7.0
 	 * @return bool
@@ -201,24 +201,19 @@ class WC_WCCOM_Site {
 	protected static function is_request_to_wccom_site_rest_api() {
 		global $wp;

-		// Once WordPress is dispatching REST, the route it resolved is the one that counts.
-		if ( wp_is_rest_endpoint() ) {
-			$route = $wp instanceof WP ? ( $wp->query_vars['rest_route'] ?? null ) : null;
-			return is_string( $route ) && str_starts_with( ltrim( $route, '/' ), 'wccom-site/' );
-		}
-
-		// Before that, a rest_route in the query or body can override the path, so leave those requests to authentication_fallback().
-		if ( isset( $_REQUEST['rest_route'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
+		if ( ! wp_is_rest_endpoint() ) {
 			return false;
 		}

-		$path = wp_parse_url( wp_unslash( $_SERVER['REQUEST_URI'] ?? '' ), PHP_URL_PATH ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Only compared against the REST prefix.
-		return is_string( $path ) && str_contains( $path, trailingslashit( rest_get_url_prefix() ) . 'wccom-site/' );
+		$route = $wp instanceof WP ? ( $wp->query_vars['rest_route'] ?? null ) : null;
+		return is_string( $route ) && str_starts_with( ltrim( $route, '/' ), 'wccom-site/' );
 	}

 	/**
 	 * Verify WooCommerce.com request from a given body and signature request.
 	 *
+	 * Only what follows the first "?" of the request URI is treated as its query string.
+	 *
 	 * @since 3.7.0
 	 * @param string $body                Request body.
 	 * @param string $signature           Request signature found in X-Woo-Signature header.
@@ -227,10 +222,16 @@ class WC_WCCOM_Site {
 	 */
 	protected static function verify_wccom_request( $body, $signature, $access_token_secret ) {
 		// phpcs:disable WordPress.Security.ValidatedSanitizedInput.InputNotValidated, WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
+		$uri_parts   = explode( '?', $_SERVER['REQUEST_URI'] ?? '', 2 );
+		$request_uri = urldecode( $uri_parts[0] );
+		if ( isset( $uri_parts[1] ) ) {
+			// With ALTERNATE_WP_CRON, WordPress redirects a GET to itself plus doing_wp_cron when cron is due, and WooCommerce.com follows it.
+			$request_uri .= urldecode( remove_query_arg( array( 'token', 'signature', 'doing_wp_cron' ), '?' . $uri_parts[1] ) );
+		}
+
 		$data = array(
 			'host'        => $_SERVER['HTTP_HOST'],
-			// With ALTERNATE_WP_CRON, WordPress redirects a GET to itself plus doing_wp_cron when cron is due, and WooCommerce.com follows it.
-			'request_uri' => urldecode( remove_query_arg( array( 'token', 'signature', 'doing_wp_cron' ), $_SERVER['REQUEST_URI'] ) ),
+			'request_uri' => $request_uri,
 			'method'      => strtoupper( $_SERVER['REQUEST_METHOD'] ),
 		);
 		// phpcs:enable
diff --git a/plugins/woocommerce/tests/php/includes/admin/helper/class-wc-helper-admin-test.php b/plugins/woocommerce/tests/php/includes/admin/helper/class-wc-helper-admin-test.php
new file mode 100644
index 00000000000..aa66224218c
--- /dev/null
+++ b/plugins/woocommerce/tests/php/includes/admin/helper/class-wc-helper-admin-test.php
@@ -0,0 +1,68 @@
+<?php
+declare( strict_types = 1 );
+
+/**
+ * Tests for the WooCommerce.com settings WC_Helper_Admin adds to wcSettings.
+ */
+class WC_Helper_Admin_Test extends WC_Unit_Test_Case {
+
+	private const ACCESS_TOKEN = 'test-access-token';
+
+	/**
+	 * @testdox Should build the full marketplace settings only for users who can manage WooCommerce.
+	 *
+	 * @testWith ["contributor", false, false]
+	 *           ["shop_manager", true, false]
+	 *           ["administrator", true, true]
+	 *
+	 * @param string $role                 Role of the current user.
+	 * @param bool   $gets_connection      Whether the user should see the connection details.
+	 * @param bool   $gets_install_url     Whether the user should get the install link.
+	 */
+	public function test_add_marketplace_settings_by_capability( string $role, bool $gets_connection, bool $gets_install_url ): void {
+		// Connecting refreshes subscription notes, which fetches subscriptions from WooCommerce.com.
+		add_filter(
+			'pre_http_request',
+			static fn() => array(
+				'response' => array(
+					'code'    => 200,
+					'message' => 'OK',
+				),
+				'headers'  => array(),
+				'body'     => '[]',
+				'cookies'  => array(),
+			)
+		);
+		WC_Helper_Options::update(
+			'auth',
+			array(
+				'access_token'        => self::ACCESS_TOKEN,
+				'access_token_secret' => 'test-access-token-secret',
+				'site_id'             => 1,
+			)
+		);
+		WC_Helper_Options::update( 'auth_user_data', array( 'email' => 'owner@example.org' ) );
+		wp_set_current_user( self::factory()->user->create( array( 'role' => $role ) ) );
+
+		$settings = WC_Helper_Admin::add_marketplace_settings( array() )['wccomHelper'];
+
+		$this->assertSame( $gets_connection, $settings['isConnected'] );
+		$this->assertSame( $gets_connection, str_contains( wp_json_encode( $settings ), 'owner@example.org' ) );
+		$this->assertSame( $gets_install_url, str_contains( wp_json_encode( $settings ), self::ACCESS_TOKEN ) );
+		$this->assertIsArray( $settings['installedProducts'] );
+	}
+
+	/**
+	 * @testdox Should give users who can't manage WooCommerce only the minimal marketplace settings.
+	 */
+	public function test_add_marketplace_settings_minimal_keys(): void {
+		wp_set_current_user( self::factory()->user->create( array( 'role' => 'contributor' ) ) );
+
+		$settings = WC_Helper_Admin::add_marketplace_settings( array() )['wccomHelper'];
+
+		$this->assertSameSets(
+			array( 'isConnected', 'storeCountry', 'installedProducts', 'wooUpdateManagerInstalled', 'wooUpdateManagerActive', 'trackingAllowed' ),
+			array_keys( $settings )
+		);
+	}
+}
diff --git a/plugins/woocommerce/tests/php/includes/admin/helper/class-wc-helper-subscriptions-api-test.php b/plugins/woocommerce/tests/php/includes/admin/helper/class-wc-helper-subscriptions-api-test.php
index eeb7dc48c5b..6b5a9b0a740 100644
--- a/plugins/woocommerce/tests/php/includes/admin/helper/class-wc-helper-subscriptions-api-test.php
+++ b/plugins/woocommerce/tests/php/includes/admin/helper/class-wc-helper-subscriptions-api-test.php
@@ -238,4 +238,34 @@ class WC_Helper_Subscriptions_API_Test extends \WC_Unit_Test_Case {
 		$this->assertIsArray( $response['data'] );
 		$this->assertStringContainsString( 'not supported', $response['data']['message'] );
 	}
+
+	/**
+	 * @testdox Should give install links only to users who can install plugins.
+	 *
+	 * @testWith ["shop_manager", false]
+	 *           ["administrator", true]
+	 *
+	 * @param string $role     Role of the current user.
+	 * @param bool   $expected Whether the user may request install links.
+	 */
+	public function test_install_url_requires_install_plugins( string $role, bool $expected ): void {
+		wp_set_current_user( self::factory()->user->create( array( 'role' => $role ) ) );
+
+		$route   = rest_get_server()->get_routes()['/wc/v3/marketplace/subscriptions/install-url'][0];
+		$request = new WP_REST_Request( 'GET', '/wc/v3/marketplace/subscriptions/install-url' );
+
+		$this->assertSame( $expected, call_user_func( $route['permission_callback'], $request ) );
+	}
+
+	/**
+	 * @testdox Should refuse install link requests from a Shop Manager.
+	 */
+	public function test_install_url_refuses_shop_manager(): void {
+		wp_set_current_user( self::factory()->user->create( array( 'role' => 'shop_manager' ) ) );
+
+		$request = new WP_REST_Request( 'GET', '/wc/v3/marketplace/subscriptions/install-url' );
+		$request->set_param( 'product_key', 'any' );
+
+		$this->assertSame( 403, rest_get_server()->dispatch( $request )->get_status() );
+	}
 }
diff --git a/plugins/woocommerce/tests/php/includes/wccom-site/class-wc-wccom-site-test.php b/plugins/woocommerce/tests/php/includes/wccom-site/class-wc-wccom-site-test.php
index 4d4c540436c..4744b8b0a9b 100644
--- a/plugins/woocommerce/tests/php/includes/wccom-site/class-wc-wccom-site-test.php
+++ b/plugins/woocommerce/tests/php/includes/wccom-site/class-wc-wccom-site-test.php
@@ -81,9 +81,10 @@ class WC_WCCOM_Site_Test extends WC_Unit_Test_Case {
 	 * Connect the site to WooCommerce.com and sign the current request with its credentials.
 	 *
 	 * @param int    $user_id     User the connection belongs to.
-	 * @param string $request_uri Request URI to sign.
+	 * @param string $request_uri Request URI as the signer saw it, without token and signature.
+	 * @return string The signature.
 	 */
-	private function sign_request_for_connected_site( int $user_id, string $request_uri ): void {
+	private function sign_request_for_connected_site( int $user_id, string $request_uri ): string {
 		WC_Helper_Options::update(
 			'auth',
 			array(
@@ -99,27 +100,26 @@ class WC_WCCOM_Site_Test extends WC_Unit_Test_Case {

 		$signed_data = array(
 			'host'        => 'example.org',
-			'request_uri' => urldecode( remove_query_arg( array( 'token', 'signature' ), $request_uri ) ),
+			'request_uri' => $request_uri,
 			'method'      => 'GET',
 		);

-		$_SERVER['HTTP_X_WOO_SIGNATURE'] = hash_hmac( 'sha256', wp_json_encode( $signed_data ), self::ACCESS_TOKEN_SECRET );
+		$signature                       = hash_hmac( 'sha256', wp_json_encode( $signed_data ), self::ACCESS_TOKEN_SECRET );
+		$_SERVER['HTTP_X_WOO_SIGNATURE'] = $signature;
+
+		return $signature;
 	}

 	/**
 	 * @testdox Should recognize a WooCommerce.com REST request only by the route WordPress dispatches.
 	 *
-	 * @testWith ["/wp-json/wccom-site/v3/status", false, null, true]
-	 *           ["/blog/wp-json/wccom-site/v3/status", false, null, true]
-	 *           ["/index.php/wp-json/wccom-site/v3/status", false, null, true]
+	 * @testWith ["/wp-json/wccom-site/v3/status", false, null, false]
 	 *           ["/wp-json/wccom-site/v3/status", true, "/wccom-site/v3/status", true]
-	 *           ["/wp-json/wccom-site/v3/status?rest_route=/wp/v2/users", false, null, false]
-	 *           ["/wp-json/wc/v3/products", false, null, false]
-	 *           ["/shop/?/wp-json/wccom-site/=1", false, null, false]
 	 *           ["/wp-json/wccom-site/v3/status", true, "/wp/v2/users", false]
-	 *           ["/wp-admin/admin-ajax.php?rest_route=/wccom-site/v3/status", false, null, false]
-	 *           ["/wp-admin/admin-ajax.php?rest_route=/wccom-site/v3/status", false, "/wccom-site/v3/status", false]
+	 *           ["/wp-json/wc/v3/products", true, "/wc/v3/products", false]
 	 *           ["/?rest_route=/wccom-site/v3/status", true, "/wccom-site/v3/status", true]
+	 *           ["/?rest_route=/wccom-site/v3/status", false, null, false]
+	 *           ["/wp-admin/admin-ajax.php?rest_route=/wccom-site/v3/status", false, "/wccom-site/v3/status", false]
 	 *           ["/?rest_route[]=/wccom-site/v3/status", true, null, false]
 	 *
 	 * @param string      $request_uri    Request URI.
@@ -136,6 +136,98 @@ class WC_WCCOM_Site_Test extends WC_Unit_Test_Case {
 		$this->assertSame( $expected, self::with_rest_route_context( $resolved_route, fn() => $method->invoke( null ) ) );
 	}

+	/**
+	 * @testdox Should verify a request signed over its whole path when the URI has no query string.
+	 *
+	 * @testWith ["/wp-json/wccom-site/v3/status"]
+	 *           ["/wp-json/wccom-site/v3/a.b&c=d"]
+	 *
+	 * @param string $request_uri Request URI.
+	 */
+	public function test_verify_wccom_request_signs_the_whole_path( string $request_uri ): void {
+		$user_id = self::factory()->user->create( array( 'role' => 'administrator' ) );
+		$this->simulate_request( $request_uri, false );
+		$signature = $this->sign_request_for_connected_site( $user_id, urldecode( $request_uri ) );
+
+		$method = new ReflectionMethod( WC_WCCOM_Site::class, 'verify_wccom_request' );
+		$method->setAccessible( true );
+
+		$this->assertTrue( $method->invoke( null, '', $signature, self::ACCESS_TOKEN_SECRET ) );
+	}
+
+	/**
+	 * @testdox Should reject a signature made for a different request URI.
+	 */
+	public function test_verify_wccom_request_rejects_signature_for_other_path(): void {
+		$user_id = self::factory()->user->create( array( 'role' => 'administrator' ) );
+		$this->simulate_request( '/wp-json/wccom-site/v3/installer', false );
+		$signature = $this->sign_request_for_connected_site( $user_id, '/wp-json/wccom-site/v3/status' );
+
+		$method = new ReflectionMethod( WC_WCCOM_Site::class, 'verify_wccom_request' );
+		$method->setAccessible( true );
+
+		$this->assertFalse( $method->invoke( null, '', $signature, self::ACCESS_TOKEN_SECRET ) );
+	}
+
+	/**
+	 * @testdox Should verify a request with a query string against the same data as before.
+	 *
+	 * @testWith ["/?rest_route=/wccom-site/v3/status&ts=1700000000&token=t&signature=s"]
+	 *           ["/blog/?rest_route=%2Fwccom-site%2Fv3%2Fstatus&ts=1700000000&token=t"]
+	 *           ["/wp-json/wccom-site/v3/installer?product-id=1&signature=s"]
+	 *
+	 * @param string $request_uri Request URI.
+	 */
+	public function test_verify_wccom_request_keeps_query_string_signing( string $request_uri ): void {
+		$user_id = self::factory()->user->create( array( 'role' => 'administrator' ) );
+		$this->simulate_request( $request_uri, false );
+		$signature = $this->sign_request_for_connected_site( $user_id, urldecode( remove_query_arg( array( 'token', 'signature' ), $request_uri ) ) );
+
+		$method = new ReflectionMethod( WC_WCCOM_Site::class, 'verify_wccom_request' );
+		$method->setAccessible( true );
+
+		$this->assertTrue( $method->invoke( null, '', $signature, self::ACCESS_TOKEN_SECRET ) );
+	}
+
+	/**
+	 * @testdox Should authenticate a request signed the way WooCommerce.com signs it, with credentials in the headers or only in the query.
+	 *
+	 * @testWith ["/", true]
+	 *           ["/", false]
+	 *           ["/blog/", false]
+	 *
+	 * @param string $site_path    Path of the store's URL.
+	 * @param bool   $with_headers Whether the token and signature are also sent as headers.
+	 */
+	public function test_authentication_fallback_accepts_request_signed_by_woocommerce_com( string $site_path, bool $with_headers ): void {
+		$user_id    = self::factory()->user->create( array( 'role' => 'administrator' ) );
+		$signed_uri = add_query_arg(
+			array(
+				'rest_route' => '/wccom-site/v3/status',
+				'ts'         => 1700000000,
+			),
+			$site_path
+		);
+		$signature  = $this->sign_request_for_connected_site( $user_id, $signed_uri );
+
+		$this->simulate_request(
+			add_query_arg(
+				array(
+					'token'     => self::ACCESS_TOKEN,
+					'signature' => $signature,
+				),
+				$signed_uri
+			),
+			true
+		);
+		if ( ! $with_headers ) {
+			unset( $_SERVER['HTTP_AUTHORIZATION'], $_SERVER['HTTP_X_WOO_SIGNATURE'] );
+		}
+
+		$this->assertTrue( self::with_rest_route_context( '/wccom-site/v3/status', fn() => WC_WCCOM_Site::authentication_fallback( null ) ) );
+		$this->assertSame( $user_id, get_current_user_id() );
+	}
+
 	/**
 	 * @testdox Should leave the current user alone on a request with an array rest_route parameter.
 	 */
@@ -146,17 +238,26 @@ class WC_WCCOM_Site_Test extends WC_Unit_Test_Case {
 	}

 	/**
-	 * @testdox Should authenticate a signed pretty-permalink request as the connected user before the route is resolved.
+	 * @testdox Should authenticate a signed pretty-permalink request only once WordPress has resolved the route.
+	 *
+	 * @testWith ["/wp-json/wccom-site/v3/status"]
+	 *           ["/blog/wp-json/wccom-site/v3/status"]
+	 *           ["/fr/wp-json/wccom-site/v3/status"]
+	 *           ["/index.php/wp-json/wccom-site/v3/status"]
+	 *
+	 * @param string $request_uri Request URI.
 	 */
-	public function test_authenticate_wccom_accepts_signed_pretty_permalink_request(): void {
+	public function test_authentication_fallback_accepts_signed_pretty_permalink_request( string $request_uri ): void {
 		$user_id = self::factory()->user->create( array( 'role' => 'administrator' ) );
-		$this->simulate_request( '/wp-json/wccom-site/v3/status', false );
-		$this->sign_request_for_connected_site( $user_id, '/wp-json/wccom-site/v3/status' );
+		$this->simulate_request( $request_uri, false );
+		$this->sign_request_for_connected_site( $user_id, $request_uri );
+
+		$this->assertFalse( self::with_rest_route_context( null, fn() => WC_WCCOM_Site::authenticate_wccom( false ) ) );

-		$user = self::with_rest_route_context( null, fn() => WC_WCCOM_Site::authenticate_wccom( false ) );
+		add_filter( 'wp_is_rest_endpoint', '__return_true', 11 );

-		$this->assertInstanceOf( WP_User::class, $user );
-		$this->assertSame( $user_id, $user->ID );
+		$this->assertTrue( self::with_rest_route_context( '/wccom-site/v3/status', fn() => apply_filters( 'rest_authentication_errors', null ) ) );
+		$this->assertSame( $user_id, get_current_user_id() );
 	}

 	/**
@@ -173,28 +274,21 @@ class WC_WCCOM_Site_Test extends WC_Unit_Test_Case {

 	/**
 	 * @testdox Should pass the previous result through for a signed request to a route outside wccom-site.
+	 *
+	 * @testWith ["/?rest_route=/wc/v3/products"]
+	 *           ["/wp-json/wccom-site/v3/status"]
+	 *
+	 * @param string $request_uri Request URI.
 	 */
-	public function test_authentication_fallback_ignores_other_routes(): void {
+	public function test_authentication_fallback_ignores_other_routes( string $request_uri ): void {
 		$user_id = self::factory()->user->create( array( 'role' => 'administrator' ) );
-		$this->simulate_request( '/?rest_route=/wc/v3/products', true );
-		$this->sign_request_for_connected_site( $user_id, '/?rest_route=/wc/v3/products' );
+		$this->simulate_request( $request_uri, true );
+		$this->sign_request_for_connected_site( $user_id, $request_uri );

 		$this->assertNull( self::with_rest_route_context( '/wc/v3/products', fn() => WC_WCCOM_Site::authentication_fallback( null ) ) );
 		$this->assertSame( 0, get_current_user_id() );
 	}

-	/**
-	 * @testdox Should leave a pretty-permalink request to determine_current_user.
-	 */
-	public function test_authentication_fallback_skips_requests_without_rest_route(): void {
-		$user_id = self::factory()->user->create( array( 'role' => 'administrator' ) );
-		$this->simulate_request( '/wp-json/wccom-site/v3/status', true );
-		$this->sign_request_for_connected_site( $user_id, '/wp-json/wccom-site/v3/status' );
-
-		$this->assertNull( self::with_rest_route_context( '/wccom-site/v3/status', fn() => WC_WCCOM_Site::authentication_fallback( null ) ) );
-		$this->assertSame( 0, get_current_user_id() );
-	}
-
 	/**
 	 * @testdox Should not authenticate a plain-permalink request with an invalid signature.
 	 */