Commit b717ce22ce0 for woocommerce

commit b717ce22ce016d260b1f2e92048432ecdfe03dc7
Author: Luigi Teschio <gigitux@gmail.com>
Date:   Fri Nov 20 18:06:38 2026 +0100

    Resolve shortcodes before generating download paths (#71246)

    (cherry picked from commit 8988f94903a066364ab8f4d08964d923ef270535)

    Co-authored-by: Albert Juhé Lluveras <contact@albertjuhe.com>

diff --git a/plugins/woocommerce/includes/class-wc-product-download.php b/plugins/woocommerce/includes/class-wc-product-download.php
index afa5e7d1a37..03ccaccb260 100644
--- a/plugins/woocommerce/includes/class-wc-product-download.php
+++ b/plugins/woocommerce/includes/class-wc-product-download.php
@@ -160,7 +160,7 @@ class WC_Product_Download implements ArrayAccess {

 		// Shortcodes are allowed, validations should be done by the shortcode provider in this case.
 		if ( 'shortcode' === $file_path_type ) {
-			return true;
+			return 0 === validate_file( $file_path );
 		}

 		// Remote paths are allowed.
diff --git a/plugins/woocommerce/tests/php/includes/class-wc-product-downloads-test.php b/plugins/woocommerce/tests/php/includes/class-wc-product-downloads-test.php
index 2c3727508b1..c60199242ca 100644
--- a/plugins/woocommerce/tests/php/includes/class-wc-product-downloads-test.php
+++ b/plugins/woocommerce/tests/php/includes/class-wc-product-downloads-test.php
@@ -43,6 +43,24 @@ class WC_Product_Download_Test extends WC_Unit_Test_Case {
 		}
 	}

+	/**
+	 * @testdox Shortcode download paths are allowed only when validate_file() accepts them.
+	 *
+	 * @testWith ["[s3 bucket=\"file.pdf\"]", true]
+	 *           ["[../wp-config.php]", false]
+	 *           ["[../../secret]", false]
+	 *           ["[:C/windows]", false]
+	 *
+	 * @param string $file    Download file path stored as a shortcode.
+	 * @param bool   $allowed Whether the shortcode is an allowed filetype.
+	 */
+	public function test_shortcode_file_paths_must_pass_validate_file( string $file, bool $allowed ): void {
+		$download = new WC_Product_Download();
+		$download->set_file( $file );
+
+		$this->assertSame( $allowed, $download->is_allowed_filetype(), $file );
+	}
+
 	/**
 	 * Test that download URLs are automatically added to the approved directories list (for
 	 * "admin"-level users) but that they are not automatically added in other cases.