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/config/DatabaseConfigHandler.class.php (2 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
// +---------------------------------------------------------------------------+
4
// | This file is part of the Agavi package.                                   |
5
// | Copyright (c) 2005-2011 the Agavi Project.                                |
6
// | Based on the Mojavi3 MVC Framework, Copyright (c) 2003-2005 Sean Kerr.    |
7
// |                                                                           |
8
// | For the full copyright and license information, please view the LICENSE   |
9
// | file that was distributed with this source code. You can also view the    |
10
// | LICENSE file online at http://www.agavi.org/LICENSE.txt                   |
11
// |   vi: set noexpandtab:                                                    |
12
// |   Local Variables:                                                        |
13
// |   indent-tabs-mode: t                                                     |
14
// |   End:                                                                    |
15
// +---------------------------------------------------------------------------+
16
17
namespace Agavi\Config;
18
19
use Agavi\Config\Util\Dom\XmlConfigDomDocument;
20
use Agavi\Config\Util\Dom\XmlConfigDomElement;
21
use Agavi\Exception\ConfigurationException;
22
use Agavi\Exception\ParseException;
23
24
/**
25
 * DatabaseConfigHandler allows you to setup database connections in a
26
 * configuration file that will be created for you automatically upon first
27
 * request.
28
 *
29
 * @package    agavi
30
 * @subpackage config
31
 *
32
 * @author     Sean Kerr <[email protected]>
33
 * @author     Dominik del Bondio <[email protected]>
34
 * @author     Noah Fontes <[email protected]>
35
 * @copyright  Authors
36
 * @copyright  The Agavi Project
37
 *
38
 * @since      0.9.0
39
 *
40
 * @version    $Id$
41
 */
42
class DatabaseConfigHandler extends XmlConfigHandler
43
{
44
    const XML_NAMESPACE = 'http://agavi.org/agavi/config/parts/databases/1.1';
45
    
46
    /**
47
     * Execute this configuration handler.
48
     *
49
     * @param      XmlConfigDomDocument $document The document to parse.
50
     *
51
     * @return     string Data to be written to a cache file.
52
     *
53
     * @throws     <b>ParseException</b> If a requested configuration file is
54
     *                                   improperly formatted.
55
     *
56
     * @author     Sean Kerr <[email protected]>
57
     * @author     Dominik del Bondio <[email protected]>
58
     * @author     Noah Fontes <[email protected]>
59
     * @since      0.9.0
60
     */
61
    public function execute(XmlConfigDomDocument $document)
62
    {
63
        // set up our default namespace
64
        $document->setDefaultNamespace(self::XML_NAMESPACE, 'databases');
65
        
66
        $databases = array();
67
        $default = null;
68
        foreach ($document->getConfigurationElements() as $configuration) {
69
            if (!$configuration->hasChildren('databases')) {
70
                continue;
71
            }
72
            
73
            $databasesElement = $configuration->getChild('databases');
74
            
75
            // make sure we have a default database exists
76
            if (!$databasesElement->hasAttribute('default') && $default === null) {
77
                // missing default database
78
                $error = 'Configuration file "%s" must specify a default database configuration';
79
                $error = sprintf($error, $document->documentURI);
80
81
                throw new ParseException($error);
82
            }
83
            if ($databasesElement->hasAttribute('default')) {
84
                $default = $databasesElement->getAttribute('default');
85
            }
86
87
            // let's do our fancy work
88
            /** @var XmlConfigDomElement $database */
89
            foreach ($configuration->get('databases') as $database) {
90
                $name = $database->getAttribute('name');
91
92
                if (!isset($databases[$name])) {
93
                    $databases[$name] = array('parameters' => array());
94
95
                    if (!$database->hasAttribute('class')) {
96
                        $error = 'Configuration file "%s" specifies database "%s" with missing class key';
97
                        $error = sprintf($error, $document->documentURI, $name);
98
99
                        throw new ParseException($error);
100
                    }
101
                }
102
103
                $databases[$name]['class'] = $database->hasAttribute('class') ? $database->getAttribute('class') : $databases[$name]['class'];
104
105
                $databases[$name]['parameters'] = $database->getAgaviParameters($databases[$name]['parameters']);
106
            }
107
        }
108
109
        if (!$databases) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $databases of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
110
            // we have no connections
111
            $error = 'Configuration file "%s" does not contain any database connections.';
112
            $error = sprintf($error, $document->documentURI);
113
            throw new ConfigurationException($error);
114
        }
115
116
        $data = array();
117
118
        foreach ($databases as $name => $db) {
119
            // append new data
120
            $data[] = sprintf('$database = new %s();', $db['class']);
121
            $data[] = sprintf('$this->databases[%s] = $database;', var_export($name, true));
122
            $data[] = sprintf('$database->initialize($this, %s);', var_export($db['parameters'], true));
123
        }
124
125 View Code Duplication
        if (!isset($databases[$default])) {
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
126
            $error = 'Configuration file "%s" specifies undefined default database "%s".';
127
            $error = sprintf($error, $document->documentURI, $default);
128
            throw new ConfigurationException($error);
129
        }
130
131
        $data[] = sprintf('$this->defaultDatabaseName = %s;', var_export($default, true));
132
133
        return $this->generate($data, $document->documentURI);
134
    }
135
}
136