Commit 32b86c82d53 for woocommerce

commit 32b86c82d5308d2d070f52e1726f98997d9a9517
Author: Darren Ethier <darren@roughsmootheng.in>
Date:   Fri Dec 4 19:16:30 2026 -0500

    Only flag an unprotected WooCommerce uploads directory as critical when files are at risk (#71856)

    The Site Health uploads directory check reported an exposed directory as
    critical even when the store had no files to protect. With Force
    downloads or X-Accel-Redirect/X-Sendfile, the result is now critical
    only when a product or variation is downloadable or the directory holds
    another file. Otherwise it reports "WooCommerce uploads directory is not
    protected" as recommended.

    The downloadable check is a single LIMIT 1 query on the product lookup
    table. While that table is regenerating and the directory is empty, the
    result is recommended and asks the merchant to check again later. The
    directory scan only runs when the product check hasn't already made the
    result critical. It skips WooCommerce guard files, leftover Site Health
    probes and the GeoLite2 database, and stops at the first other file or
    after 500 entries.

    When the directory is confirmed exposed on Apache, the result adds a
    hint about AllowOverride None. Confirmed failures also link to the
    Apache or NGINX configuration guide. No link is shown when protection
    couldn't be verified.

    Adds an Apache configuration guide and expands the NGINX one. They cover
    rule placement around existing uploads locations, WordPress multisite
    rewrite rules, custom rewrites, multiple server blocks and virtual
    hosts, caches, Apache Alias, OpenLiteSpeed, file URLs that use another
    address, changing the download method, and checks that Site Health can't
    do.

    Closes #71811.

diff --git a/docs/code-snippets/using_apache_server_to_protect_your_uploads_directory.md b/docs/code-snippets/using_apache_server_to_protect_your_uploads_directory.md
new file mode 100644
index 00000000000..3ca0763dcce
--- /dev/null
+++ b/docs/code-snippets/using_apache_server_to_protect_your_uploads_directory.md
@@ -0,0 +1,81 @@
+---
+post_title: Using Apache server to protect your upload directory
+sidebar_label: Apache server to protect upload directory
+
+current wccom url: https://woocommerce.com/document/digital-downloadable-product-handling/#protecting-your-uploads-directory
+---
+
+# Using Apache server to protect your upload directory
+
+WooCommerce adds an `.htaccess` file to the `woocommerce_uploads` directory to stop downloadable product files from being fetched directly by URL. Apache only applies that file when the server configuration allows it. If Site Health reports that files in the WooCommerce uploads directory can be accessed directly from the web on an Apache server, the server is most likely ignoring `.htaccess` files, usually because `AllowOverride` is set to `None`.
+
+In that case, add the rule to the Apache server or virtual host configuration instead. The rules on this page can't go in an `.htaccess` file. If you can't edit the server configuration, for example on shared hosting, send your host a link to this page.
+
+Some hosts put NGINX in front of Apache and let NGINX serve files such as PDFs and images directly. Apache never sees those requests, so neither the `.htaccess` file nor the rules on this page apply, even though Site Health links to this page. Follow [Using NGINX server to protect your upload directory](./using_nginx_server_to_protect_your_uploads_directory.md) on the NGINX server instead. If your server runs OpenLiteSpeed, see [OpenLiteSpeed](#openlitespeed) below.
+
+The rule depends on your store's download method. To check it, go to **WooCommerce > Settings > Products > Downloadable products** and look at **File download method**. **Force downloads** is the default.
+
+Before you start:
+
+- Run `apachectl configtest` to check the configuration for errors before you reload Apache.
+- If a cache such as Varnish sits in front of Apache, purge any cached copies of files in `woocommerce_uploads` after adding the rule. The cache keeps serving files it has already stored.
+
+## X-Accel-Redirect/X-Sendfile or Force Downloads
+
+If your store uses the **X-Accel-Redirect/X-Sendfile** or **Force Downloads** download method, add this to your Apache 2.4 server configuration and reload Apache:
+
+```apache
+# Block direct access to WooCommerce downloadable product files.
+# Customers still get their files through WooCommerce download links.
+<DirectoryMatch "/wp-content/uploads/(sites/[0-9]+/)?woocommerce_uploads(/|$)">
+    Require all denied
+</DirectoryMatch>
+```
+
+- Add the rule outside any `<VirtualHost>` section so it covers every virtual host. A rule inside one `<VirtualHost>` only protects requests to that host, for example HTTPS but not HTTP. Site Health only checks your site's own address, so it doesn't notice a host you missed.
+- The rule covers folders inside `woocommerce_uploads` and multisite subsites (for example `/wp-content/uploads/sites/2/woocommerce_uploads/`). If your site moves the `wp-content` or uploads directory, change the path in the pattern to match.
+- The pattern matches the directory's path on disk, not its URL. If an `Alias` serves the uploads from a directory elsewhere, match that directory instead, for example `<DirectoryMatch "^/mnt/uploads/woocommerce_uploads(/|$)">`.
+- Use `Require all denied`, not `deny from all`. The older syntax only works on Apache 2.4 when the `mod_access_compat` module is loaded.
+- Customer downloads keep working. With **Force Downloads**, WooCommerce reads the file and sends it itself. With **X-Accel-Redirect/X-Sendfile**, Apache sends the file internally, and this rule doesn't change how that works.
+- `<Files>`, `<FilesMatch>` and `<Location>` sections are applied after `<DirectoryMatch>` sections, so one that grants access overrides this rule. For example, `<FilesMatch "\.pdf$"> Require all granted </FilesMatch>` makes PDFs downloadable again, and `<Location "/"> Require all granted </Location>` undoes the whole rule. Check the result as described below.
+- For files stored on this server, use your site's own address in the downloadable file URL. If the URL reaches this server through another address, such as another domain name for the same site, WooCommerce treats it as a file on another server and fetches it over the web, and this rule blocks that request. The download then fails, even with **Allow using redirect mode (insecure) as a last resort** turned on, because that setting sends the customer to the same blocked URL.
+
+## Redirect only
+
+With the **Redirect only** download method, customers are sent straight to the file, so files can't be blocked. Don't use the rule above with this method, because every download would fail. To stop the directory from listing its files, add this instead:
+
+```apache
+<DirectoryMatch "/wp-content/uploads/(sites/[0-9]+/)?woocommerce_uploads(/|$)">
+    Options -Indexes
+</DirectoryMatch>
+```
+
+## Changing the download method
+
+WooCommerce updates its own `.htaccess` file when you change the download method, but it can't change your server configuration. If you switch to or from **Redirect only**, update the rule in your server configuration at the same time.
+
+## OpenLiteSpeed
+
+OpenLiteSpeed ignores the `deny from all` line in the `.htaccess` file WooCommerce adds, and its server configuration doesn't use Apache's format. If your store uses **X-Accel-Redirect/X-Sendfile** or **Force Downloads**, add this context to the virtual host configuration, before the `/` context, and restart OpenLiteSpeed:
+
+```text
+context exp:^/wp-content/uploads/(sites/[0-9]+/)?woocommerce_uploads/ {
+  allowBrowse 0
+}
+```
+
+It blocks every request to the directory, so don't use it with **Redirect only**.
+
+## Check your configuration
+
+After reloading Apache, go to **Tools > Site Health** in your WordPress dashboard. The WooCommerce uploads directory check reports whether files in the WooCommerce uploads directory can be accessed directly from the web. With **Redirect only**, it reports whether the directory can be browsed instead.
+
+Site Health only checks your site's own address, using a file it creates. It can't see rules that only apply to some file types, virtual hosts for other addresses, or copies held by a cache. So also:
+
+- Unless your store uses **Redirect only**, open the URL of one of your downloadable files directly in a private browser window. Apache should return a 403 Forbidden error.
+- With **Redirect only**, open a folder inside the directory, such as `/wp-content/uploads/woocommerce_uploads/2026/12/`, and check that it doesn't list files. Site Health only checks the top folder.
+- Test a download from an order to make sure customers can still get their files.
+
+The rules only cover the `woocommerce_uploads` directory. Downloadable files stored anywhere else, such as the media library, can be opened by anyone who has the URL.
+
+If you do not know which web server you are using, please reach out to your host along with a link to this page.
diff --git a/docs/code-snippets/using_nginx_server_to_protect_your_uploads_directory.md b/docs/code-snippets/using_nginx_server_to_protect_your_uploads_directory.md
index 573e17ab2d2..2019a9e2d1f 100644
--- a/docs/code-snippets/using_nginx_server_to_protect_your_uploads_directory.md
+++ b/docs/code-snippets/using_nginx_server_to_protect_your_uploads_directory.md
@@ -11,6 +11,12 @@ WooCommerce adds an `.htaccess` file to the `woocommerce_uploads` directory to s

 The rule depends on your store's download method. To check it, go to **WooCommerce > Settings > Products > Downloadable products** and look at **File download method**. **Force downloads** is the default.

+Before you start:
+
+- Add the rules to every `server` block that serves your site, for example separate blocks for HTTP and HTTPS or for other domain names. Site Health only checks your site's own address, so it doesn't notice a `server` block you missed.
+- Run `nginx -t` to check the configuration for errors before you reload NGINX.
+- If a cache such as Varnish sits in front of NGINX, purge any cached copies of files in `woocommerce_uploads` after adding the rules. The cache keeps serving files it has already stored.
+
 ## X-Accel-Redirect/X-Sendfile or Force Downloads

 If your store uses the **X-Accel-Redirect/X-Sendfile** or **Force Downloads** download method, add this to your NGINX `server` block:
@@ -25,13 +31,51 @@ location ~* /woocommerce_uploads/ {

 Place it **before** any other `location` block that uses a regular expression, such as a rule for static files like `location ~* \.(pdf|zip|jpg)$`. NGINX uses the first regular expression location that matches a request, so a static file rule placed earlier would serve downloadable files directly.

-The rule matches the `woocommerce_uploads` directory wherever your uploads are stored, including multisite subsites (for example `/wp-content/uploads/sites/2/woocommerce_uploads/`) and sites that move the `wp-content` or uploads directory.
+Some configurations already have a `location` block for the uploads directory, such as `location ^~ /wp-content/uploads/`, a `location /wp-content/` block with regular expression locations inside it, or a block with its own `root` or `alias`. NGINX can then serve files without reaching the rule, or X-Accel-Redirect downloads fail. Put the rule inside that block as well, before any locations it already contains:
+
+```nginx
+location ^~ /wp-content/uploads/ {
+    location ~* /woocommerce_uploads/ {
+        internal;
+    }
+    # The block's existing directives stay here.
+}
+```
+
+If you can't edit that block, for example because a hosting control panel manages it, add `location ^~ /wp-content/uploads/woocommerce_uploads/ { internal; }` to the `server` block instead. It only covers that exact path, so it doesn't protect multisite subsites or a moved uploads directory.
+
+The rule matches the `woocommerce_uploads` directory wherever your uploads are stored, including multisite subsites (for example `/wp-content/uploads/sites/2/woocommerce_uploads/`) and sites that move the `wp-content` or uploads directory. If your configuration has WordPress's multisite rewrite rules, it also needs the block described below.
+
+NGINX treats a request changed by a `rewrite` rule as internal, so `internal` lets it through. A rule such as `rewrite ^/files/(.*)$ /wp-content/uploads/$1 last;` makes `/files/woocommerce_uploads/ebook.pdf` downloadable. The block in the next section also stops these requests if you place it before your `rewrite` rules.
+
+For files stored on this server, use your site's own address in the downloadable file URL. If the URL reaches this server through another address, such as another domain name for the same site, WooCommerce treats it as a file on another server and fetches it over the web, and this rule blocks that request. The download then fails, even with **Allow using redirect mode (insecure) as a last resort** turned on, because that setting sends the customer to the same blocked URL.
+
+### Configurations with WordPress multisite rewrite rules
+
+If your NGINX configuration has the rewrite rules WordPress uses for multisite networks with sites in subdirectories, such as `rewrite ^(/[^/]+)?(/wp-.*) $2 last;`, the rule above isn't enough. These rules turn a URL like `/shop/wp-content/uploads/sites/2/woocommerce_uploads/ebook.pdf` into `/wp-content/uploads/sites/2/woocommerce_uploads/ebook.pdf`, whatever the first part of the path is, and NGINX treats a rewritten request as internal, so `internal` lets it through. This applies to any site whose configuration has these rules, including a network with sites on subdomains or a single site that uses a multisite configuration. Add this to the same `server` block as well:

-If **Allow using redirect mode (insecure) as a last resort** is turned on under the same settings, WooCommerce sends customers straight to the file when the selected method fails. This rule blocks those direct requests, so the fallback download fails instead.
+```nginx
+# Block WooCommerce uploads reached through WordPress's multisite rewrites.
+# Real file paths, used by X-Accel-Redirect downloads, are not affected.
+set $wc_uploads_block "";
+if (!-e $request_filename) {
+    set $wc_uploads_block "missing";
+}
+if ($uri ~* "/woocommerce_uploads/") {
+    set $wc_uploads_block "${wc_uploads_block}-wc";
+}
+if ($wc_uploads_block = "missing-wc") {
+    return 403;
+}
+```
+
+Place it **before** WordPress's multisite rewrite rules, the `if (!-e $request_filename)` block that contains `rewrite ^(/[^/]+)?(/wp-.*) $2 last;`. When those rules rewrite a request, NGINX skips any rewrite directives that come after them, so this block placed later would never run. If your configuration doesn't have these rewrite rules, you don't need this block.
+
+If your uploads are served by a `location` block with its own `root` or `alias`, this block also stops X-Accel-Redirect downloads. Use **Force Downloads** in that case.

 ## Redirect only

-With the **Redirect only** download method, customers are sent straight to the file, so files can't be blocked. To stop the directory from listing its files, add:
+With the **Redirect only** download method, customers are sent straight to the file, so files can't be blocked. Don't use the rules above with this method, because every download would fail. To stop the directory from listing its files, add:

 ```nginx
 location ~* /woocommerce_uploads/ {
@@ -39,8 +83,20 @@ location ~* /woocommerce_uploads/ {
 }
 ```

+## Changing the download method
+
+Changing the download method in WooCommerce doesn't change your NGINX configuration. If you switch to **Redirect only**, remove the `internal` rules and the multisite block at the same time, or downloads fail while Site Health still reports the directory as protected. If you switch from **Redirect only**, add them back.
+
 ## Check your configuration

-After reloading NGINX, go to **Tools > Site Health** in your WordPress dashboard. The WooCommerce uploads directory check reports whether downloadable product files can be accessed directly from the web.
+After reloading NGINX, go to **Tools > Site Health** in your WordPress dashboard. The WooCommerce uploads directory check reports whether files in the WooCommerce uploads directory can be accessed directly from the web. With **Redirect only**, it reports whether the directory can be browsed instead.
+
+Site Health only checks your site's own address, using a file it creates. It can't see rules that only apply to some file types, `server` blocks for other addresses, or copies held by a cache. So also:
+
+- Unless your store uses **Redirect only**, open the URL of one of your downloadable files directly in a private browser window. NGINX should return a 404 Not Found error.
+- With **Redirect only**, open a folder inside the directory, such as `/wp-content/uploads/woocommerce_uploads/2026/12/`, and check that it doesn't list files. Site Health only checks the top folder.
+- Test a download from an order to make sure customers can still get their files.
+
+The rules only cover the `woocommerce_uploads` directory. Downloadable files stored anywhere else, such as the media library, can be opened by anyone who has the URL.

-If you do not know which web server you are using, please reach out to your host along with a link to this page.
+If your store runs on Apache instead, see [Using Apache server to protect your upload directory](./using_apache_server_to_protect_your_uploads_directory.md). If you do not know which web server you are using, please reach out to your host along with a link to this page.
diff --git a/plugins/woocommerce/changelog/71811-site-health-uploads-protection-severity b/plugins/woocommerce/changelog/71811-site-health-uploads-protection-severity
new file mode 100644
index 00000000000..68e92a97c2e
--- /dev/null
+++ b/plugins/woocommerce/changelog/71811-site-health-uploads-protection-severity
@@ -0,0 +1,4 @@
+Significance: patch
+Type: tweak
+
+Site Health no longer marks the WooCommerce uploads directory as critical when its files can be fetched directly but nothing stored there is at risk.
diff --git a/plugins/woocommerce/src/Internal/Admin/SiteHealth.php b/plugins/woocommerce/src/Internal/Admin/SiteHealth.php
index 01f0c8e55d1..9f1d5ced353 100644
--- a/plugins/woocommerce/src/Internal/Admin/SiteHealth.php
+++ b/plugins/woocommerce/src/Internal/Admin/SiteHealth.php
@@ -16,6 +16,10 @@ use Automattic\WooCommerce\Internal\Utilities\FilesystemUtil;
 use Automattic\WooCommerce\Internal\Utilities\ProductUtil;
 use Automattic\WooCommerce\Utilities\OrderUtil;
 use Exception;
+use FilesystemIterator;
+use RecursiveDirectoryIterator;
+use RecursiveIteratorIterator;
+use UnexpectedValueException;
 use WC_Admin_Notices;
 use WC_Admin_Status;
 use WC_Helper_Updater;
@@ -191,7 +195,12 @@ class SiteHealth {
 		$actions_html = '';
 		if ( ! $is_good && ! empty( $data['actions'] ) ) {
 			foreach ( $data['actions'] as $action ) {
-				$url           = is_callable( $action['url'] ) ? ( $action['url'] )( $context ) : $action['url'];
+				$url = is_callable( $action['url'] ) ? ( $action['url'] )( $context ) : $action['url'];
+
+				if ( empty( $url ) ) {
+					continue;
+				}
+
 				$actions_html .= $this->get_site_health_action( $url, $action['label'], ! empty( $action['new_tab'] ) );
 			}
 		}
@@ -220,7 +229,8 @@ class SiteHealth {
 	 *   - skip_cron: whether to exclude a direct test from scheduled checks (defaults to true).
 	 *   - good: result data when the check passes (label, description).
 	 *   - fail: result data when the check fails (status defaults to 'recommended', label, description, optional actions).
-	 *     Label, status, and description may be callables that receive the check context.
+	 *     Label, status, and description may be callables that receive the check context. An action URL may be a callable
+	 *     too; the action is left out when it returns an empty value.
 	 *
 	 * @return array<string, array>
 	 */
@@ -257,32 +267,46 @@ class SiteHealth {
 					'description' => function () {
 						return $this->uses_redirect_download_method()
 							? __( 'The directory used for downloadable product files is not browsable from the web.', 'woocommerce' )
-							: __( 'Downloadable product files cannot be accessed directly from the web.', 'woocommerce' );
+							: __( 'Files in the WooCommerce uploads directory cannot be accessed directly from the web.', 'woocommerce' );
 					},
 				),
 				'fail'  => array(
 					'status'      => function ( ?array $context ) {
-						return ! empty( $context['unverified'] ) ? 'recommended' : 'critical';
+						return empty( $context ) ? 'critical' : 'recommended';
 					},
 					'label'       => function ( ?array $context ) {
 						if ( ! empty( $context['unverified'] ) ) {
 							return __( 'WooCommerce could not verify uploads directory protection', 'woocommerce' );
 						}

+						if ( ! empty( $context['nothing_stored'] ) ) {
+							return __( 'WooCommerce uploads directory is not protected', 'woocommerce' );
+						}
+
 						return $this->uses_redirect_download_method()
 							? __( 'WooCommerce uploads directory is browsable from the web', 'woocommerce' )
-							: __( 'Downloadable product files can be accessed directly from the web', 'woocommerce' );
+							: __( 'Files in the WooCommerce uploads directory can be accessed directly from the web', 'woocommerce' );
 					},
 					'description' => function ( ?array $context ) {
 						if ( $this->uses_redirect_download_method() ) {
 							return ! empty( $context['unverified'] )
 								? __( 'A loopback request to the WooCommerce uploads directory failed, so WooCommerce could not confirm whether directory browsing is disabled. Check your server configuration or try again later.', 'woocommerce' )
-								: __( 'Directory browsing can expose downloadable product files. Configure your web server to prevent directory indexing for the WooCommerce uploads directory.', 'woocommerce' );
+								: __( 'Directory browsing can expose downloadable product files. Configure your web server to prevent directory indexing for the WooCommerce uploads directory.', 'woocommerce' ) . $this->get_ignored_htaccess_hint();
+						}
+
+						if ( ! empty( $context['unverified'] ) ) {
+							return __( 'WooCommerce could not confirm whether downloadable product files can be accessed directly from the web. This happens when test files cannot be written to the uploads directory, your site cannot make requests to itself, or uploads are served from somewhere else, such as a CDN or behind a login.', 'woocommerce' );
+						}
+
+						if ( ! empty( $context['products_unknown'] ) ) {
+							return __( 'Your web server does not block direct access to the WooCommerce uploads directory. Nothing is stored there right now, but WooCommerce could not check whether your store has downloadable products because product data is being updated. Check again once the update finishes, and block direct access to this directory before you sell downloadable products.', 'woocommerce' ) . $this->get_ignored_htaccess_hint();
+						}
+
+						if ( ! empty( $context['nothing_stored'] ) ) {
+							return __( 'Your web server does not block direct access to the WooCommerce uploads directory. Your store has no downloadable products and nothing stored there is at risk right now, but files added later would be. Block direct access to this directory before you sell downloadable products.', 'woocommerce' ) . $this->get_ignored_htaccess_hint();
 						}

-						return ! empty( $context['unverified'] )
-							? __( 'WooCommerce could not confirm whether downloadable product files can be accessed directly from the web. This happens when test files cannot be written to the uploads directory, your site cannot make requests to itself, or uploads are served from somewhere else, such as a CDN or behind a login.', 'woocommerce' )
-							: __( 'Anyone with the URL of a downloadable product file can download it without buying the product. Configure your web server to block direct access to the WooCommerce uploads directory.', 'woocommerce' );
+						return __( 'Anyone with the URL of a file in the WooCommerce uploads directory, such as a downloadable product file, can download it. Configure your web server to block direct access to this directory.', 'woocommerce' ) . $this->get_ignored_htaccess_hint();
 					},
 					'actions'     => array(
 						array(
@@ -290,6 +314,20 @@ class SiteHealth {
 							'label'   => __( 'Learn how to protect downloads', 'woocommerce' ),
 							'new_tab' => true,
 						),
+						array(
+							'url'     => fn( ?array $context ) => empty( $context['unverified'] ) && ! empty( $GLOBALS['is_apache'] )
+								? 'https://developer.woocommerce.com/docs/code-snippets/using_apache_server_to_protect_your_uploads_directory/'
+								: '',
+							'label'   => __( 'Apache configuration guide', 'woocommerce' ),
+							'new_tab' => true,
+						),
+						array(
+							'url'     => fn( ?array $context ) => empty( $context['unverified'] ) && ! empty( $GLOBALS['is_nginx'] )
+								? 'https://developer.woocommerce.com/docs/code-snippets/using_nginx_server_to_protect_your_uploads_directory/'
+								: '',
+							'label'   => __( 'NGINX configuration guide', 'woocommerce' ),
+							'new_tab' => true,
+						),
 					),
 				),
 			),
@@ -737,16 +775,116 @@ class SiteHealth {
 	 * With the "Redirect only" download method files are served directly by design, so only directory browsing is checked.
 	 * Other methods need the files themselves to be blocked.
 	 *
-	 * @return bool|array{unverified: true}
+	 * An unprotected directory is only critical when something there is at risk: a downloadable product, or a file
+	 * other than the ones WooCommerce adds itself.
+	 *
+	 * @return bool|array{unverified: true}|array{nothing_stored: true, products_unknown?: true}
 	 */
 	private function is_uploads_directory_protected() {
-		$status = $this->uses_redirect_download_method() ? $this->get_uploads_directory_browsing_status() : $this->get_uploads_file_access_status();
+		$uses_redirect = $this->uses_redirect_download_method();
+		$status        = $uses_redirect ? $this->get_uploads_directory_browsing_status() : $this->get_uploads_file_access_status();

 		if ( 'unverified' === $status ) {
 			return array( 'unverified' => true );
 		}

-		return 'protected' === $status;
+		if ( 'protected' === $status ) {
+			return true;
+		}
+
+		if ( $uses_redirect ) {
+			return false;
+		}
+
+		$has_downloadable_products = $this->store_has_downloadable_products();
+
+		if ( true === $has_downloadable_products || $this->has_files_in_uploads_directory() ) {
+			return false;
+		}
+
+		return null === $has_downloadable_products
+			? array(
+				'nothing_stored'   => true,
+				'products_unknown' => true,
+			)
+			: array( 'nothing_stored' => true );
+	}
+
+	/**
+	 * Check whether any product or variation is downloadable.
+	 *
+	 * @return bool|null True when one is or the query fails, null while the product lookup table is being regenerated.
+	 */
+	private function store_has_downloadable_products(): ?bool {
+		global $wpdb;
+
+		if ( get_option( 'woocommerce_product_lookup_table_is_generating' ) ) {
+			return null;
+		}
+
+		$product_id = $wpdb->get_var( "SELECT product_id FROM {$wpdb->wc_product_meta_lookup} WHERE downloadable = 1 LIMIT 1" );
+
+		return null !== $product_id || '' !== $wpdb->last_error;
+	}
+
+	/**
+	 * Check whether the WooCommerce uploads directory holds any file besides the ones WooCommerce adds itself.
+	 *
+	 * Those are the index.html and .htaccess guard files, Site Health test files and the MaxMind GeoLite2 database,
+	 * which has a random file name and holds public data. The scan stops after a fixed number of entries.
+	 *
+	 * @return bool True when it does, when the directory can't be read, or when it has too many entries to scan.
+	 */
+	private function has_files_in_uploads_directory(): bool {
+		$directory = wp_get_upload_dir()['basedir'] . '/woocommerce_uploads';
+
+		if ( ! is_dir( $directory ) ) {
+			return false;
+		}
+
+		try {
+			$entries = new RecursiveIteratorIterator(
+				new RecursiveDirectoryIterator( $directory, FilesystemIterator::SKIP_DOTS ),
+				RecursiveIteratorIterator::SELF_FIRST
+			);
+			$scanned = 0;
+
+			foreach ( $entries as $entry ) {
+				if ( ++$scanned > 500 ) {
+					return true;
+				}
+
+				$name = $entry->getFilename();
+
+				if (
+					( $entry->isDir() && ! $entry->isLink() )
+					|| in_array( $name, array( 'index.html', '.htaccess' ), true )
+					|| preg_match( '/^wc-site-health-[0-9a-f]{12}\.txt$/', $name )
+					|| ( 0 === $entries->getDepth() && preg_match( '/^([a-zA-Z0-9]+-)?GeoLite2-Country\.mmdb$/', $name ) )
+				) {
+					continue;
+				}
+
+				return true;
+			}
+		} catch ( UnexpectedValueException $e ) {
+			return true;
+		}
+
+		return false;
+	}
+
+	/**
+	 * Point Apache sites that serve the WooCommerce uploads directory at the most likely cause: an ignored .htaccess file.
+	 *
+	 * @return string The explanation with a leading space, or '' on other web servers.
+	 */
+	private function get_ignored_htaccess_hint(): string {
+		if ( empty( $GLOBALS['is_apache'] ) ) {
+			return '';
+		}
+
+		return ' ' . __( 'If your site runs on Apache, check that it reads the .htaccess file WooCommerce adds to this directory. Apache ignores it when AllowOverride is set to None.', 'woocommerce' );
 	}

 	/**
diff --git a/plugins/woocommerce/tests/php/src/Internal/Admin/SiteHealthTest.php b/plugins/woocommerce/tests/php/src/Internal/Admin/SiteHealthTest.php
index 80837dbd3d3..06ffd4400c0 100644
--- a/plugins/woocommerce/tests/php/src/Internal/Admin/SiteHealthTest.php
+++ b/plugins/woocommerce/tests/php/src/Internal/Admin/SiteHealthTest.php
@@ -7,7 +7,9 @@ use Automattic\WooCommerce\Internal\Admin\SiteHealth;
 use Automattic\WooCommerce\Internal\DataStores\Orders\CustomOrdersTableController;
 use Automattic\WooCommerce\Internal\DataStores\Orders\OrdersTableDataStore;
 use Automattic\WooCommerce\Internal\ProductDownloads\ApprovedDirectories\Register as Download_Directories;
+use Automattic\WooCommerce\Internal\Utilities\FilesystemUtil;
 use WC_Admin_Notices;
+use WC_Helper_Product;
 use WC_Unit_Test_Case;
 use WP_Error;
 use WP_REST_Request;
@@ -23,6 +25,20 @@ class SiteHealthTest extends WC_Unit_Test_Case {
 	 */
 	private SiteHealth $sut;

+	/**
+	 * Temporary uploads directory created by the current test, if any.
+	 *
+	 * @var string|null
+	 */
+	private ?string $temporary_uploads_directory = null;
+
+	/**
+	 * Uploaded file paths requested through serve_uploads_directly().
+	 *
+	 * @var string[]
+	 */
+	private array $requested_upload_paths = array();
+
 	/**
 	 * Set up test fixtures.
 	 */
@@ -37,6 +53,11 @@ class SiteHealthTest extends WC_Unit_Test_Case {
 	 * Tear down test fixtures.
 	 */
 	public function tearDown(): void {
+		if ( $this->temporary_uploads_directory ) {
+			FilesystemUtil::get_wp_filesystem_direct()->rmdir( $this->temporary_uploads_directory, true );
+			$this->temporary_uploads_directory = null;
+		}
+
 		delete_option( 'wc_downloads_approved_directories_mode' );
 		delete_option( 'woocommerce_file_download_method' );
 		WC_Admin_Notices::remove_notice( 'download_directories_sync_complete', true );
@@ -330,37 +351,82 @@ class SiteHealthTest extends WC_Unit_Test_Case {
 	}

 	/**
-	 * @testdox Upload directory protection check is critical when the web server serves uploaded files directly.
+	 * @testdox Upload directory protection check is critical when the web server serves uploaded files directly and the store has downloadable products.
 	 */
 	public function test_uploads_directory_protection_is_critical_when_files_are_served_directly(): void {
-		$uploads         = wp_get_upload_dir();
-		$requested_paths = array();
-		$filter_callback = static function ( $_preempt, $_parsed_args, $url ) use ( $uploads, &$requested_paths ) {
-			unset( $_preempt, $_parsed_args );
+		$product = WC_Helper_Product::create_simple_product();
+		$product->set_downloadable( true );
+		$product->save();

-			$path              = str_replace( $uploads['baseurl'], $uploads['basedir'], $url );
-			$requested_paths[] = $path;
+		$directory = $this->use_temporary_uploads_directory();
+		$this->serve_uploads_directly();

-			return array(
-				'headers'  => array(),
-				'body'     => file_get_contents( $path ), // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents
-				'response' => array(
-					'code'    => 200,
-					'message' => 'OK',
-				),
-				'cookies'  => array(),
-				'filename' => null,
-			);
-		};
+		$result = $this->sut->run_test( 'woocommerce_uploads_directory_protection' );

-		add_filter( 'pre_http_request', $filter_callback, 10, 3 );
+		$this->assertSame( 'critical', $result['status'], 'Directly downloadable files should be a confirmed security failure.' );
+		$this->assertSame( 'Files in the WooCommerce uploads directory can be accessed directly from the web', $result['label'], 'Directly downloadable files should report that files are exposed.' );
+		$this->assertStringStartsWith( $directory . '/woocommerce_uploads/', $this->requested_upload_paths[0], 'The check should request a file in the WooCommerce uploads directory.' );
+		$this->assertFileDoesNotExist( $this->requested_upload_paths[0], 'The temporary file should be deleted after the request.' );
+	}
+
+	/**
+	 * @testdox Upload directory protection check is only critical without downloadable products when the directory holds a file WooCommerce did not add itself.
+	 * @testWith [["index.html", ".htaccess", "reports/index.html", "reports/.htaccess", "abc123-GeoLite2-Country.mmdb"], "recommended", "WooCommerce uploads directory is not protected"]
+	 *           [["index.html", "reports/wc-customers-report-export-17700000001234.csv"], "critical", "Files in the WooCommerce uploads directory can be accessed directly from the web"]
+	 *           [["index.html", "reports/abc123-GeoLite2-Country.mmdb"], "critical", "Files in the WooCommerce uploads directory can be accessed directly from the web"]
+	 *
+	 * @param string[] $files           Files to put in the WooCommerce uploads directory.
+	 * @param string   $expected_status Expected Site Health status.
+	 * @param string   $expected_label  Expected Site Health label.
+	 */
+	public function test_uploads_directory_protection_severity_without_downloadable_products( array $files, string $expected_status, string $expected_label ): void {
+		$directory = $this->use_temporary_uploads_directory();
+
+		foreach ( $files as $file ) {
+			wp_mkdir_p( dirname( "{$directory}/woocommerce_uploads/{$file}" ) );
+			file_put_contents( "{$directory}/woocommerce_uploads/{$file}", 'contents' ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_file_put_contents
+		}
+
+		$this->serve_uploads_directly();

 		$result = $this->sut->run_test( 'woocommerce_uploads_directory_protection' );

-		$this->assertSame( 'critical', $result['status'], 'Directly downloadable files should be a confirmed security failure.' );
-		$this->assertSame( 'Downloadable product files can be accessed directly from the web', $result['label'], 'Directly downloadable files should report that files are exposed.' );
-		$this->assertStringStartsWith( $uploads['basedir'] . '/woocommerce_uploads/', $requested_paths[0], 'The check should request a file in the WooCommerce uploads directory.' );
-		$this->assertFileDoesNotExist( $requested_paths[0], 'The temporary file should be deleted after the request.' );
+		$this->assertSame( $expected_status, $result['status'], 'Severity should depend on whether anything in the directory is at risk.' );
+		$this->assertSame( $expected_label, $result['label'], 'The label should match the severity.' );
+	}
+
+	/**
+	 * @testdox Upload directory protection check explains on Apache that the .htaccess file is probably ignored.
+	 */
+	public function test_uploads_directory_protection_explains_ignored_htaccess_on_apache(): void {
+		global $is_apache;
+
+		$was_apache = $is_apache;
+		$is_apache  = true; // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
+		$this->serve_uploads_directly();
+
+		try {
+			$result = $this->sut->run_test( 'woocommerce_uploads_directory_protection' );
+		} finally {
+			$is_apache = $was_apache; // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
+		}
+
+		$this->assertStringContainsString( 'AllowOverride', $result['description'], 'Apache servers that serve the files should be pointed at their .htaccess setting.' );
+		$this->assertStringContainsString( 'using_apache_server_to_protect_your_uploads_directory', $result['actions'], 'Apache servers should get a link to the Apache configuration guide.' );
+	}
+
+	/**
+	 * @testdox Upload directory protection check asks to check again when it can't tell whether the store has downloadable products.
+	 */
+	public function test_uploads_directory_protection_asks_to_check_again_while_product_data_is_updated(): void {
+		update_option( 'woocommerce_product_lookup_table_is_generating', true );
+		$this->use_temporary_uploads_directory();
+		$this->serve_uploads_directly();
+
+		$result = $this->sut->run_test( 'woocommerce_uploads_directory_protection' );
+
+		$this->assertSame( 'recommended', $result['status'], 'An empty directory should not be critical while product data is being updated.' );
+		$this->assertStringContainsString( 'Check again once the update finishes', $result['description'], 'The description should say why the result may change.' );
 	}

 	/**
@@ -395,7 +461,7 @@ class SiteHealthTest extends WC_Unit_Test_Case {
 		$result = $this->sut->run_test( 'woocommerce_uploads_directory_protection' );

 		$this->assertSame( 'good', $result['status'], 'Files that are not served should be reported as protected.' );
-		$this->assertStringContainsString( 'Downloadable product files cannot be accessed directly from the web.', $result['description'], 'The protected description should refer to file access.' );
+		$this->assertStringContainsString( 'Files in the WooCommerce uploads directory cannot be accessed directly from the web.', $result['description'], 'The protected description should refer to file access.' );
 	}

 	/**
@@ -504,6 +570,57 @@ class SiteHealthTest extends WC_Unit_Test_Case {
 		$this->assertSame( 0, $request_count, 'No request should be made without a temporary file.' );
 	}

+	/**
+	 * Make loopback requests to uploaded files return their contents, as a server that doesn't block them would.
+	 *
+	 * Requested file paths are recorded in $requested_upload_paths.
+	 */
+	private function serve_uploads_directly(): void {
+		$uploads         = wp_get_upload_dir();
+		$filter_callback = function ( $_preempt, $_parsed_args, $url ) use ( $uploads ) {
+			unset( $_preempt, $_parsed_args );
+
+			$path                           = str_replace( $uploads['baseurl'], $uploads['basedir'], $url );
+			$this->requested_upload_paths[] = $path;
+
+			return array(
+				'headers'  => array(),
+				'body'     => file_get_contents( $path ), // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents
+				'response' => array(
+					'code'    => 200,
+					'message' => 'OK',
+				),
+				'cookies'  => array(),
+				'filename' => null,
+			);
+		};
+
+		add_filter( 'pre_http_request', $filter_callback, 10, 3 );
+	}
+
+	/**
+	 * Point the uploads directory at a new, empty temporary directory for the rest of the test.
+	 *
+	 * @return string The temporary uploads base directory.
+	 */
+	private function use_temporary_uploads_directory(): string {
+		$directory = get_temp_dir() . 'wc-site-health-test-' . wp_generate_password( 8, false );
+		wp_mkdir_p( $directory . '/woocommerce_uploads' );
+		$this->temporary_uploads_directory = $directory;
+
+		add_filter(
+			'upload_dir',
+			static function ( $uploads ) use ( $directory ) {
+				$uploads['basedir'] = $directory;
+				$uploads['baseurl'] = 'http://example.org/temporary-uploads';
+
+				return $uploads;
+			}
+		);
+
+		return $directory;
+	}
+
 	/**
 	 * Replace HPOS table statistics with predictable estimates.
 	 *