Issues (52)

Security Analysis    not enabled

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.

src/Command/DetectCommand.php (4 issues)

Labels
Severity

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
 * @author Victor Dubiniuk <[email protected]>
4
 *
5
 * @copyright Copyright (c) 2015, ownCloud, Inc.
6
 * @license AGPL-3.0
7
 *
8
 * This code is free software: you can redistribute it and/or modify
9
 * it under the terms of the GNU Affero General Public License, version 3,
10
 * as published by the Free Software Foundation.
11
 *
12
 * This program is distributed in the hope that it will be useful,
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
 * GNU Affero General Public License for more details.
16
 *
17
 * You should have received a copy of the GNU Affero General Public License, version 3,
18
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
19
 *
20
 */
21
22
namespace Owncloud\Updater\Command;
23
24
use Symfony\Component\Console\Input\InputInterface;
25
use Symfony\Component\Console\Input\InputOption;
26
use Symfony\Component\Console\Output\OutputInterface;
27
use Symfony\Component\Console\Question\ChoiceQuestion;
28
use GuzzleHttp\Event\ProgressEvent;
29
use GuzzleHttp\Exception\ClientException;
30
use Owncloud\Updater\Utils\Fetcher;
31
use Owncloud\Updater\Utils\ConfigReader;
32
use \Owncloud\Updater\Controller\DownloadController;
33
34
/**
35
 * Class DetectCommand
36
 *
37
 * @package Owncloud\Updater\Command
38
 */
