Issues (62)

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.

code/DataIntegrityTestUTF8.php (8 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
class DataIntegrityTestUTF8 extends BuildTask
5
{
6
    private static $replacement_array = array(
7
        'Â' => '',
8
        'Â' => '',
9
        'Â' => '',
10
        '’' => '&#39;',
11
        '–' => '&mdash;',
12
        '
' => '',
13
        '“' => '&quot;',
14
        'â€^Ý' => '&quot;',
15
        '<br>' => '<br />',
16
        '•' => '&#8226',
17
        'Ý' => '- '
18
    );
19
20
    /**
21
     * standard SS variable
22
     * @var String
23
     */
24
    protected $title = "Convert tables to utf-8 and replace funny characters.";
25
26
    /**
27
     * standard SS variable
28
     * @var String
29
     */
30
    protected $description = "Converts table to utf-8 by replacing a bunch of characters that show up in the Silverstripe Conversion. CAREFUL: replaces all tables in Database to utf-8!";
31
32
    public function run($request)
33
    {
34
        ini_set('max_execution_time', 3000);
35
        $tables = DB::query('SHOW tables');
36
        $unique = array();
0 ignored issues
show
$unique 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...
37
        $arrayOfReplacements = Config::inst()->get("DataIntegrityTestUTF8", "replacement_array");
38
        foreach ($tables as $table) {
39
            $table = array_pop($table);
40
            DB::query("ALTER TABLE \"$table\" CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci");
41
            DB::alteration_message("<h2>Resetting $table to utf8</h2>");
42
            $this->flushNow();
43
            $originatingClass = str_replace("_Live", "", $table);
44
            if (class_exists($originatingClass) && !class_exists($table)) {
45
            } else {
46
                $originatingClass = $table;
47
            }
48
            if (class_exists($originatingClass)) {
49
                $fields = Config::inst()->get($originatingClass, "db", $uninherited = 1);
50
                if ($fields && count($fields)) {
51
                    $unusedFields = array();
52
                    foreach ($fields as $fieldName => $type) {
0 ignored issues
show
The expression $fields of type array|integer|double|string|boolean is not guaranteed to be traversable. How about adding an additional type check?

There are different options of fixing this problem.

  1. If you want to be on the safe side, you can add an additional type-check:

    $collection = json_decode($data, true);
    if ( ! is_array($collection)) {
        throw new \RuntimeException('$collection must be an array.');
    }
    
    foreach ($collection as $item) { /** ... */ }
    
  2. If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:

    /** @var array $collection */
    $collection = json_decode($data, true);
    
    foreach ($collection as $item) { /** .. */ }
    
  3. Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.

Loading history...
53
                        $usedFieldsChanged = array("CHECKING $table.$fieldName : ");
54
                        if (substr($type, 0, 4) == "HTML") {
55
                            foreach ($arrayOfReplacements as $from => $to) {
0 ignored issues
show
The expression $arrayOfReplacements of type array|integer|double|string|boolean is not guaranteed to be traversable. How about adding an additional type check?

There are different options of fixing this problem.

  1. If you want to be on the safe side, you can add an additional type-check:

    $collection = json_decode($data, true);
    if ( ! is_array($collection)) {
        throw new \RuntimeException('$collection must be an array.');
    }
    
    foreach ($collection as $item) { /** ... */ }
    
  2. If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:

    /** @var array $collection */
    $collection = json_decode($data, true);
    
    foreach ($collection as $item) { /** .. */ }
    
  3. Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.

Loading history...
56
                                DB::query("UPDATE \"$table\" SET \"$fieldName\" = REPLACE(\"$fieldName\", '$from', '$to');");
57
                                $count = DB::getConn()->affectedRows();
0 ignored issues
show
Deprecated Code introduced by
The method DB::getConn() has been deprecated with message: since version 4.0 Use DB::get_conn instead

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
58
                                $toWord = $to;
59
                                if ($to == '') {
60
                                    $toWord = '[NOTHING]';
61
                                }
62
                                $usedFieldsChanged[] = "$count Replacements <strong>$from</strong> with <strong>$toWord</strong>";
63
                            }
64
                        } else {
65
                            $unusedFields[] = $fieldName;
66
                        }
67
                        if (count($usedFieldsChanged)) {
68
                            DB::alteration_message(implode("<br /> &nbsp;&nbsp;&nbsp;&nbsp; - ", $usedFieldsChanged));
69
                            $this->flushNow();
70
                        }
71
                    }
72
                    if (count($unusedFields)) {
73
                        DB::alteration_message("Skipped the following fields: ".implode(",", $unusedFields));
74
                    }
75
                } else {
76
                    DB::alteration_message("No fields for $originatingClass");
77
                }
78
            } else {
79
                DB::alteration_message("Skipping $originatingClass - class can not be found");
80
            }
81
        }
82
        DB::alteration_message("<hr /><hr /><hr /><hr /><hr /><hr /><hr />COMPLETED<hr /><hr /><hr /><hr /><hr /><hr /><hr />");
83
    }
84
85
    private function flushNow()
86
    {
87
        // check that buffer is actually set before flushing
88
        if (ob_get_length()) {
89
            @ob_flush();
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
90
            @flush();
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
91
            @ob_end_flush();
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
92
        }
93
        @ob_start();
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
94
    }
95
}
96