Issues (183)

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.

system/sql.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
/**
4
 * Classe fornissant des fonctions de protection des injections SQL et d'autres fonctions liƩes aux requetes
5
 * @version 1.0
6
 * @deprecated use \FMUP\Db instead
7
 */
8
class Sql
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
9
{
10
    /**
11
     * ProtĆØge des injections SQL
12
     * @param {string} la chaƮne Ơ sƩcuriser
13
     *
14
     */
15
    public static function sanitize($value)
16
    {
17
        $value = preg_replace('@<script[^>]*?>.*?</script>@si', '[disabled]', $value);
18
        return str_replace('\'', '\'\'', $value);
19
    }
20
21
    /**
22
     * ProtĆØge des injections SQL (pour les requĆØtes)
23
     * @param {string} la chaƮne Ơ sƩcuriser
24
     **/
25
    public static function secure($value)
26
    {
27
        return "'" . Sql::sanitize($value) . "'";
28
    }
29
30
    /**
31
     * ProtĆØge des injections SQL pour les integers
32
     * @param {string} la chaƮne Ơ sƩcuriser
33
     **/
34
    public static function secureId($value)
35
    {
36
        if (Is::id($value)) {
37
            return $value;
38
        } else {
39
            return "null"; // entre guillements pour que ça devienne une requète SQL
40
        }
41
    }
42
43
    public static function secureListeId($value)
44
    {
45
        if ($value) {
46
            $values = explode(',', $value);
47
            $values = self::secureArray($values);
48
            return implode(',', $values);
49
        } else {
50
            return "0"; // entre guillements pour que ça devienne une requète SQL
51
        }
52
    }
53
54
    /**
55
     * ProtĆØge des injections SQL pour les integers
56
     * @param {string} la chaƮne Ơ sƩcuriser
57
     **/
58
    public static function secureInteger($value)
59
    {
60
        $value = strtr($value, ' ', '');
61
        if (Is::integer($value)) {
62
            return $value;
63
        } else {
64
            return "null"; // entre guillements pour que ça devienne une requète SQL
65
        }
66
    }
67
68
    /**
69
     * ProtĆØge des injections SQL pour les integers
70
     * @param {string} la chaƮne Ơ sƩcuriser
71
     **/
72
    public static function secureBoolean($value)
73
    {
74
        if (Is::integer($value)) {
75
            if ($value) {
76
                return "1";
77
            } else {
78
                return "0";
79
            }
80
        } else {
81
            return "0"; // entre guillements pour que ça devienne une requète SQL
82
        }
83
    }
84
85
    /**
86
     * Protège des injections décimales SQL en remplaçant les "," par des "."
87
     * @param {Decimal} le DƩcimal Ơ sƩcuriser
88
     **/
89
    public static function secureDecimal($value)
90
    {
91
        $value = str_replace(' ', '', $value);
92
        if (Is::decimal($value)) {
93
            return str_replace(",", ".", $value);
94
        } else {
95
            return "null";
96
        }
97
    }
98
99
    /**
100
     * Protège des injections de date SQL en remplaçant les "" par des null
101
     * @param {date} lea date Ơ sƩcuriser
102
     **/
103
    public static function secureDate($value)
104
    {
105
        if ($value instanceof \DateTime) {
106
            return '"' . $value->format('Y-m-d') . '"';
107
        }
108
        if (Is::dateTime($value) || Is::dateTimeUk($value)) {
109
            return "'" . $value . "'";
110
        } else {
111
            return "null";
112
        }
113
    }
114
115
    /**
116
     * ProtĆØge des injections SQL (pour les requĆØtes)
117
     * @param {Array} le tableau Ơ sƩcuriser
118
     **/
119
    public static function secureArray($values)
120
    {
121
        return array_map(array('Sql', 'secure'), $values);
122
    }
123
124
    public static function replaceXJoins($tabs, $orig_join, &$join = array())
125
    {
126
        foreach ($tabs as $tab) {
127
            if (!isset($join[$tab])) {
128
                if (isset($orig_join[$tab]['dep'])) {
129
                    self::replaceXJoins($orig_join[$tab]['dep'], $orig_join, $join);
130
                }
131
                if (isset($orig_join[$tab])) {
132
                    $join[$tab] = $orig_join[$tab]['join'];
133
                }
134
            }
135
        }
136
    }
137
138
    public static function replaceXFields($tab, $class = null, $option = array(), &$join = array())
139
    {
140
        if ($class) {
141
            $fields = call_user_func(array($class, 'xFields'), $option);
142
            $orig_fields = array_keys($fields);
143
            $dest_fields = array_values($fields);
144
            if (isset($option['x_joins'])) {
145
                $orig_join = call_user_func(array($class, 'xJoins'), $option);
146
            }
147
            foreach ($tab as $key => $value) {
148
                $tab[$key] = preg_replace($orig_fields, $dest_fields, trim($value));
149
                if (!empty($orig_join)) {
150
                    preg_match_all("/([[:alpha:]_]+)\./", $tab[$key], $out);
151
                    self::replaceXJoins($out[1], $orig_join, $join);
152
                }
153
            }
154
        }
155
156
        return $tab;
157
    }
158
159
    private static function filterWhere($i)
0 ignored issues
show
This method is not used, and could be removed.
Loading history...
160
    {
161
        return $i <> "";
162
    }
163
164
    /**
165
     * Convertit un tableau de conditions en un WHERE conditions
166
     * Le deuxiĆØme paramĆØtre permet de faire un HAVING Ć  la place
167
     * @uses self::filterWhere
168
     */
169
    public static function parseWhere($where, $having = false, $class = null, $option = array())
170
    {
171
        $where = self::replaceXFields($where, $class, $option);
172
173
        if (!is_array($where)) {
174
            throw new \FMUP\Exception(
175
                "Erreur Ơ l'utilisation de sqlParseWhere : tableau attendu. ReƧu : " . serialize($where)
176
            );
177
        }
178
179
        $where = array_filter($where, array('\Sql', 'filterWhere'));
180
        if ($where == array()) {
181
            return "";
182
        } else {
183
            if ($having) {
184
                $result = " HAVING ";
185
            } else {
186
                $result = " WHERE ";
187
            }
188
            foreach ($where as $condition) {
189
                if ($condition != '') {
190
                    $result .= '(' . $condition . ') ' . "\n" . 'AND ';
191
                }
192
            }
193
            // suppression du dernier AND
194
            $result = substr($result, 0, -5);
195
            return $result;
196
        }
197
    }
198
199
    /*     * ********
200
     * Filtres *
201
     * ******** */
202
203
    /**
204
     * Cette fonction crƩe un tableau de conditions LIKE Ơ partir d'un tableau
205
     */
206
    public static function conditionsFromArray($params)
207
    {
208
        $where = array();
209
        foreach ($params as $champ => $valeur) {
210
            if (0 === strpos($champ, 'id_') || $champ == 'id') {
211
                if ($valeur != '') {
212
                    $where[$champ] = "$champ = " . Sql::secureId($valeur);
213
                }
214
            } elseif (0 === strpos($champ, "date_")) {
215
                $where[$champ] = " CONVERT(VARCHAR, " . $champ . ", 103) LIKE '%"
216
                    . Sql::sanitize(trim($valeur)) . "%' ";
217
            } elseif (0 < strpos($champ, "chrono") && $valeur) {
218
                try {
219
                    $valeur = intval($valeur);
220
                } catch (Exception $e) {
221
                    $valeur = $valeur;
0 ignored issues
show
Why assign $valeur to itself?

This checks looks for cases where a variable has been assigned to itself.

This assignement can be removed without consequences.

Loading history...
222
                }
223 View Code Duplication
                if (0 === strpos($champ, 'equal_')) {
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...
224
                    $champ = substr($champ, 6);
225
                    $where[$champ] = "$champ LIKE '" . Sql::sanitize(trim($valeur)) . "'";
226
                } else {
227
                    $where[$champ] = "$champ LIKE '" . Sql::sanitize(trim($valeur)) . "%'";
228
                }
229
            } else {
230
                if ($valeur == "null") {
231
                    $where[$champ] = "$champ IS null";
232
                } elseif ($valeur == "IS NOT null") {
233
                    $where[$champ] = "$champ IS NOT null";
234 View Code Duplication
                } elseif ($valeur != '') {
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...
235
                    if (0 === strpos($champ, 'equal_')) {
236
                        $champ = substr($champ, 6);
237
                        $where[$champ] = "$champ = '" . Sql::sanitize(trim($valeur)) . "'";
238
                    } else {
239
                        $where[$champ] = "$champ LIKE '%" . Sql::sanitize(trim($valeur)) . "%'";
240
                    }
241
                }
242
            }
243
        }
244
        return $where;
245
    }
246
}
247