Issues (1919)

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/Ajde/Db/PDOStatement.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
 * @source http://www.coderholic.com/php-database-query-logging-with-pdo/
4
 * Modified for use with Ajde_Document_Processor_Html_Debugger
5
 */
6
7
/**
8
 * PDOStatement decorator that logs when a PDOStatement is
9
 * executed, and the time it took to run.
10
 */
11
class Ajde_Db_PDOStatement extends PDOStatement
12
{
13
    /**
14
     * @see http://www.php.net/manual/en/book.pdo.php#73568
15
     */
16
    public $dbh;
17
18
    protected function __construct($dbh)
19
    {
20
        $this->dbh = $dbh;
21
    }
22
23
    /**
24
     * When execute is called record the time it takes and
25
     * then log the query.
26
     *
27
     * @param array $input_parameters
28
     *
29
     * @throws Ajde_Db_Exception
30
     * @throws Ajde_Exception
31
     *
32
     * @return PDO result set
33
     */
34
    public function execute($input_parameters = null)
35
    {
36
        $log = ['query' => ''];
37
        if (config('app.debug') === true) {
38
            //$cache = Ajde_Db_Cache::getInstance();
39
            if (count($input_parameters)) {
40
                $log = ['query' => vsprintf(str_replace('?', '%s', $this->queryString), $input_parameters)];
41
            } else {
42
                $log = ['query' => '[PS] '.$this->queryString];
43
            }
44
            // add backtrace
45
            $i = 0;
46
            $source = [];
47
            foreach (array_reverse(debug_backtrace()) as $item) {
48
                try {
49
                    $line = issetor($item['line']);
0 ignored issues
show
Are you sure the assignment to $line is correct as issetor($item['line']) (which targets issetor()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
50
                    $file = issetor($item['file']);
0 ignored issues
show
Are you sure the assignment to $file is correct as issetor($item['file']) (which targets issetor()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
51
                    $source[] = sprintf('%s. <em>%s</em>%s<strong>%s</strong> (%s on line %s)',
52
                        $i,
53
                        !empty($item['class']) ? $item['class'] : '&lt;unknown class&gt;',
54
                        // Assume of no classname is available, dumped from template.. (naive)
55
                        !empty($item['type']) ? $item['type'] : '::',
56
                        !empty($item['function']) ? $item['function'] : '&lt;unknown function&gt;',
57
                        $file,
58
                        $line);
59
                } catch (Exception $e) {
60
                }
61
62
                $i++;
63
            }
64
            $hash = md5(implode('', $source).microtime());
65
66
            $log['query'] = '<a href="javascript:void(0)" onclick="$(\'#'.$hash.'\').slideToggle(\'fast\');" style="color: black;">'.$log['query'].'</a>';
67
            $log['query'] .= '<div id="'.$hash.'" style="display: none;">'.implode('<br/>', $source).'</div>';
68
        }
69
        // start timer
70
        $start = microtime(true);
71
        try {
72
            //if (!$cache->has($this->queryString . serialize($input_parameters))) {
73
            $result = parent::execute($input_parameters);
74
            //$cache->set($this->queryString . serialize($input_parameters), $result);
75
            //	$log['cache'] = false;
76
            //} else {
77
            //	$result = $cache->get($this->queryString . serialize($input_parameters));
78
            //	$log['cache'] = true;
79
            //}
80
        } catch (Exception $e) {
81
            if (substr_count(strtolower($e->getMessage()), 'integrity constraint violation')) {
82
                throw new Ajde_Db_IntegrityException($e->getMessage());
83 View Code Duplication
            } else {
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...
84
                if (config('app.debug') === true) {
85
                    if (isset($this->queryString)) {
86
                        dump($this->queryString);
87
                    }
88
                    dump('Go to '.config('app.rootUrl').'?install=1 to install DB');
89
                    throw new Ajde_Db_Exception($e->getMessage());
90
                } else {
91
                    Ajde_Exception_Log::logException($e);
0 ignored issues
show
$e is of type object<Exception>, but the function expects a object<Throwable>.

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...
92
                    die('DB connection problem. <a href="?install=1">Install database?</a>');
93
                }
94
            }
95
        }
96
        $time = microtime(true) - $start;
97
        $log['time'] = round($time * 1000, 0);
98
        Ajde_Db_PDO::$log[] = $log;
99
100
        return $result;
101
    }
102
103
    public static function getEmulatedSql($sql, $PDOValues)
104
    {
105
        // @see http://stackoverflow.com/questions/210564/pdo-prepared-statements/1376838#1376838
106
        $keys = [];
107
        $values = [];
108
        foreach ($PDOValues as $key => $value) {
109
            if (is_string($key)) {
110
                $keys[] = '/:'.$key.'/';
111
            } else {
112
                $keys[] = '/[?]/';
113
            }
114
            if (is_null($value)) {
115
                $values[] = 'NULL';
116
            } elseif (is_numeric($value)) {
117
                $values[] = intval($value);
118
            } elseif ($value instanceof Ajde_Db_Function) {
119
                $values[] = (string) $value;
120
            } else {
121
                $values[] = '"'.$value.'"';
122
            }
123
        }
124
        $query = preg_replace($keys, $values, $sql, -1, $count);
125
126
        return $query;
127
    }
128
}
129