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/Controller/DownloadController.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
 * @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\Controller;
23
24
use Owncloud\Updater\Utils\Fetcher;
25
use Owncloud\Updater\Utils\Registry;
26
use Owncloud\Updater\Utils\FilesystemHelper;
27
28
/**
29
 * Class DownloadController
30
 *
31
 * @package Owncloud\Updater\Controller
32
 */
33
class DownloadController {
34
	
35
	/**
36
	 * @var Fetcher 
37
	 */
38
	protected $fetcher;
39
40
	/**
41
	 * @var Registry
42
	 */
43
	protected $registry;
44
45
	/**
46
	 * @var FilesystemHelper
47
	 */
48
	protected $fsHelper;
49
50
	/**
51
	 * DownloadController constructor.
52
	 *
53
	 * @param Fetcher $fetcher
54
	 * @param Registry $registry
55
	 * @param FilesystemHelper $fsHelper
56
	 */
57 4
	public function __construct(Fetcher $fetcher, Registry $registry, FilesystemHelper $fsHelper){
58 4
		$this->fetcher = $fetcher;
59 4
		$this->registry = $registry;
60 4
		$this->fsHelper = $fsHelper;
61 4
	}
62
63
	/**
64
	 * @return array
65
	 */
66 2
	public function checkFeed(){
67 2
		$response = $this->getDefaultResponse();
68
		try {
69 2
			$feed = $this->fetcher->getFeed();
70 1
			$response['success'] = true;
71 1
			$response['data']['feed'] = $feed;
72 1
		} catch (\Exception $e){
73 1
			$response['exception'] = $e;
74
		}
75
76 2
		return $response;
77
	}
78
79
	/**
80
	 * @param null $progressCallback
81
	 * @return array
82
	 */
83 2
	public function downloadOwncloud($progressCallback = null){
84 2
		$response = $this->getDefaultResponse();
85 2
		if (is_null($progressCallback)){
86
			$progressCallback = function (){};
87
		}
88
		try {
89 2
			$feed = $this->getFeed();
90 2
			$path = $this->fetcher->getBaseDownloadPath($feed);
91
			// Fixme: Daily channel has no checksum
92 2
			$isDailyChannel = $this->fetcher->getUpdateChannel() == 'daily';
93 2
			if (!$isDailyChannel){
94 2
				$md5 = $this->fetcher->getMd5($feed);
95
			} else {
96
				// We can't check md5 so we don't trust the cache
97
				$this->fsHelper->removeIfExists($path);
98
			}
99 2
			if ($isDailyChannel || !$this->checkIntegrity($path, $md5)){
0 ignored issues
show
The variable $md5 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...
100 1
				$this->fetcher->getOwncloud($feed, $progressCallback);
101
			}
102
103 1
			if ($isDailyChannel || $this->checkIntegrity($path, $md5)){
104 1
				$response['success'] = true;
105 1
				$response['data']['path'] = $path;
106
			} else {
107 1
				$response['exception'] = new \Exception('Deleted ' . $feed->getDownloadedFileName() . ' due to wrong checksum');
108
			}
109 1
		} catch (\Exception $e) {
110 1
			if (isset($path)){
111 1
				$this->fsHelper->removeIfExists($path);
112
			}
113 1
			$response['exception'] = $e;
114
		}
115 2
		return $response;
116
	}
117
118
	/**
119
	 * Check if package is not corrupted on download
120
	 * @param string $path
121
	 * @param string $md5
122
	 * @return boolean
123
	 */
124 2
	protected function checkIntegrity($path, $md5){
125 2
			$fileExists = $this->fsHelper->fileExists($path);
126 2
			$checksumMatch = $fileExists && $md5 === $this->fsHelper->md5File($path);
127 2
			if (!$checksumMatch){
128 1
				$this->fsHelper->removeIfExists($path);
129
			}
130 2
			return $checksumMatch;
131
	}
132
133
	/**
134
	 * Get a Feed instance
135
	 * @param bool $useCache
136
	 * @return \Owncloud\Updater\Utils\Feed
137
	 */
138 2
	protected function getFeed($useCache = true){
139 2
		if ($useCache && !is_null($this->registry->get('feed'))){
140 2
			return $this->registry->get('feed');
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $this->registry->get('feed'); (object|integer|double|string|array|boolean) is incompatible with the return type documented by Owncloud\Updater\Control...loadController::getFeed of type Owncloud\Updater\Utils\Feed.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
141
		}
142
		return $this->fetcher->getFeed();
143
	}
144
145
	/**
146
	 * Init response array
147
	 * @return array
148
	 */
149 4
	protected function getDefaultResponse(){
150
		return [
151 4
			'success' => false,
152
			'exception' => '',
153
			'details' => '',
154
			'data' => []
155
		];
156
	}
157
}
158