Issues (28)

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.

src/Command.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
/**
4
 * This software package is licensed under AGPL or Commercial license.
5
 *
6
 * @package maslosoft/mangan
7
 * @licence AGPL or Commercial
8
 * @copyright Copyright (c) Piotr MaseÅ‚kowski <[email protected]>
9
 * @copyright Copyright (c) Maslosoft
10
 * @copyright Copyright (c) Others as mentioned in code
11
 * @link https://maslosoft.com/mangan/
12
 */
13
14
namespace Maslosoft\Mangan;
15
16
use Maslosoft\Addendum\Interfaces\AnnotatedInterface;
17
use Maslosoft\Mangan\Exceptions\CommandException;
18
use Maslosoft\Mangan\Exceptions\CommandNotFoundException;
19
use Maslosoft\Mangan\Helpers\CollectionNamer;
20
use Maslosoft\Mangan\Model\Command\User;
21
use Maslosoft\Mangan\Traits\AvailableCommands;
22
23
/**
24
 * Command
25
 *
26
 * @author Piotr Maselkowski <pmaselkowski at gmail.com>
27
 */
28
class Command
29
{
30
31
	use AvailableCommands;
32
33
	/**
34
	 * @var AnnotatedInterface
35
	 */
36
	private $model;
37
38
	/**
39
	 * @var Mangan
40
	 */
41
	private $mn;
42
43
	/**
44
	 * @var string 
45
	 */
46
	private $collection;
47
48 13
	public function __construct(AnnotatedInterface $model = null, Mangan $mangan = null)
49
	{
50 13
		$this->model = $model;
51 13
		if ($mangan !== null)
52
		{
53 8
			$this->mn = $mangan;
54
		}
55 13
		if ($model === null)
56
		{
57 4
			$this->mn = Mangan::fly();
58 4
			return;
59
		}
60 9
		$this->mn = Mangan::fromModel($model);
61 9
		$this->collection = CollectionNamer::nameCollection($model);
62 9
	}
63
64 2
	public function call($command, $arguments = [])
65
	{
66 2
		$arg = $this->model ? CollectionNamer::nameCollection($this->model) : true;
67 2
		$cmd = [$command => $arg];
68 2
		if (is_array($arguments) && count($arguments))
69
		{
70
			$cmd = array_merge($cmd, $arguments);
71
		}
72 2
		$result = $this->mn->getDbInstance()->command($cmd);
73
74 2
		if (array_key_exists('errmsg', $result) && array_key_exists('ok', $result) && $result['ok'] == 0)
75
		{
76
			if (array_key_exists('bad cmd', $result))
77
			{
78
				$badCmd = key($result['bad cmd']);
79
				if ($badCmd == $command)
80
				{
81
					throw new CommandNotFoundException(sprintf('Command `%s` not found', $command));
82
				}
83
			}
84
			elseif (strpos($result['errmsg'], 'no such command') !== false)
85
			{
86
				throw new CommandNotFoundException(sprintf('Command `%s` not found', $command));
87
			}
88
			throw new CommandException(sprintf('Could not execute command `%s`, mongo returned: "%s"', $command, $result['errmsg']));
89
		}
90 2
		return $result;
91
	}
92
93
	public function __call($name, $arguments)
94
	{
95
		if (count($arguments))
96
		{
97
			return $this->call($name, $arguments[0]);
98
		}
99
		return $this->call($name);
100
	}
101
102
	/**
103
	 * Explicitly creates a collection or view.
104
	 *
105
	 * Parameter `$params` depends on MongoDB version,
106
	 * see (official documentation)[https://docs.mongodb.com/manual/reference/command/create/] for details
107
	 *
108
	 * @param string $collectionName The name of the new collection
109
	 * @param array $params
110
	 * @return array
111
	 */
112 1
	public function create($collectionName, $params = [])
113
	{
114
		$cmd = [
115 1
			'create' => $collectionName
116
		];
117 1
		return $this->mn->getDbInstance()->command(array_merge($cmd, $params));
118
	}
119
120 2
	public function createUser(User $user, $writeConcerns = [])
0 ignored issues
show
The parameter $writeConcerns is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
121
	{
122
		$cmd = [
123 2
			'createUser' => $user->user,
124 2
			'pwd' => $user->pwd,
125
		];
126 2
		if (!empty($user->customData))
127
		{
128
			assert(is_object($user->customData));
129
			$cmd['customData'] = $user->customData;
130
		}
131 2
		$cmd = array_merge($cmd, $user->toArray(['user', 'customData']));
132 2
		return $this->mn->getDbInstance()->command($cmd);
133
	}
134
135 2
	public function dropUser($username, $writeConcerns = [])
136
	{
137 2
		if ($username instanceof User)
138
		{
139 2
			$username = $username->user;
140
		}
141
		$cmd = [
142 2
			'dropUser' => $username
143
		];
144 2
		return $this->mn->getDbInstance()->command(array_merge($cmd, $writeConcerns));
145
	}
146
147 8
	public function createIndex($keys, $options = [])
148
	{
149
		// Ensure array
150 8
		if(empty($options))
151
		{
152 7
			$options = [];
153
		}
154 8
		return $this->mn->getDbInstance()->selectCollection($this->collection)->createIndex($keys, $options);
155
	}
156
157
	/**
158
	 * NOTE: This is broken
159
	 * @return array
160
	 * @throws Exceptions\ManganException
161
	 */
162
	public function getIndexes()
163
	{
164
		return $this->mn->getDbInstance()->selectCollection($this->collection)->getIndexInfo();
165
	}
166
167
	/**
168
	 * The `collStats` command returns a variety of storage statistics for a given collection.
169
	 *
170
	 * @param string $collectionName The name of the target collection. If the collection does not exist, collStats returns an error message.
171
	 * @param int $scale Optional. The scale used in the output to display the sizes of items. By default, output displays sizes in bytes. To display kilobytes rather than bytes, specify a scale value of 1024. The scale factor rounds values to whole numbers.
172
	 * @param boolean $verbose Optional. When true, collStats increases reporting for the MMAPv1 Storage Engine. Defaults to false.
173
	 * @return array
174
	 */
175 9
	public function collStats($collectionName, $scale = 1, $verbose = false)
176
	{
177
		$cmd = [
178 9
			'collStats' => $collectionName,
179 9
			'scale' => $scale,
180 9
			'verbose' => $verbose
181
		];
182 9
		return $this->mn->getDbInstance()->command($cmd);
183
	}
184
185
}
186