Issues (1131)

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/database/Database.class.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
namespace Agavi\Database;
3
4
// +---------------------------------------------------------------------------+
5
// | This file is part of the Agavi package.                                   |
6
// | Copyright (c) 2005-2011 the Agavi Project.                                |
7
// | Based on the Mojavi3 MVC Framework, Copyright (c) 2003-2005 Sean Kerr.    |
8
// |                                                                           |
9
// | For the full copyright and license information, please view the LICENSE   |
10
// | file that was distributed with this source code. You can also view the    |
11
// | LICENSE file online at http://www.agavi.org/LICENSE.txt                   |
12
// |   vi: set noexpandtab:                                                    |
13
// |   Local Variables:                                                        |
14
// |   indent-tabs-mode: t                                                     |
15
// |   End:                                                                    |
16
// +---------------------------------------------------------------------------+
17
18
use Agavi\Exception\DatabaseException;
19
use Agavi\Exception\InitializationException;
20
use Agavi\Util\ParameterHolder;
21
22
/**
23
 * AgaviDatabase is a base abstraction class that allows you to setup any type
24
 * of database connection via a configuration file.
25
 *
26
 * @package    agavi
27
 * @subpackage database
28
 *
29
 * @author     Sean Kerr <[email protected]>
30
 * @author     David Zülke <[email protected]>
31
 * @copyright  Authors
32
 * @copyright  The Agavi Project
33
 *
34
 * @since      0.9.0
35
 *
36
 * @version    $Id$
37
 */
38
abstract class Database extends ParameterHolder
39
{
40
    /**
41
     * @var        DatabaseManager An AgaviDatabaseManager instance.
42
     */
43
    protected $databaseManager = null;
44
    
45
    /**
46
     * @var        mixed A database connection.
47
     */
48
    protected $connection = null;
49
50
    /**
51
     * @var        string The name of the database.
52
     */
53
    private $name = null;
54
55
    /**
56
     * @var        mixed A database resource.
57
     */
58
    protected $resource = null;
59
60
    /**
61
     * Connect to the database.
62
     *
63
     * @throws     <b>AgaviDatabaseException</b> If a connection could not be
64
     *                                           created.
65
     *
66
     * @author     Sean Kerr <[email protected]>
67
     * @since      0.9.0
68
     */
69
    abstract protected function connect();
70
    
71
    /**
72
     * Retrieve the Database Manager instance for this implementation.
73
     *
74
     * @return     DatabaseManager A Database Manager instance.
75
     *
76
     * @author     David Zülke <[email protected]>
77
     * @since      0.11.0
78
     */
79
    public function getDatabaseManager()
80
    {
81
        return $this->databaseManager;
82
    }
83
84
    /**
85
     * Retrieve the name of this database connection.
86
     *
87
     * @return     string The name of the database.
88
     *
89
     * @author     David Zülke <[email protected]>
90
     * @since      0.11.0
91
     */
92
    public function getName()
93
    {
94
        return $this->name;
95
    }
96
    
97
    /**
98
     * Retrieve the database connection associated with this Database
99
     * implementation.
100
     *
101
     * When this is executed on a Database implementation that isn't an
102
     * abstraction layer, a copy of the resource will be returned.
103
     *
104
     * @return     mixed A database connection.
105
     *
106
     * @throws     DatabaseException If a connection could not be retrieved.
107
     *
108
     * @author     Sean Kerr <[email protected]>
109
     * @since      0.9.0
110
     */
111
    public function getConnection()
112
    {
113
        if ($this->connection === null) {
114
            $this->connect();
115
        }
116
117
        return $this->connection;
118
    }
119
120
    /**
121
     * Retrieve a raw database resource associated with this Database
122
     * implementation.
123
     *
124
     * @return     mixed A database resource.
125
     *
126
     * @throws     <b>AgaviDatabaseException</b> If no resource could be retrieved
127
     *
128
     * @author     Sean Kerr <[email protected]>
129
     * @since      0.9.0
130
     */
131
    public function getResource()
132
    {
133
        if ($this->resource === null) {
134
            $this->connect();
135
        }
136
137
        return $this->resource;
138
    }
139
140
    /**
141
     * Initialize this Database.
142
     *
143
     * @param      DatabaseManager $databaseManager The database manager of this instance.
144
     * @param      array           $parameters      An assoc array of initialization params.
145
     *
146
     * @throws     InitializationException If an error occurs while initializing this Database.
147
     *
148
     * @author     David Zülke <[email protected]>
149
     * @author     Sean Kerr <[email protected]>
150
     * @since      0.9.0
151
     */
152
    public function initialize(DatabaseManager $databaseManager, array $parameters = array())
153
    {
154
        $this->databaseManager = $databaseManager;
155
        
156
        $this->setParameters($parameters);
157
        
158
        $this->name = $databaseManager->getDatabaseName($this);
0 ignored issues
show
Documentation Bug introduced by
It seems like $databaseManager->getDatabaseName($this) can also be of type false or integer. However, the property $name is declared as type string. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
159
    }
160
161
    /**
162
     * Do any necessary startup work after initialization.
163
     *
164
     * This method is not called directly after initialize().
165
     * It is called during the startup() of the database manager.
166
     *
167
     * @author     David Zülke <[email protected]>
168
     * @since      0.11.0
169
     */
170
    public function startup()
171
    {
172
    }
173
174
    /**
175
     * Execute the shutdown procedure.
176
     *
177
     * @throws     <b>AgaviDatabaseException</b> If an error occurs while shutting
178
     *                                           down this database.
179
     *
180
     * @author     Sean Kerr <[email protected]>
181
     * @since      0.9.0
182
     */
183
    abstract public function shutdown();
184
}
185