Issues (45)

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/Xhgui/Db/Mapper.php (5 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
class Xhgui_Db_Mapper
4
{
5
6
    /**
7
     * Convert request data keys into mongo values.
8
     *
9
     * @param array $options
10
     * @return array
11
     */
12
    public function convert($options)
13
    {
14
        $result = array(
15
            'conditions' => array(),
16
            'sort' => null,
17
            'direction' => null,
18
            'perPage' => 25
19
        );
20
        if (isset($options['conditions'])) {
21
            $result['conditions'] = $this->_conditions($options['conditions']);
22
        }
23
        $result['direction'] = $this->_direction($options);
24
        $result['sort'] = $this->_sort($options);
25
26
        if (isset($options['perPage'])) {
27
            $result['perPage'] = $options['perPage'];
28
        }
29
30
        return $result;
31
    }
32
33
    /**
34
     * Convert the search parameters into the matching fields.
35
     *
36
     * Keeps the schema details out of the GET parameters.
37
     * String casts are uses to prevent mongo operator injection.
38
     *
39
     * @param array $search
40
     * @return array
41
     */
42
    protected function _conditions($search)
43
    {
44 View Code Duplication
        if (!empty($search['limit_custom']) && $search['limit_custom'][0] == "P") {
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...
45
            $search['limit'] = $search['limit_custom'];
46
        }
47
        $hasLimit = (!empty($search['limit']) && $search['limit'] != -1);
48
49
        $conditions = array();
50 View Code Duplication
        if (!empty($search['date_start']) && !$hasLimit) {
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...
51
            $conditions['meta.request_date']['$gte'] = (string)$search['date_start'];
52
        }
53 View Code Duplication
        if (!empty($search['date_end']) && !$hasLimit) {
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...
54
            $conditions['meta.request_date']['$lte'] = (string)$search['date_end'];
55
        }
56
        if (isset($search['simple_url'])) {
57
            $conditions['meta.simple_url'] = (string)$search['simple_url'];
58
        }
59 View Code Duplication
        if (!empty($search['request_start'])) {
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...
60
            $conditions['meta.SERVER.REQUEST_TIME']['$gte'] = $this->_convertDate($search['request_start']);
61
        }
62 View Code Duplication
        if (!empty($search['request_end'])) {
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...
63
            $conditions['meta.SERVER.REQUEST_TIME']['$lte'] = $this->_convertDate($search['request_end']);
64
        }
65
66
        if (!empty($search['remote_addr'])) {
67
            $conditions['meta.SERVER.REMOTE_ADDR'] = (string)$search['remote_addr'];
68
        }
69
        if (isset($search['cookie'])) {
70
            $conditions['meta.SERVER.HTTP_COOKIE'] = (string)$search['cookie'];
71
        }
72
73
        if ($hasLimit && $search['limit'][0] == "P") {
74
            $date = new DateTime();
75
            try {
76
                $date->sub(new DateInterval($search['limit']));
77
                $conditions['meta.request_ts']['$gte'] = new MongoDate($date->getTimestamp());
78
            } catch (\Exception $e) {
79
                // Match a day in the future so we match nothing, as it's likely an invalid format
80
                $conditions['meta.request_ts']['$gte'] = new MongoDate(time() + 86400);
81
            }
82
        }
83
84
        if (isset($search['url'])) {
85
            // Not sure if letting people use regex here
86
            // is a good idea. Only one way to find out.
87
            $conditions['meta.url'] = array(
88
                '$regex' => (string)$search['url'],
89
                '$options' => 'i',
90
            );
91
        }
92
93
        return $conditions;
94
    }
95
96
    protected function _convertDate($dateString)
97
    {
98
        if (is_numeric($dateString)) {
99
            return (float) $dateString;
100
        }
101
        $date = DateTime::createFromFormat('Y-m-d H:i:s', $dateString);
102
        if (!$date) {
103
            return $date;
104
        }
105
        return $date->getTimestamp();
106
    }
107
108
    protected function _direction($options)
109
    {
110
        if (empty($options['direction'])) {
111
            return 'desc';
112
        }
113
        $valid = array('desc', 'asc');
114
        if (in_array($options['direction'], $valid, true)) {
115
            return $options['direction'];
116
        }
117
        return 'desc';
118
    }
119
    /**
120
     * Get sort options for a paginated set.
121
     *
122
     * Whitelists to valid known keys.
123
     *
124
     * @param array $options Pagination options including the sort key.
125
     * @return array Sort field & direction.
126
     */
127
    protected function _sort($options)
128
    {
129
        $direction = -1;
130
        if (isset($options['direction']) && $options['direction'] === 'asc') {
131
            $direction = 1;
132
        }
133
134
        $valid = array('time', 'wt', 'mu', 'cpu');
135
        if (
136
            empty($options['sort']) ||
137
            (isset($options['sort']) && !in_array($options['sort'], $valid))
138
        ) {
139
            return array('meta.SERVER.REQUEST_TIME' => $direction);
140
        }
141
        if ($options['sort'] == 'time') {
142
            return array('meta.SERVER.REQUEST_TIME' => $direction);
143
        } elseif ($options['sort'] == 'wt') {
144
            return array('profile.main().wt' => $direction);
145
        } elseif ($options['sort'] == 'mu') {
146
            return array('profile.main().mu' => $direction);
147
        } elseif ($options['sort'] == 'cpu') {
148
           return array('profile.main().cpu' => $direction);
149
        }
150
    }
151
152
}
153