Issues (273)

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/Debug/DatabaseDataCollector.php (1 issue)

Severity

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 file contains a data collector for the profiler
4
 *
5
 * @license    https://github.com/allejo/bzion/blob/master/LICENSE.md GNU General Public License Version 3
6
 */
7
8
namespace BZIon\Debug;
9
10
use Symfony\Component\HttpFoundation\Request;
11
use Symfony\Component\HttpFoundation\Response;
12
use Symfony\Component\HttpKernel\DataCollector\DataCollectorInterface;
13
14
/**
15
 * A data collector that collects database data that will be shown on the
16
 * profiler
17
 */
18
class DatabaseDataCollector implements DataCollectorInterface
19
{
20
    public $data;
21
    protected $queries = array();
22
    protected $cacheFetches = array();
23
24
    /**
25
     * Collects data for the given Request and Response, so that it can be
26
     * serialized and stored for later retrieval
27
     *
28
     * @param Request    $request   A Request instance
29
     * @param Response   $response  A Response instance
30
     * @param \Exception $exception An Exception instance
31
     */
32
    public function collect(Request $request, Response $response, \Exception $exception = null)
33
    {
34
        $this->data = array(
35
            'queries'      => $this->queries,
36
            'cachedModels' => \Service::getModelCache()->all(),
37
            'cacheFetches' => $this->cacheFetches
38
        );
39
    }
40
41
    /**
42
     * Log a database query
43
     *
44
     * @param DatabaseQuery $query The query
45
     */
46
    public function logQuery($query)
47
    {
48
        $this->queries[] = $query;
49
    }
50
51
    /**
52
     * Log a fetch from the Model Cache
53
     *
54
     * @param string $type The type of the model
55
     * @param int    $id   The ID of the model
56
     */
57
    public function logCacheFetch($type, $id)
0 ignored issues
show
The parameter $id is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
58
    {
59
        if (isset($this->cacheFetches[$type])) {
60
            ++$this->cacheFetches[$type];
61
        } else {
62
            $this->cacheFetches[$type] = 1;
63
        }
64
    }
65
66
    /**
67
     * Get the sorted catche fetches by Model type
68
     *
69
     * @return array
70
     */
71
    public function getCacheFetches()
72
    {
73
        arsort($this->data['cacheFetches']);
74
        return $this->data['cacheFetches'];
75
    }
76
77
    /**
78
     * Get the total number of catche fetches
79
     *
80
     * @return int
81
     */
82
    public function getTotalCacheFetches()
83
    {
84
        return array_sum($this->data['cacheFetches']);
85
    }
86
87
    /**
88
     * Get an estimate of the time that the model cache saved in milliseconds
89
     *
90
     * @return number
91
     */
92
    public function estimateTimeSaved()
93
    {
94
        $sum = 0;
95
        $count = 0;
96
97
        foreach ($this->data['queries'] as $query) {
98
            if (0 === strpos(trim($query->getQuery()), 'SELECT *')) {
99
                $sum += $query->getDuration();
100
                ++$count;
101
            }
102
        }
103
104
        if ($count == 0) {
105
            return 0;
106
        } else {
107
            return array_sum($this->data['cacheFetches']) * $sum / $count / 1000;
108
        }
109
    }
110
111
    /**
112
     * Get the number of times each query was sent to the server
113
     *
114
     * @return array An array with resolved queries as keys and frequencies as values
115
     */
116
    public function getQueryFrequencies()
117
    {
118
        $return = array();
119
120
        foreach ($this->data['queries'] as $query) {
121
            $resolved = $query->getResolvedQuery();
122
123
            if (!isset($return[$resolved])) {
124
                $return[$resolved] = 1;
125
            } else {
126
                ++$return[$resolved];
127
            }
128
        }
129
130
        return $return;
131
    }
132
133
    /**
134
     * Get the number of duplicated queries
135
     *
136
     * @return int
137
     */
138
    public function getDuplicatedQueryCount()
139
    {
140
        $frequencies = $this->getQueryFrequencies();
141
142
        return array_sum($frequencies) - count($frequencies);
143
    }
144
145
    /**
146
     * Get the queries made to the database
147
     *
148
     * @return DatabaseQuery[]
149
     */
150
    public function getQueries()
151
    {
152
        return $this->data['queries'];
153
    }
154
155
    /**
156
     * Get the total duration of the database queries in milliseconds
157
     *
158
     * @return float
159
     */
160
    public function getDuration()
161
    {
162
        $sum = 0;
163
164
        foreach ($this->data['queries'] as $query) {
165
            $sum += $query->getDuration();
166
        }
167
168
        return $sum / 1000;
169
    }
170
171
    /**
172
     * Returns the name of the collector.
173
     *
174
     * @return string The collector name
175
     */
176 2
    public function getName()
177
    {
178 2
        return 'database';
179
    }
180
}
181