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/DataIntegrityTestYML.php (5 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 DataIntegrityTestYML extends BuildTask
5
{
6
7
    /**
8
     * list of files you want to check
9
     * @var array
10
     */
11
    private static $config_files = array("mysite/_config/config.yml");
12
13
    /**
14
     * list of classes that do not need to be checked
15
     * NB: they are all lowercase, as we test for them only lowercase!
16
     * @var array
17
     */
18
    private static $classes_to_skip = array("name", "before", "only", "after");
19
20
    /**
21
     * list of variables that do not need checking...
22
     * @var array
23
     */
24
    private static $variables_to_skip = array();
25
26
    /**
27
     * standard SS variable
28
     * @var String
29
     */
30
    protected $title = "Check your config files for rogue entries.";
31
32
    /**
33
     * standard SS variable
34
     * @var String
35
     */
36
    protected $description = "Checks a selection of yml files to see if there are any entries that may be incorrect.";
37
38
    public function run($request)
39
    {
40
        ini_set('max_execution_time', 3000);
41
        require_once 'thirdparty/spyc/spyc.php';
42
        $filesArray = Config::inst()->get("DataIntegrityTestYML", "config_files");
43
        $classesToSkip = Config::inst()->get("DataIntegrityTestYML", "classes_to_skip");
44
        $variablesToSkip = Config::inst()->get("DataIntegrityTestYML", "variables_to_skip");
45
        foreach ($filesArray as $folderAndFileLocation) {
0 ignored issues
show
The expression $filesArray 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...
46
            db::alteration_message("<h2>Checking $folderAndFileLocation</h2>");
47
            $fixtureFolderAndFile = Director::baseFolder().'/'. $folderAndFileLocation;
48
            if (!file_exists($fixtureFolderAndFile)) {
49
                user_error('No custom configuration has been setup here : "' . $fixtureFolderAndFile . '" set the files here: DataIntegrityTestYML::config_files', E_USER_NOTICE);
50
            }
51
            $parser = new Spyc();
52
            $arrayOfSettings = $parser->loadFile($fixtureFolderAndFile);
53
            foreach ($arrayOfSettings as $className => $variables) {
54
                if (in_array(strtolower($className), $classesToSkip)) {
55
                    db::alteration_message("$className : skipped");
56
                } else {
57
                    echo "<br /><br />";
58
                    if (!class_exists($className)) {
59
                        db::alteration_message("$className does not exist", "deleted");
60
                    } else {
61
                        db::alteration_message("$className", "created");
62
                        foreach ($variables as $variable => $setting) {
63
                            if ($variable == "icon") {
64
                                $fileLocationForOthers = Director::baseFolder().'/'.$setting;
65
                                $fileLocationForSiteTree = Director::baseFolder().'/'.$setting.'-file.gif';
66
                                if ($className::create() instanceof SiteTree) {
67 View Code Duplication
                                    if (!file_exists($fileLocationForSiteTree)) {
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
68
                                        db::alteration_message("&nbsp; &nbsp; &nbsp; <u>$className.$variable</u> icon $fileLocationForSiteTree can not be found", "deleted");
69
                                    } else {
70
                                        db::alteration_message("&nbsp; &nbsp; &nbsp; <u>$className.$variable</u> icon $fileLocationForSiteTree exists", "created");
71
                                    }
72 View Code Duplication
                                } else {
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
73
                                    if (!file_exists($fileLocationForOthers)) {
74
                                        db::alteration_message("&nbsp; &nbsp; &nbsp; <u>$className.$variable</u> icon $fileLocationForOthers can not be found", "deleted");
75
                                    } else {
76
                                        db::alteration_message("&nbsp; &nbsp; &nbsp; <u>$className.$variable</u> icon $fileLocationForOthers exists", "created");
77
                                    }
78
                                }
79
                            } elseif ($variable == "extensions") {
80
                                if (!is_array($setting)) {
81
                                    db::alteration_message("&nbsp; &nbsp; &nbsp; <u>$className.$variable</u> extensions should be set as an array.", "deleted");
82 View Code Duplication
                                } else {
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
83
                                    foreach ($setting as $extensionClassName) {
84
                                        if (!class_exists($extensionClassName)) {
85
                                            db::alteration_message("&nbsp; &nbsp; &nbsp; <u>$className.$variable</u> extension class <u>$extensionClassName</u> does not exist", "deleted");
86
                                        } else {
87
                                            db::alteration_message("&nbsp; &nbsp; &nbsp; <u>$className.$variable</u> extension class <u>$extensionClassName</u> found", "created");
88
                                        }
89
                                    }
90
                                }
91
                            } elseif (in_array($variable, $variablesToSkip)) {
92
                                db::alteration_message("&nbsp; &nbsp; &nbsp; <u>$className.$variable</u> skipped");
93 View Code Duplication
                            } else {
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
94
                                if (!property_exists($className, $variable)) {
95
                                    db::alteration_message("&nbsp; &nbsp; &nbsp; <u>$className.$variable</u> does not exist", "deleted");
96
                                } else {
97
                                    db::alteration_message("&nbsp; &nbsp; &nbsp; <u>$className.$variable</u> found", "created");
98
                                }
99
                            }
100
                        }
101
                    }
102
                }
103
            }
104
        }
105
    }
106
}
107