Issues (3948)

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.

app/Foundation/Csv.php (1 issue)

Labels
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
/*
4
 * This file is part of Jitamin.
5
 *
6
 * Copyright (C) Jitamin Team
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Jitamin\Foundation;
13
14
use SplFileObject;
15
16
/**
17
 * CSV Writer/Reader.
18
 */
19
class Csv
20
{
21
    /**
22
     * CSV delimiter.
23
     *
24
     * @var string
25
     */
26
    private $delimiter = ',';
27
28
    /**
29
     * CSV enclosure.
30
     *
31
     * @var string
32
     */
33
    private $enclosure = '"';
34
35
    /**
36
     * CSV/SQL columns.
37
     *
38
     * @var array
39
     */
40
    private $columns = [];
41
42
    /**
43
     * Constructor.
44
     *
45
     * @param string $delimiter
46
     * @param string $enclosure
47
     */
48
    public function __construct($delimiter = ',', $enclosure = '"')
49
    {
50
        $this->delimiter = $delimiter;
51
        $this->enclosure = $enclosure;
52
    }
53
54
    /**
55
     * Get list of delimiters.
56
     *
57
     * @static
58
     *
59
     * @return array
60
     */
61
    public static function getDelimiters()
62
    {
63
        return [
64
            ','  => t('Comma'),
65
            ';'  => t('Semi-colon'),
66
            '\t' => t('Tab'),
67
            '|'  => t('Vertical bar'),
68
        ];
69
    }
70
71
    /**
72
     * Get list of enclosures.
73
     *
74
     * @static
75
     *
76
     * @return array
77
     */
78
    public static function getEnclosures()
79
    {
80
        return [
81
            '"' => t('Double Quote'),
82
            "'" => t('Single Quote'),
83
            ''  => t('None'),
84
        ];
85
    }
86
87
    /**
88
     * Check boolean field value.
89
     *
90
     * @static
91
     *
92
     * @param mixed $value
93
     *
94
     * @return int
95
     */
96
    public static function getBooleanValue($value)
97
    {
98
        if (!empty($value)) {
99
            $value = trim(strtolower($value));
100
101
            return $value === '1' || $value[0]
102
            === 't' || $value[0]
103
            === 'y' ? 1 : 0;
104
        }
105
106
        return 0;
107
    }
108
109
    /**
110
     * Output CSV file to standard output.
111
     *
112
     * @static
113
     *
114
     * @param array $rows
115
     */
116
    public static function output(array $rows)
117
    {
118
        $csv = new static();
119
        $csv->write('php://output', $rows);
120
    }
121
122
    /**
123
     * Define column mapping between CSV and SQL columns.
124
     *
125
     * @param array $columns
126
     *
127
     * @return Csv
128
     */
129
    public function setColumnMapping(array $columns)
130
    {
131
        $this->columns = $columns;
132
133
        return $this;
134
    }
135
136
    /**
137
     * Read CSV file.
138
     *
139
     * @param string   $filename
140
     * @param callable $callback Example: function(array $row, $line_number)
141
     *
142
     * @return Csv
143
     */
144
    public function read($filename, $callback)
145
    {
146
        $file = new SplFileObject($filename);
147
        $file->setFlags(SplFileObject::READ_CSV);
148
        $file->setCsvControl($this->delimiter, $this->enclosure);
149
        $line_number = 0;
150
151
        foreach ($file as $row) {
152
            $row = $this->filterRow($row);
0 ignored issues
show
It seems like $row can also be of type string; however, Jitamin\Foundation\Csv::filterRow() does only seem to accept array, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
153
154
            if (!empty($row) && $line_number > 0) {
155
                call_user_func_array($callback, [$this->associateColumns($row), $line_number]);
156
            }
157
158
            $line_number++;
159
        }
160
161
        return $this;
162
    }
163
164
    /**
165
     * Write CSV file.
166
     *
167
     * @param string $filename
168
     * @param array  $rows
169
     *
170
     * @return Csv
171
     */
172
    public function write($filename, array $rows)
173
    {
174
        $fp = fopen($filename, 'w');
175
176
        if (is_resource($fp)) {
177
            foreach ($rows as $row) {
178
                fputcsv($fp, $row, $this->delimiter, $this->enclosure);
179
            }
180
181
            fclose($fp);
182
        }
183
184
        return $this;
185
    }
186
187
    /**
188
     * Associate columns header with row values.
189
     *
190
     * @param array $row
191
     *
192
     * @return array
193
     */
194
    private function associateColumns(array $row)
195
    {
196
        $line = [];
197
        $index = 0;
198
199
        foreach ($this->columns as $sql_name => $csv_name) {
200
            if (isset($row[$index])) {
201
                $line[$sql_name] = $row[$index];
202
            } else {
203
                $line[$sql_name] = '';
204
            }
205
206
            $index++;
207
        }
208
209
        return $line;
210
    }
211
212
    /**
213
     * Filter empty rows.
214
     *
215
     * @param array $row
216
     *
217
     * @return array
218
     */
219
    private function filterRow(array $row)
220
    {
221
        return array_filter($row);
222
    }
223
}
224