Issues (569)

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.

src/Common/ResourceExistenceChecker.php (4 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 Robo\Common;
4
5
trait ResourceExistenceChecker
6
{
7
    /**
8
     * Checks if the given input is a file or folder.
9
     *
10
     * @param string|string[] $resources
11
     * @param string $type
12
     *   Allowed values: "file", "dir", "fileAndDir"
13
     *
14
     * @return bool
15
     *   True if no errors were encountered otherwise false.
16
     */
17
    protected function checkResources($resources, $type = 'fileAndDir')
18
    {
19
        if (!in_array($type, ['file', 'dir', 'fileAndDir'])) {
20
            throw new \InvalidArgumentException(sprintf('Invalid resource check of type "%s" used!', $type));
21
        }
22
        if (is_string($resources)) {
23
            $resources = [$resources];
24
        }
25
        $success = true;
26
        foreach ($resources as $resource) {
27
            $glob = glob($resource);
28
            if ($glob === false) {
29
                $this->printTaskError(sprintf('Invalid glob "%s"!', $resource), $this);
0 ignored issues
show
It seems like printTaskError() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
30
                $success = false;
31
                continue;
32
            }
33
            foreach ($glob as $resource) {
34
                if (!$this->checkResource($resource, $type)) {
35
                    $success = false;
36
                }
37
            }
38
        }
39
        return $success;
40
    }
41
42
    /**
43
     * Checks a single resource, file or directory.
44
     *
45
     * It will print an error as well on the console.
46
     *
47
     * @param string $resource
48
     *   File or folder.
49
     * @param string $type
50
     *   Allowed values: "file", "dir", "fileAndDir".
51
     *
52
     * @return bool
53
     */
54
    protected function checkResource($resource, $type)
55
    {
56
        switch ($type) {
57
            case 'file':
58
                if (!$this->isFile($resource)) {
59
                    $this->printTaskError(sprintf('File "%s" does not exist!', $resource), $this);
0 ignored issues
show
It seems like printTaskError() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
60
                    return false;
61
                }
62
                return true;
63
            case 'dir':
64
                if (!$this->isDir($resource)) {
65
                    $this->printTaskError(sprintf('Directory "%s" does not exist!', $resource), $this);
0 ignored issues
show
It seems like printTaskError() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
66
                    return false;
67
                }
68
                return true;
69
            case 'fileAndDir':
70
                if (!$this->isDir($resource) && !$this->isFile($resource)) {
71
                    $this->printTaskError(sprintf('File or directory "%s" does not exist!', $resource), $this);
0 ignored issues
show
It seems like printTaskError() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
72
                    return false;
73
                }
74
                return true;
75
        }
76
    }
77
78
    /**
79
     * Convenience method to check the often uses "source => target" file / folder arrays.
80
     *
81
     * @param string|array $resources
82
     */
83
    protected function checkSourceAndTargetResource($resources)
84
    {
85
        if (is_string($resources)) {
86
            $resources = [$resources];
87
        }
88
        $sources = [];
89
        $targets = [];
90
        foreach ($resources as $source => $target) {
91
            $sources[] = $source;
92
            $target[] = $target;
93
        }
94
        $this->checkResources($sources);
95
        $this->checkResources($targets);
96
    }
97
98
   /**
99
    * Wrapper method around phps is_dir()
100
    *
101
    * @param string $directory
102
    *
103
    * @return bool
104
    */
105
    protected function isDir($directory)
106
    {
107
        return is_dir($directory);
108
    }
109
110
   /**
111
    * Wrapper method around phps file_exists()
112
    *
113
    * @param string $file
114
    *
115
    * @return bool
116
    */
117
    protected function isFile($file)
118
    {
119
        return file_exists($file);
120
    }
121
}
122