Issues (16)

Security Analysis    no request data  

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.

Metadata/Metadata.php (1 issue)

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
 * KumbiaPHP web & app Framework.
5
 *
6
 * LICENSE
7
 *
8
 * This source file is subject to the new BSD license that is bundled
9
 * with this package in the file LICENSE.txt.
10
 * It is also available through the world-wide-web at this URL:
11
 * http://wiki.kumbiaphp.com/Licencia
12
 * If you did not receive a copy of the license and are unable to
13
 * obtain it through the world-wide-web, please send an email
14
 * to [email protected] so we can send you a copy immediately.
15
 *
16
 * @category   Kumbia
17
 *
18
 * @copyright  2005 - 2020  Kumbia Team (http://www.kumbiaphp.com)
19
 * @license    http://wiki.kumbiaphp.com/Licencia     New BSD License
20
 */
21
namespace Kumbia\ActiveRecord\Metadata;
22
23
use Kumbia\ActiveRecord\Db;
24
25
/**
26
 * Metadata de tabla.
27
 */
28
abstract class Metadata
29
{
30
    /**
31
     * Singleton de metadata.
32
     *
33
     * @var self[]
34
     */
35
    private static $instances = [];
36
37
    /**
38
     * Descripción de los campos.
39
     *
40
     * @var array
41
     */
42
    protected $fields = [];
43
44
    /**
45
     * Lista de campos.
46
     *
47
     * @var string[]
48
     */
49
    protected $fieldsList = [];
50
51
    /**
52
     * Clave primaria.
53
     *
54
     * @var string
55
     */
56
    protected $pk;
57
58
    /**
59
     * Campos con valor predeterminado.
60
     *
61
     * @var string[]
62
     */
63
    protected $withDefault = [];
64
65
    /**
66
     * Campos con valor autogenerado.
67
     *
68
     * @var string[]
69
     */
70
    protected $autoFields = [];
71
72
    /**
73
     * Metadata de la tabla.
74
     *
75
     * @param  string     $database
76
     * @param  string     $table
77
     * @param  string     $schema
78
     * 
79
     * @return self
80
     */
81
    public static function get(string $database, string $table, string $schema = ''): self
82
    {
83
        return self::$instances["$database.$table.$schema"] ?? self::getMetadata($database, $table, $schema);
84
    }
85
86
    /**
87
     * Obtiene la metadata de la tabla
88
     * Y la cachea si esta en producción.
89
     *
90
     * @param  string     $database
91
     * @param  string     $table
92
     * @param  string     $schema
93
     * 
94
     * @return self
95
     */
96
    private static function getMetadata(string $database, string $table, string $schema): self
97
    {
98
        $key = "$database.$table.$schema";
99
        //TODO añadir cache propia
100
        if (\PRODUCTION && ! (self::$instances[$key] = \Cache::driver()->get($key, 'ActiveRecord.Metadata'))) {
101
            return self::$instances[$key];
102
        }
103
        
104
        $pdo = Db::get($database);
105
106
        $driverClass = __NAMESPACE__."\\".\ucfirst($pdo->getAttribute(\PDO::ATTR_DRIVER_NAME)).'Metadata';
107
108
        self::$instances[$key] = new $driverClass($pdo, $table, $schema);
109
110
        // Cachea los metadatos
111
        if (\PRODUCTION) {
112
            \Cache::driver()->save(
113
                self::$instances[$key],
114
                \Config::get('config.application.metadata_lifetime'),
115
                $key,
116
                'ActiveRecord.Metadata'
117
            );
118
        }
119
120
        return self::$instances[$key];
121
    }
122
123
    /**
124
     * Constructor.
125
     *
126
     * @param \PDO   $pdo      base de datos
127
     * @param string $table    tabla
128
     * @param string $schema   squema
129
     */
130
    private function __construct(\PDO $pdo, string $table, string $schema = '')
131
    {
132
        $this->fields     = $this->queryFields($pdo, $table, $schema);
133
        $this->fieldsList = \array_keys($this->fields);
0 ignored issues
show
Documentation Bug introduced by manuel_j555
It seems like \array_keys($this->fields) of type array<integer,integer|string> is incompatible with the declared type array<integer,string> of property $fieldsList.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
134
    }
135
136
    /**
137
     * Permite el filtrado de columna en PK, por Defecto y Autogenerado.
138
     *
139
     * @param array     $meta  información de la columna
140
     * @param string    $field nombre      de la columna
141
     */
142
    protected function filterColumn(array $meta, string $field): void
143
    {
144
        if ($meta['Key'] === 'PRI') {
145
            $this->pk = $field;
146
        }
147
        if ($meta['Default']) {
148
            $this->withDefault[] = $field;
149
        }
150
        if ($meta['Auto']) {
151
            $this->autoFields[] = $field;
152
        }
153
    }
154
155
    /**
156
     * Consultar los campos de la tabla en la base de datos.
157
     *
158
     * @param  \PDO    $pdo      base de datos
159
     * @param  string  $table    tabla
160
     * @param  string  $schema   squema
161
     * 
162
     * @return array
163
     */
164
    abstract protected function queryFields(\PDO $pdo, string $table, string $schema = ''): array;
165
166
    /**
167
     * Obtiene la descripción de los campos.
168
     *
169
     * @return string[]
170
     */
171
    public function getFields(): array
172
    {
173
        return $this->fields;
174
    }
175
176
    /**
177
     * Obtiene la lista de campos.
178
     *
179
     * @return string[]
180
     */
181
    public function getFieldsList(): array
182
    {
183
        return $this->fieldsList;
184
    }
185
186
    /**
187
     * Obtiene la clave primaria.
188
     *
189
     * @return string
190
     */
191
    public function getPK(): string
192
    {
193
        return $this->pk;
194
    }
195
196
    /**
197
     * Obtiene los campos con valor predeterminado.
198
     *
199
     * @return string[]
200
     */
201
    public function getWithDefault(): array
202
    {
203
        return $this->withDefault;
204
    }
205
206
    /**
207
     * Obtiene los campos con valor generado automatico.
208
     *
209
     * @return string[]
210
     */
211
    public function getAutoFields(): array
212
    {
213
        return $this->autoFields;
214
    }
215
}
216