CVE-2022-3708: Server-Side Request Forgery (SSRF) (CWE-918)
value: The Web Stories plugin for WordPress is vulnerable to Server-Side Request Forgery in versions up to, and including 1.24.0 due to insufficient validation of URLs supplied via the 'url' parameter found via the /v1/hotlink/proxy REST API Endpoint. This makes it possible for authenticated users to make web requests to arbitrary locations originating from the web application and can be used to query and modify information from internal services.
CWE description: The web server receives a URL or similar request from an upstream component and retrieves the contents of this URL, but it does not sufficiently ensure that the request is being sent to the expected destination.
CVSS v3 base score: 8.1
Published: 2022-10-28T19:15Z
Repository: https://github.com/GoogleForCreators/web-stories-wp
Language: PHP
Files changed: includes/REST_API/Hotlinking_Controller.php, tests/phpunit/integration/tests/REST_API/Hotlinking_Controller.php
Commit date: 2022-09-02 17:09:39 +0200
Commit message: Improve URL checks in hotlinking controller

Diff: diff --git a/includes/REST_API/Hotlinking_Controller.php b/includes/REST_API/Hotlinking_Controller.php
index efe3dc3a5..cd35c2ff3 100644
--- a/includes/REST_API/Hotlinking_Controller.php
+++ b/includes/REST_API/Hotlinking_Controller.php
@@ -670,13 +670,25 @@ class Hotlinking_Controller extends REST_Controller implements HasRequirements {
 					return false;
 				}
 			}
 
 			$parts = array_map( 'intval', explode( '.', $ip ) );
-			if ( 127 === $parts[0] || 10 === $parts[0] || 0 === $parts[0]
-				|| ( 172 === $parts[0] && 16 <= $parts[1] && 31 >= $parts[1] )
-				|| ( 192 === $parts[0] && 168 === $parts[1] )
+			if (
+				0 === $parts[0] // 0.0.0.0/8.
+				||
+				127 === $parts[0] // 127.0.0.0/8.
+				||
+				10 === $parts[0] // 10.0.0.0/8.
+				||
+				( 172 === $parts[0] && 16 <= $parts[1] && 31 >= $parts[1] ) // 172.16.0.0/12.
+				||
+				( 192 === $parts[0] && 168 === $parts[1] ) // 192.168.0.0/16.
+				||
+				( 169 === $parts[0] && 254 === $parts[1] ) // 169.254.0.0/16.
+				||
+				// phpcs:ignore Squiz.PHP.CommentedOutCode.Found
+				( 100 === $parts[0] && 64 <= $parts[1] && 127 >= $parts[1] ) // Private: 100.64.0.0/10.
 			) {
 				// If host appears local, reject.
 				return false;
 			}
 
diff --git a/tests/phpunit/integration/tests/REST_API/Hotlinking_Controller.php b/tests/phpunit/integration/tests/REST_API/Hotlinking_Controller.php
index f333c43c3..f017990a5 100644
--- a/tests/phpunit/integration/tests/REST_API/Hotlinking_Controller.php
+++ b/tests/phpunit/integration/tests/REST_API/Hotlinking_Controller.php
@@ -571,10 +571,13 @@ class Hotlinking_Controller extends DependencyInjectedRestTestCase {
 				'url' => 'http://exampleeeee.com/caniload.php',
 			],
 			'an external request when not allowed'         => [
 				'url' => 'http://192.168.0.1/caniload.php',
 			],
+			'a request with disallowed link-local ip'      => [
+				'url' => 'http://169.254.0.0/caniload.php',
+			],
 			'a port not considered safe by default'        => [
 				'url' => 'https://example.com:81/caniload.php',
 			],
 			'a port not considered safe by filter'         => [
 				'url'           => 'https://example.com:82/caniload.php',

Vulnerable code: 			if ( 127 === $parts[0] || 10 === $parts[0] || 0 === $parts[0]
				|| ( 172 === $parts[0] && 16 <= $parts[1] && 31 >= $parts[1] )
				|| ( 192 === $parts[0] && 168 === $parts[1] )
Fixed code: 			if (
				0 === $parts[0] // 0.0.0.0/8.
				||
				127 === $parts[0] // 127.0.0.0/8.
				||
				10 === $parts[0] // 10.0.0.0/8.
				||
				( 172 === $parts[0] && 16 <= $parts[1] && 31 >= $parts[1] ) // 172.16.0.0/12.
				||
				( 192 === $parts[0] && 168 === $parts[1] ) // 192.168.0.0/16.
				||
				( 169 === $parts[0] && 254 === $parts[1] ) // 169.254.0.0/16.
				||
				// phpcs:ignore Squiz.PHP.CommentedOutCode.Found
				( 100 === $parts[0] && 64 <= $parts[1] && 127 >= $parts[1] ) // Private: 100.64.0.0/10.
			'a request with disallowed link-local ip'      => [
				'url' => 'http://169.254.0.0/caniload.php',
			],