CVE-2017-20157 (published 2022-12-31T10:15Z)

A vulnerability was found in Ariadne Component Library up to 2.x. It has been classified as critical. Affected is an unknown function of the file src/url/Url.php. The manipulation leads to server-side request forgery. Upgrading to version 3.0 is able to address this issue. It is recommended to upgrade the affected component. The identifier of this vulnerability is VDB-217140.

CVSS v3 base score: 9.8, CRITICAL (CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H)

Weakness information:
cwe_id: CWE-918
cwe_name: Server-Side Request Forgery (SSRF)
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.
extended_description: By providing URLs to unexpected hosts or ports, attackers can make it appear that the server is sending the request, possibly bypassing access controls such as firewalls that prevent the attackers from accessing the URLs directly. The server can be used as a proxy to conduct port scanning of hosts in internal networks, use other URLs such as that can access documents on the system (using file://), or use other protocols such as gopher:// or tftp://, which may provide greater control over the contents of requests.
         

Fix information:
repo_url: https://github.com/Ariadne-CMS/arc-web
commit_details: repo_url: https://github.com/Ariadne-CMS/arc-web
author: Auke van Slooten
author_date: 2017-09-26 11:47:59+02:00
msg: added checks for evil URL's (url's that could trigger parse errors and ssrf attacks)
added test for double port number ssrf attack and prevent it
repository: repo_url: https://github.com/Ariadne-CMS/arc-web
repo_name: Ariadne-CMS/arc-web
description: ARC: url, http and xss prevention components
repo_language: PHP
owner: Ariadne-CMS
file_changes: filename: Url.php
change_type: ModificationType.MODIFY
diff: @@ -12,29 +12,29 @@
 namespace arc\url;
 
 /**
- *	Url parses a URL string and returns an object with the seperate parts. You can change
- *	these and when cast to a string Url will regenerate the URL string and make sure it
- *	is valid.
+ * Url parses a URL string and returns an object with the seperate parts. You can change
+ * these and when cast to a string Url will regenerate the URL string and make sure it
+ * is valid.
  *
- *	Usage:
- *		$url = new \arc\url\Url( 'http://www.ariadne-cms.org/' );
- *		$url->path = '/docs/search/';
- *		$url->query = 'a=1&a=2';
- *		echo $url; // => 'http://www.ariadne-cms.org/docs/search/?a=1&a=2'
+ * Usage:
+ *    $url = new \arc\url\Url( 'http://www.ariadne-cms.org/' );
+ *    $url->path = '/docs/search/';
+ *    $url->query = 'a=1&a=2';
+ *    echo $url; // => 'http://www.ariadne-cms.org/docs/search/?a=1&a=2'
  * @property Query $query The query arguments
  */
 class Url
 {
     /**
-     *	All parts of the URL format, as returned by parse_url.
-     *	scheme://user:pass@host:port/path?query#fragment
+     * All parts of the URL format, as returned by parse_url.
+     * scheme://user:pass@host:port/path?query#fragment
      */
     public $scheme, $user, $pass, $host, $port, $path, $fragment;
     private $query;
 
     /**
-     *	@param string $url The URL to parse, the query part will remain a string.
-     *  @param QueryInterface queryObject Optional. An object that parses the query string.
+     * @param string $url The URL to parse, the query part will remain a string.
+     * @param QueryInterface queryObject Optional. An object that parses the query string.
      */
     public function __construct($url, $queryObject = null)
     {
@@ -42,6 +42,10 @@ class Url
             'scheme', 'host', 'port', 'user', 'pass', 'path', 'query', 'fragment'
         ];
         $this->importUrlComponents( parse_url( $url ), $componentList );
+        if ($this->scheme!='ldap' && strpos($this->host, ':')) {
+            // parse_url allows ':' in host when it occurs more than once\
+            $this->host = substr($this->host, 0, strpos($this->host, ':'));
+        }
         if ( isset( $queryObject ) ) {
             $this->query = $queryObject->import( $this->query );
         }

programming_language: PHP
filename: url.Test.php
change_type: ModificationType.MODIFY
diff: @@ -109,4 +109,59 @@
             $this->assertEquals( $commonUrls, $parsedUrls);
         }
 
+      function testEvilURL1()
+      {
+         $evilURL = 'http://127.0.0.1:11211:80/';
+         $parsed = \arc\url::url($evilURL);
+         $this->assertEquals( $parsed->port, 80 );
+         $parsedSafe = \arc\url::safeUrl($evilURL);
+         $this->assertEquals( $parsedSafe->port, 80 );
+         $safeURL = (string) $parsed;
+         $this->assertEquals( 'http://127.0.0.1:80/', $safeURL);
+      }
+
+      function testEvilURL2()
+      {
+         $evilURL = 'http://google.com#@evil.com/';
+         $parsed = \arc\url::url($evilURL);
+         $this->assertEquals( $parsed->host, 'google.com' );
+         $parsedSafe = \arc\url::safeUrl($evilURL);
+         $this->assertEquals( $parsedSafe->host, 'google.com');
+         $safeURL = (string) $parsed;
+         $this->assertEquals( 'http://google.com#%40evil.com%2F', $safeURL);
+      }
+
+      function testEvilURL3()
+      {
+         $evilURL = 'http://foo@evil.com:80@google.com/';
+         $parsed = \arc\url::url($evilURL);
+         $this->assertEquals( $parsed->host, 'google.com' );
+         $parsedSafe = \arc\url::safeUrl($evilURL);
+         $this->assertEquals( $parsedSafe->host, 'google.com');
+         $safeURL = (string) $parsed;
+         $this->assertEquals( 'http://foo%40evil.com:80@google.com/', $safeURL);
+      }
+
+      function testEvilURL4()
+      {
+         $evilURL = 'http://foo@127.0.0.1 @google.com/';
+         $parsed = \arc\url::url($evilURL);
+         $this->assertEquals( $parsed->host, 'google.com' );
+         $parsedSafe = \arc\url::safeUrl($evilURL);
+         $this->assertEquals( $parsedSafe->host, 'google.com');
+         $safeURL = (string) $parsed;
+         $this->assertEquals( 'http://foo%40127.0.0.1%20@google.com/', $safeURL);
+      }
+
+      function testEvilURL5()
+      {
+         $evilURL = 'http://127.0.0.1:11211#@google.com:80/';
+         $parsed = \arc\url::url($evilURL);
+         $this->assertEquals( $parsed->host, '127.0.0.1' );
+         $parsedSafe = \arc\url::safeUrl($evilURL);
+         $this->assertEquals( $parsedSafe->host, '127.0.0.1');
+         $safeURL = (string) $parsed;
+         $this->assertEquals( 'http://127.0.0.1:11211#%40google.com%3A80%2F', $safeURL);
+      }
+
     }

programming_language: PHP