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/Alcaeus/MongoDbAdapter/ExceptionConverter.php (4 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
 * 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
namespace Alcaeus\MongoDbAdapter;
17
18
use MongoDB\Driver\Exception;
19
use MongoDB\Driver\WriteError;
20
use MongoDB\Driver\WriteResult;
21
22
/**
23
 * @internal
24
 */
25
class ExceptionConverter
26
{
27
    /**
28
     * @param Exception\Exception $e
29
     * @param string $fallbackClass
30
     *
31
     * @return \MongoException
32
     */
33 33
    public static function toLegacy(Exception\Exception $e, $fallbackClass = 'MongoException')
34
    {
35
        // Starting with ext-mongodb 1.6.0, errors during bulk write are always wrapped in a BulkWriteException.
36
        // If a BulkWriteException wraps another driver exception, use that instead.
37 33
        if ($e instanceof Exception\BulkWriteException && $e->getPrevious() instanceof Exception\Exception) {
0 ignored issues
show
The class MongoDB\Driver\Exception\BulkWriteException does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
The class MongoDB\Driver\Exception\Exception does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
38 2
            $e = $e->getPrevious();
39
        }
40
41 33
        $message = $e->getMessage();
42 33
        $code = $e->getCode();
43
44 33
        switch (get_class($e)) {
45
            case Exception\AuthenticationException::class:
46
            case Exception\ConnectionException::class:
47
            case Exception\ConnectionTimeoutException::class:
48
            case Exception\SSLConnectionException::class:
49 9
                $class = 'MongoConnectionException';
50 9
                break;
51
52
            case Exception\BulkWriteException::class:
53
            case Exception\WriteException::class:
54 12
                $writeResult = $e->getWriteResult();
55
                // attempt to retrieve write error
56 12
                if ($writeResult instanceof WriteResult && is_array($writeResult->getWriteErrors()) && $writeResult->getWriteErrors() !== []) {
0 ignored issues
show
The class MongoDB\Driver\WriteResult does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
57 9
                    $writeError = $writeResult->getWriteErrors()[0];
58 9
                    if ($writeError instanceof WriteError) {
0 ignored issues
show
The class MongoDB\Driver\WriteError does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
59 9
                        $message = $writeError->getMessage();
60 9
                        $code = $writeError->getCode();
61
                    }
62
                }
63
64
                switch ($code) {
65
                    // see https://github.com/mongodb/mongo-php-driver-legacy/blob/ad3ed45739e9702ae48e53ddfadc482d9c4c7e1c/cursor_shared.c#L540
66 12
                    case 11000:
67 3
                    case 11001:
68 3
                    case 12582:
69 9
                        $class = 'MongoDuplicateKeyException';
70 9
                        break;
71
                    default:
72 3
                        $class = 'MongoCursorException';
73
                }
74 12
                break;
75
76
            case Exception\ExecutionTimeoutException::class:
77 1
                $class = 'MongoExecutionTimeoutException';
78 1
                break;
79
80
            default:
81 11
                $class = $fallbackClass;
82
        }
83
84 33
        if (strpos($message, 'No suitable servers found') !== false) {
85 3
            return new \MongoConnectionException($message, $code, $e);
86
        }
87
88 30
        if ($message === "cannot use 'w' > 1 when a host is not replicated") {
89 2
            return new \MongoWriteConcernException($message, $code, $e);
90
        }
91
92 28
        return new $class($message, $code, $e);
93
    }
94
95
    /**
96
     * Converts an exception to
97
     *
98
     * @param Exception\Exception $e
99
     * @return array
100
     */
101 4
    public static function toResultArray(Exception\Exception $e)
102
    {
103
        return [
104 4
            'ok' => 0.0,
105 4
            'errmsg' => $e->getMessage(),
106 4
            'code' => $e->getCode(),
107
        ];
108
    }
109
}
110