Issues (26)

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.

src/CustomReader.php (3 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
namespace ilateral\SilverStripe\SlightlyBetterBulkLoader;
4
5
use League\Csv\Reader;
6
7
class CustomReader extends Reader
8
{
9
    /**
10
     * Should this reader ignore column headers that are null when importing?
11
     *
12
     * Sometimes Excel adds null headers to the end of a CSV and this can result in the
13
     * CSV failing to parse.
14
     *
15
     * @var boolean
16
     */
17
    protected $ignore_empty_headers = true;
18
19
    /**
20
     * Validates the array to be used by the fetchAssoc method
21
     *
22
     * @param array $keys
23
     *
24
     * @throws InvalidArgumentException If the submitted array fails the assertion
25
     *
26
     * @return array
27
     */
28
    protected function validateKeys(array $keys)
29
    {
30
        if ($this->getIgnoreEmptyHeaders()) {
31
            $last = $this->findLastHeaderPos($keys);
32
            $new_keys = [];
33
            
34
            for ($i = 0; $i < count($keys); $i++) {
0 ignored issues
show
Performance Best Practice introduced by
It seems like you are calling the size function count() as part of the test condition. You might want to compute the size beforehand, and not on each iteration.

If the size of the collection does not change during the iteration, it is generally a good practice to compute it beforehand, and not on each iteration:

for ($i=0; $i<count($array); $i++) { // calls count() on each iteration
}

// Better
for ($i=0, $c=count($array); $i<$c; $i++) { // calls count() just once
}
Loading history...
35
                if ($i <= $last) {
36
                    $new_keys[] = $keys[$i];
37
                }
38
            }
39
40
            $keys = $new_keys;
41
        }
42
43
        return parent::validateKeys($keys);
44
    }
45
46
    /**
47
     * Attempt to find the position of the last legitimate
48
     * header column (a column that is not null and is the last
49
     * item in the list that is not null).
50
     *
51
     * @param array $keys
52
     *
53
     * @return int
54
     */
55
    protected function findLastHeaderPos(array $keys)
56
    {
57
        $last = 0;
58
        $count = count($keys);
59
60
        for ($i = 0; $i < $count; $i++) {
61
            $curr = trim($keys[$i]);
62
            $j = $i;
0 ignored issues
show
$j is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
63
64
            // If the current field isn't empty, skip
65
            if (!empty($curr)) {
66
                $last = $i;
67
                continue;
68
            }
69
70
            // If the column is empty, the previous one isn't
71
            // and the next few are or don't exist, assume
72
            // we have hit the last item. Set and break.
73
            if (empty($curr) && isset($keys[$i-1])) {
74
                $temp = 0;
75
                for ($j = $i; $j < $count; $j++) {
76
                    if (!empty($keys[$j])) {
77
                        $temp = $keys[$j];
78
                    }
79
                }
80
81
                if ($temp > 0) {
82
                    $last = $i;
83
                }
84
            }
85
        }
86
87
        return $last;
88
    }
89
90
    /**
91
     * Get the ignore_empty_headers param
92
     *
93
     * @return boolean
94
     */
95
    public function getIgnoreEmptyHeaders()
96
    {
97
        return $this->ignore_empty_headers;
98
    }
99
100
    /**
101
     * Set the ignore_empty_headers param
102
     *
103
     * @param boolean $ignore_empty_headers Ignore header keys that are blank?
104
     *
105
     * @return self
106
     */
107
    public function setIgnoreEmptyHeaders(boolean $ignore_empty_headers)
108
    {
109
        $this->ignore_empty_headers = $ignore_empty_headers;
0 ignored issues
show
Documentation Bug introduced by
It seems like $ignore_empty_headers of type object<ilateral\SilverSt...tterBulkLoader\boolean> is incompatible with the declared type boolean of property $ignore_empty_headers.

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...
110
        return $this;
111
    }
112
}
113