Issues (61)

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.

lib/Mongo/MongoCommandCursor.php (3 issues)

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
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
4
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
5
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
6
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
7
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
8
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
9
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
10
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
11
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
12
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
13
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
14
 */
15
16
if (class_exists('MongoCommandCursor', false)) {
17
    return;
18
}
19
20
use Alcaeus\MongoDbAdapter\AbstractCursor;
21
use Alcaeus\MongoDbAdapter\TypeConverter;
22
23
class MongoCommandCursor extends AbstractCursor implements MongoCursorInterface
24
{
25
    /**
26
     * @var array
27
     */
28
    private $command;
29
30
    /**
31
     * MongoCommandCursor constructor.
32
     * @param MongoClient $connection
33
     * @param string $ns
34
     * @param array $command
35
     */
36
    public function __construct(MongoClient $connection, $ns, array $command = [])
37
    {
38
        parent::__construct($connection, $ns);
39
40
        $this->command = $command;
41
    }
42
43
    /**
44
     * @param MongoClient $connection
45
     * @param string $hash
46
     * @param array $document
47
     * @return MongoCommandCursor
48
     */
49
    public static function createFromDocument(MongoClient $connection, $hash, array $document)
0 ignored issues
show
The parameter $connection 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...
The parameter $hash 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...
The parameter $document 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...
50
    {
51
        throw new \Exception('Not implemented');
52
    }
53
54
    /**
55
     * @return \MongoDB\Driver\Cursor
56
     */
57
    protected function ensureCursor()
58
    {
59
        if ($this->cursor === null) {
60
            $convertedCommand = TypeConverter::fromLegacy($this->command);
61
            if (isset($convertedCommand->cursor)) {
62
                if ($convertedCommand->cursor === true || $convertedCommand->cursor === []) {
63
                    $convertedCommand->cursor = new \stdClass();
64
                }
65
            }
66
67
            $originalReadPreference = null;
68
            if (!$this->supportsReadPreference()) {
69
                $originalReadPreference = $this->readPreference;
70
                $this->setReadPreference(\MongoClient::RP_PRIMARY);
71
            }
72
73
            try {
74
                $this->cursor = $this->db->command($convertedCommand, $this->getOptions());
75
            } finally {
76
                if ($originalReadPreference) {
77
                    $this->readPreference = $originalReadPreference;
78
                }
79
            }
80
        }
81
82
        return $this->cursor;
83
    }
84
85
    /**
86
     * @return array
87
     */
88
    protected function getCursorInfo()
89
    {
90
        return [
91
            'ns' => $this->ns,
92
            'limit' => 0,
93
            'batchSize' => $this->batchSize,
94
            'skip' => 0,
95
            'flags' => 0,
96
            'query' => $this->command,
97
            'fields' => null,
98
        ];
99
    }
100
101
    /**
102
     * @return array
103
     */
104
    protected function getIterationInfo()
105
    {
106
        $iterationInfo = parent::getIterationInfo();
107
108
        if ($iterationInfo['started_iterating']) {
109
            $iterationInfo += [
110
                'firstBatchAt' => $iterationInfo['at'],
111
                'firstBatchNumReturned' => $iterationInfo['numReturned'],
112
            ];
113
            $iterationInfo['at'] = 0;
114
            $iterationInfo['numReturned'] = 0;
115
        }
116
117
        return $iterationInfo;
118
    }
119
120
    /**
121
     * @return array
122
     */
123
    public function __sleep()
124
    {
125
        return ['command'] + parent::__sleep();
126
    }
127
128
    /**
129
     * @see https://github.com/mongodb/mongo-php-driver-legacy/blob/1.6.14/db.c#L51
130
     * @return bool
131
     */
132
    private function supportsReadPreference()
133
    {
134
        if ($this->command === []) {
135
            return false;
136
        }
137
138
        $firstKey = array_keys($this->command)[0];
139
        switch ($firstKey) {
140
            case 'count':
141
            case 'group':
142
            case 'dbStats':
143
            case 'geoNear':
144
            case 'geoWalk':
145
            case 'distinct':
146
            case 'aggregate':
147
            case 'collStats':
148
            case 'geoSearch':
149
            case 'parallelCollectionScan':
150
                return true;
151
152
            case 'mapreduce':
153
            case 'mapReduce':
154
                return (isset($this->command['out']) &&
155
                    is_array($this->command['out']) &&
156
                    array_key_exists('inline', $this->command['out']));
157
158
            default:
159
                return false;
160
        }
161
    }
162
}
163