Issues (15)

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
101
        if (\PRODUCTION && self::$instances[$key] = \unserialize(\Cache::driver()->get($key, 'ActiveRecord.Metadata'))) {
102
            return self::$instances[$key];
103
        }
104
        
105
        $pdo = Db::get($database);
106
107
        $driverClass = __NAMESPACE__."\\".\ucfirst($pdo->getAttribute(\PDO::ATTR_DRIVER_NAME)).'Metadata';
108
109
        self::$instances[$key] = new $driverClass($pdo, $table, $schema);
110
111
        // Cachea los metadatos
112
        if (\PRODUCTION) {
113
            \Cache::driver()->save(
114
                \serialize(self::$instances[$key]),
115
                \Config::get('config.application.metadata_lifetime'),
116
                $key,
117
                'ActiveRecord.Metadata'
118
            );
119
        }
120
121
        return self::$instances[$key];
122
    }
123
124
    /**
125
     * Constructor.
126
     *
127
     * @param \PDO   $pdo      base de datos
128
     * @param string $table    tabla
129
     * @param string $schema   squema
130
     */
131
    private function __construct(\PDO $pdo, string $table, string $schema = '')
132
    {
133
        $this->fields     = $this->queryFields($pdo, $table, $schema);
134
        $this->fieldsList = \array_keys($this->fields);
0 ignored issues
show
Documentation Bug introduced by
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...
135
    }
136
137
    /**
138
     * Permite el filtrado de columna en PK, por Defecto y Autogenerado.
139
     *
140
     * @param array     $meta  informaciĆ³n de la columna
141
     * @param string    $field nombre      de la columna
142
     */
143
    protected function filterColumn(array $meta, string $field): void
144
    {
145
        if ($meta['Key'] === 'PRI') {
146
            $this->pk = $field;
147
        }
148
        if ($meta['Default']) {
149
            $this->withDefault[] = $field;
150
        }
151
        if ($meta['Auto']) {
152
            $this->autoFields[] = $field;
153
        }
154
    }
155
156
    /**
157
     * Consultar los campos de la tabla en la base de datos.
158
     *
159
     * @param  \PDO    $pdo      base de datos
160
     * @param  string  $table    tabla
161
     * @param  string  $schema   squema
162
     * 
163
     * @return array
164
     */
165
    abstract protected function queryFields(\PDO $pdo, string $table, string $schema = ''): array;
166
167
    /**
168
     * Obtiene la descripciĆ³n de los campos.
169
     *
170
     * @return string[]
171
     */
172
    public function getFields(): array
173
    {
174
        return $this->fields;
175
    }
176
177
    /**
178
     * Obtiene la lista de campos.
179
     *
180
     * @return string[]
181
     */
182
    public function getFieldsList(): array
183
    {
184
        return $this->fieldsList;
185
    }
186
187
    /**
188
     * Obtiene la clave primaria.
189
     *
190
     * @return string
191
     */
192
    public function getPK(): string
193
    {
194
        return $this->pk;
195
    }
196
197
    /**
198
     * Obtiene los campos con valor predeterminado.
199
     *
200
     * @return string[]
201
     */
202
    public function getWithDefault(): array
203
    {
204
        return $this->withDefault;
205
    }
206
207
    /**
208
     * Obtiene los campos con valor generado automatico.
209
     *
210
     * @return string[]
211
     */
212
    public function getAutoFields(): array
213
    {
214
        return $this->autoFields;
215
    }
216
}
217