CVE-2017-20157 (PHP, published 2022-12-31T10:15Z)
Description: value: 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.
Severity: nan (CVSS v3 base score: 9.8)
Weakness: CWE-918 \u2014 Server-Side Request Forgery (SSRF)
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.
Repository: https://github.com/Ariadne-CMS/arc-web
Files changed:
src/url/Url.php
tests/url.Test.php
Commit message: 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


Vulnerable code:
 *	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'
     *	All parts of the URL format, as returned by parse_url.
     *	scheme://user:pass@host:port/path?query#fragment
     *	@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.

Fixed code:
 * 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'
     * All parts of the URL format, as returned by parse_url.
     * scheme://user:pass@host:port/path?query#fragment
     * @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.
        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, ':'));
        }
      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);
      }