39
class DetectCommand extends Command {
40
41
	/**
42
	 * @var Fetcher $fetcher
43
	 */
44
	protected $fetcher;
45
46
	/**
47
	 * @var ConfigReader $configReader
48
	 */
49
	protected $configReader;
50
51
	/**
52
	 *
53
	 */
54
	protected $output;
55
56
	/**
57
	 * Constructor
58
	 *
59
	 * @param Fetcher $fetcher
60
	 * @param ConfigReader $configReader
61
	 */
62
	public function __construct(Fetcher $fetcher, ConfigReader $configReader){
63
		parent::__construct();
64
		$this->fetcher = $fetcher;
65
		$this->configReader = $configReader;
66
	}
67
68
	protected function configure(){
69
		$this
70
				->setName('upgrade:detect')
71
				->setDescription('Detect
72
- 1. currently existing code, 
73
- 2. version in config.php, 
74
- 3. online available verison.
75
(ASK) what to do? (download, upgrade, abort, …)')
76
				->addOption(
77
						'exit-if-none', null, InputOption::VALUE_NONE, 'exit with non-zero status code if new version is not found'
78
				)
79
				->addOption(
80
						'only-check', null, InputOption::VALUE_NONE, 'Only check if update is available'
81
				)
82
		;
83
		;
84
	}
85
86
	/**
87
	 * @param InputInterface $input
88
	 * @param OutputInterface $output
89
	 * @return int
90
	 */
91
	protected function execute(InputInterface $input, OutputInterface $output){
92
		$registry = $this->container['utils.registry'];
93
		$registry->set('feed', false);
94
95
		$fsHelper = $this->container['utils.filesystemhelper'];
96
		$downloadController = new DownloadController($this->fetcher, $registry, $fsHelper);
97
		try {
98
			$currentVersion = $this->configReader->getByPath('system.version');
99
			if (!strlen($currentVersion)){
100
				throw new \UnexpectedValueException('Could not detect installed version.');
101
			}
102
103
			$this->getApplication()->getLogger()->info('ownCloud ' . $currentVersion . ' found');
0 ignored issues
show
It seems like you code against a specific sub-type and not the parent class Symfony\Component\Console\Application as the method getLogger() does only exist in the following sub-classes of Symfony\Component\Console\Application: Owncloud\Updater\Console\Application. Maybe you want to instanceof check for one of these explicitly?

Let’s take a look at an example:

abstract class User
{
    /** @return string */
    abstract public function getPassword();
}

class MyUser extends User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the parent class:

    abstract class User
    {
        /** @return string */
        abstract public function getPassword();
    
        /** @return string */
        abstract public function getDisplayName();
    }
    
Loading history...
104
			$output->writeln('Current version is ' . $currentVersion);
105
106
			$feedData = $downloadController->checkFeed();
107
			if (!$feedData['success']){
108
				// Network errors, etc
109
				$output->writeln("Can't fetch feed.");
110
				$output->writeln($feedData['exception']->getMessage());
111
				$this->getApplication()->logException($feedData['exception']);
0 ignored issues
show
It seems like you code against a specific sub-type and not the parent class Symfony\Component\Console\Application as the method logException() does only exist in the following sub-classes of Symfony\Component\Console\Application: Owncloud\Updater\Console\Application. Maybe you want to instanceof check for one of these explicitly?

Let’s take a look at an example:

abstract class User
{
    /** @return string */
    abstract public function getPassword();
}

class MyUser extends User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the parent class:

    abstract class User
    {
        /** @return string */
        abstract public function getPassword();
    
        /** @return string */
        abstract public function getDisplayName();
    }
    
Loading history...
112
				// Return a number to stop the queue
113
				return $input->getOption('exit-if-none') ? 4 : null;
114
			}
115
116
			/** @var \Owncloud\Updater\Utils\Feed $feed */
117
			$feed = $feedData['data']['feed'];
118
			if (!$feed->isValid()){
119
				// Feed is empty. Means there are no updates
120
				$output->writeln('No updates found online.');
121
				return $input->getOption('exit-if-none') ? 4 : null;
122
			}
123
124
			$registry->set('feed', $feed);
125
			$output->writeln(
126
				sprintf(
127
					'Online version is %s [%s]',
128
					$feed->getVersion(),
129
					$this->fetcher->getUpdateChannel()
130
				)
131
			);
132
133
			if ($input->getOption('only-check')){
134
				return 0;
135
			}
136
137
			$action = $this->ask($input, $output);
138
			if ($action === 'abort'){
139
				$output->writeln('Exiting on user command.');
140
				return 128;
141
			}
142
143
			$this->output = $output;
144
			$packageData = $downloadController->downloadOwncloud([$this, 'progress']);
145
			//Empty line, in order not to overwrite the progress message
146
			$this->output->writeln('');
147
			if (!$packageData['success']){
148
				$registry->set('feed', null);
149
				throw $packageData['exception'];
150
			}
151
	
152
			if ($action === 'download'){
153
				$output->writeln('Downloading has been completed. Exiting.');
154
				return 64;
155
			}
156
		} catch (ClientException $e){
157
			$this->getApplication()->getLogger()->error($e->getMessage());
0 ignored issues
show
It seems like you code against a specific sub-type and not the parent class Symfony\Component\Console\Application as the method getLogger() does only exist in the following sub-classes of Symfony\Component\Console\Application: Owncloud\Updater\Console\Application. Maybe you want to instanceof check for one of these explicitly?

Let’s take a look at an example:

abstract class User
{
    /** @return string */
    abstract public function getPassword();
}

class MyUser extends User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the parent class:

    abstract class User
    {
        /** @return string */
        abstract public function getPassword();
    
        /** @return string */
        abstract public function getDisplayName();
    }
    
Loading history...
158
			$output->writeln('<error>Network error</error>');
159
			$output->writeln(
160
					sprintf(
161
							'<error>Error %d: %s while fetching an URL %s</error>',
162
							$e->getCode(),
163
							$e->getResponse()->getReasonPhrase(),
164
							$e->getResponse()->getEffectiveUrl()
165
							)
166
			);
167
			return 2;
168
		} catch (\Exception $e){
169
			$this->getApplication()->getLogger()->error($e->getMessage());
0 ignored issues
show
It seems like you code against a specific sub-type and not the parent class Symfony\Component\Console\Application as the method getLogger() does only exist in the following sub-classes of Symfony\Component\Console\Application: Owncloud\Updater\Console\Application. Maybe you want to instanceof check for one of these explicitly?

Let’s take a look at an example:

abstract class User
{
    /** @return string */
    abstract public function getPassword();
}

class MyUser extends User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the parent class:

    abstract class User
    {
        /** @return string */
        abstract public function getPassword();
    
        /** @return string */
        abstract public function getDisplayName();
    }
    
Loading history...
170
			$output->writeln('<error>'.$e->getMessage().'</error>');
171
			return 2;
172
		}
173
174
		return 0;
175
	}
176
177
	/**
178
	 * Ask what to do
179
	 * @param InputInterface $input
180
	 * @param OutputInterface $output
181
	 * @return string
182
	 */
183
	public function ask(InputInterface $input, OutputInterface $output){
184
		$helper = $this->getHelper('question');
185
		$question = new ChoiceQuestion(
186
			'What would you do next?',
187
			['download', 'upgrade', 'abort'],
188
			'1'
189
		);
190
		$action = $helper->ask($input, $output, $question);
191
192
		return $action;
193
	}
194
195
	/**
196
	 * Callback to output download progress
197
	 * @param ProgressEvent $e
198
	 */
199
	public function progress(ProgressEvent $e){
200
		if ($e->downloadSize){
201
			$percent = intval(100 * $e->downloaded / $e->downloadSize );
202
			$percentString = $percent . '%';
203
			$this->output->write( 'Downloaded ' . $percentString . ' (' . $e->downloaded . ' of ' . $e->downloadSize . ")\r");
204
		}
205
	}
206
}
207