Issues (220)

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.

Tests/ConnectionFactoryTest.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
namespace Doctrine\Bundle\DoctrineBundle\Tests;
4
5
use Doctrine\Bundle\DoctrineBundle\ConnectionFactory;
6
use Doctrine\DBAL\Connection;
7
use Doctrine\DBAL\Driver;
8
use Doctrine\DBAL\Exception\DriverException;
9
use Doctrine\DBAL\Platforms\AbstractPlatform;
10
use Doctrine\DBAL\Platforms\MySqlPlatform;
11
use Exception;
12
13
class ConnectionFactoryTest extends TestCase
14
{
15
    /**
16
     * @expectedException \Doctrine\DBAL\DBALException
17
     */
18
    public function testContainer() : void
19
    {
20
        $typesConfig  = [];
21
        $factory      = new ConnectionFactory($typesConfig);
22
        $params       = ['driverClass' => FakeDriver::class];
23
        $config       = null;
24
        $eventManager = null;
25
        $mappingTypes = [0];
26
        $exception    = new DriverException('', $this->createMock(Driver\AbstractDriverException::class));
0 ignored issues
show
$this->createMock(\Doctr...DriverException::class) is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Doctrine\DBAL\Driver\DriverException>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
27
28
        // put the mock into the fake driver
29
        FakeDriver::$exception = $exception;
30
31
        try {
32
            $factory->createConnection($params, $config, $eventManager, $mappingTypes);
33
        } catch (Exception $e) {
34
            $this->assertTrue(strpos($e->getMessage(), 'can circumvent this by setting') > 0);
35
            throw $e;
36
        } finally {
37
            FakeDriver::$exception = null;
38
        }
39
    }
40
41
    public function testDefaultCharset() : void
42
    {
43
        $factory = new ConnectionFactory([]);
44
        $params  = [
45
            'driverClass' => FakeDriver::class,
46
            'wrapperClass' => FakeConnection::class,
47
        ];
48
49
        $creationCount = FakeConnection::$creationCount;
50
        $connection    = $factory->createConnection($params);
51
52
        $this->assertInstanceof(FakeConnection::class, $connection);
53
        $this->assertSame('utf8', $connection->getParams()['charset']);
54
        $this->assertSame(1 + $creationCount, FakeConnection::$creationCount);
55
    }
56
57
    public function testDefaultCharsetMySql() : void
58
    {
59
        $factory = new ConnectionFactory([]);
60
        $params  = ['driver' => 'pdo_mysql'];
61
62
        $connection = $factory->createConnection($params);
63
64
        $this->assertSame('utf8mb4', $connection->getParams()['charset']);
65
    }
66
}
67
68
/**
69
 * FakeDriver class to simulate a problem discussed in DoctrineBundle issue #673
70
 * In order to not use a real database driver we have to create our own fake/mock implementation.
71
 *
72
 * @link https://github.com/doctrine/DoctrineBundle/issues/673
73
 */
74
class FakeDriver implements Driver
75
{
76
    /**
77
     * Exception Mock
78
     *
79
     * @var DriverException
80
     */
81
    public static $exception;
82
83
    /** @var AbstractPlatform|null */
84
    public static $platform;
85
86
    /**
87
     * This method gets called to determine the database version which in our case leeds to the problem.
88
     * So we have to fake the exception a driver would normally throw.
89
     *
90
     * @link https://github.com/doctrine/DoctrineBundle/issues/673
91
     */
92
    public function getDatabasePlatform() : AbstractPlatform
93
    {
94
        if (self::$exception !== null) {
95
            throw self::$exception;
96
        }
97
98
        return static::$platform ?? new MySqlPlatform();
99
    }
100
101
    // ----- below this line follow only dummy methods to satisfy the interface requirements ----
102
103
    /**
104
     * @param mixed[]     $params
105
     * @param string|null $username
106
     * @param string|null $password
107
     * @param mixed[]     $driverOptions
108
     */
109
    public function connect(array $params, $username = null, $password = null, array $driverOptions = []) : void
110
    {
111
        throw new Exception('not implemented');
112
    }
113
114
    public function getSchemaManager(Connection $conn) : void
115
    {
116
        throw new Exception('not implemented');
117
    }
118
119
    public function getName() : string
120
    {
121
        return 'FakeDriver';
122
    }
123
124
    public function getDatabase(Connection $conn) : string
125
    {
126
        return 'fake_db';
127
    }
128
}
129
130
class FakeConnection extends Connection
131
{
132
    /** @var int */
133
    public static $creationCount = 0;
134
135
    public function __construct(array $params, FakeDriver $driver, ?Configuration $config = null, ?EventManager $eventManager = null)
136
    {
137
        ++self::$creationCount;
138
139
        parent::__construct($params, $driver, $config, $eventManager);
140
    }
141
}
142