Issues (78)

Security Analysis    no request data  

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

lib/service/autoconfig/ispdb.php (2 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
/**
4
 * @author Bernhard Scheirle <[email protected]>
5
 * @author Christoph Wurst <[email protected]>
6
 * @author Scheirle <[email protected]>
7
 *
8
 * Mail
9
 *
10
 * This code is free software: you can redistribute it and/or modify
11
 * it under the terms of the GNU Affero General Public License, version 3,
12
 * as published by the Free Software Foundation.
13
 *
14
 * This program is distributed in the hope that it will be useful,
15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
 * GNU Affero General Public License for more details.
18
 *
19
 * You should have received a copy of the GNU Affero General Public License, version 3,
20
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
21
 *
22
 */
23
24
namespace OCA\Mail\Service\AutoConfig;
25
26
use Exception;
27
use OCA\Mail\Service\Logger;
28
29
class IspDb {
30
31
	/** @var Logger */
32
	private $logger;
33
34
	/** @var string[] */
35 2
	public function getUrls() {
36
		return [
37 2
			'https://autoconfig.{DOMAIN}/mail/config-v1.1.xml',
38 2
			'https://{DOMAIN}/.well-known/autoconfig/mail/config-v1.1.xml',
39 2
			'https://autoconfig.thunderbird.net/v1.1/{DOMAIN}',
40 2
		];
41
	}
42
43
	/**
44
	 * @param Logger $logger
45
	 * @param string[] $ispUrls
0 ignored issues
show
There is no parameter named $ispUrls. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
46
	 */
47 3
	public function __construct(Logger $logger) {
48 3
		$this->logger = $logger;
49 3
	}
50
51 3
	private function queryUrl($url) {
52
		try {
53 3
			$content = @file_get_contents($url, false, stream_context_create([
54
				'http' => [
55
					'timeout' => 7
56 3
				]
57 3
			]));
58 3
			if ($content !== false) {
59 3
				$xml = @simplexml_load_string($content);
60 3
			} else {
61 2
				$this->logger->debug("IsbDb: <$url> request timed out");
62 2
				return [];
63
			}
64
65 3
			if (libxml_get_last_error() !== false || !is_object($xml) || !$xml->emailProvider) {
66
				libxml_clear_errors();
67
				return [];
68
			}
69
			$provider = [
70 3
				'displayName' => (string) $xml->emailProvider->displayName,
71 3
			];
72 3
			foreach ($xml->emailProvider->children() as $tag => $server) {
73 3
				if (!in_array($tag, ['incomingServer', 'outgoingServer'])) {
74 3
					continue;
75
				}
76 3
				foreach ($server->attributes() as $name => $value) {
77 3
					if ($name == 'type') {
78 3
						$type = (string) $value;
79 3
					}
80 3
				}
81 3
				$data = [];
82 3
				foreach ($server as $name => $value) {
83 3
					foreach ($value->children() as $tag => $val) {
84 2
						$data[$name][$tag] = (string) $val;
85 3
					}
86 3
					if (!isset($data[$name])) {
87 3
						$data[$name] = (string) $value;
88 3
					}
89 3
				}
90 3
				$provider[$type][] = $data;
0 ignored issues
show
The variable $type does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
91 3
			}
92 3
		} catch (Exception $e) {
93
			// ignore own not-found exception or xml parsing exceptions
94
			unset($e);
95
			$provider = [];
96
		}
97 3
		return $provider;
98
	}
99
100
	/**
101
	 * @param string $domain
102
	 * @return array
103
	 */
104 3
	public function query($domain, $tryMx = true) {
105 3
		$this->logger->debug("IsbDb: querying <$domain>");
106 3
		if (strpos($domain, '@') !== false) {
107
			// TODO: use horde mail address parsing instead
108
			list(, $domain) = explode('@', $domain);
109
		}
110
111 3
		$provider = [];
112 3
		foreach ($this->getUrls() as $url) {
113 3
			$url = str_replace("{DOMAIN}", $domain, $url);
114 3
			$this->logger->debug("IsbDb: querying <$domain> via <$url>");
115
116 3
			$provider = $this->queryUrl($url);
117 3
			if (!empty($provider)) {
118 3
				return $provider;
119
			}
120 2
		}
121
122
		if ($tryMx && ($dns = dns_get_record($domain, DNS_MX))) {
123
			$domain = $dns[0]['target'];
124
			if (!($provider = $this->query($domain, false))) {
125
				list(, $domain) = explode('.', $domain, 2);
126
				$provider = $this->query($domain, false);
127
			}
128
		}
129
		return $provider;
130
	}
131
132
}
133