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/Utils/ZipExtractor.php (1 issue)

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\Utils;
23
24
use Symfony\Component\Console\Output\OutputInterface;
25
use Symfony\Component\Process\Process;
26
use Symfony\Component\Process\ProcessUtils;
27
use ZipArchive;
28
29
/**
30
 * Class ZipExtractor
31
 *
32
 * @package Owncloud\Updater\Utils
33
 */
34
class ZipExtractor {
35
36
	protected $file;
37
	protected $path;
38
	
39
	/** @var  OutputInterface */
40
	protected $output;
41
42
	/**
43
	 * @param string $file
44
	 * @param string $path
45
	 * @param OutputInterface $output
46
	 */
47
	public function __construct($file, $path, OutputInterface $output = null){
48
		$this->file = $file;
49
		$this->path = $path;
50
		if (!is_null($output)){
51
			$this->output = $output;
52
		}
53
	}
54
55
	/**
56
	 * @return bool
57
	 */
58
	public function extract(){
59
		if ($this->extractShell()){
60
			return true;
61
		}
62
		if (!class_exists('ZipArchive')){
63
			throw new \RuntimeException("Could not decompress the archive, enable the PHP zip extension or install unzip.");
64
		}
65
		return $this->extractZipArchive();
66
	}
67
68
	/**
69
	 * @return bool
70
	 */
71
	private function extractShell(){
72
		$command = 'unzip ' . ProcessUtils::escapeArgument($this->file) . ' -d ' . ProcessUtils::escapeArgument($this->path) . ' && chmod -R u+w ' . ProcessUtils::escapeArgument($this->path);
0 ignored issues
show
Deprecated Code introduced by
The method Symfony\Component\Proces...Utils::escapeArgument() has been deprecated with message: since version 3.3, to be removed in 4.0. Use a command line array or give env vars to the `Process::start/run()` method instead.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
73
		$process = new Process($command);
74
		$process->setTimeout(null);
75
		$process->run();
76
		if ($this->output) {
77
			$this->output->writeln($process->getErrorOutput());
78
		}
79
		return $process->isSuccessful();
80
	}
81
82
	/**
83
	 * @return bool
84
	 */
85
	private function extractZipArchive(){
86
		$zipArchive = new ZipArchive();
87
88
		if (true !== ($exitCode = $zipArchive->open($this->file))){
89
			throw new \UnexpectedValueException($this->getErrorMessage($exitCode), $exitCode);
90
		}
91
92
		if (true !== $zipArchive->extractTo($this->path)){
93
			throw new \RuntimeException("There was an error extracting the ZIP file. Corrupt file?");
94
		}
95
96
		$zipArchive->close();
97
		return true;
98
	}
99
100
	/**
101
	 * @param int $exitCode
102
	 * @return string
103
	 */
104
	protected function getErrorMessage($exitCode){
105
		switch ($exitCode){
106
			case ZipArchive::ER_EXISTS:
107
				return sprintf("File '%s' already exists.", $this->file);
108
			case ZipArchive::ER_INCONS:
109
				return sprintf("Zip archive '%s' is inconsistent.", $this->file);
110
			case ZipArchive::ER_INVAL:
111
				return sprintf("Invalid argument (%s)", $this->file);
112
			case ZipArchive::ER_MEMORY:
113
				return sprintf("Malloc failure (%s)", $this->file);
114
			case ZipArchive::ER_NOENT:
115
				return sprintf("No such zip file: '%s'", $this->file);
116
			case ZipArchive::ER_NOZIP:
117
				return sprintf("'%s' is not a zip archive.", $this->file);
118
			case ZipArchive::ER_OPEN:
119
				return sprintf("Can't open zip file: %s", $this->file);
120
			case ZipArchive::ER_READ:
121
				return sprintf("Zip read error (%s)", $this->file);
122
			case ZipArchive::ER_SEEK:
123
				return sprintf("Zip seek error (%s)", $this->file);
124
			default:
125
				return sprintf("'%s' is not a valid zip archive, got error code: %s", $this->file, $exitCode);
126
		}
127
	}
128
}
129