Issues (14)

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/Filesystem.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 IQParts\Content;
4
5
use IQParts\Content\Object\File;
6
use IQParts\Content\Object\Folder;
7
use League\Flysystem\AdapterInterface;
8
use League\Flysystem\Config;
9
use League\Flysystem\Directory;
10
use League\Flysystem\FileNotFoundException;
11
use League\Flysystem\Filesystem as FlySystem;
12
use League\Flysystem\Plugin\ListPaths;
13
14
/**
15
 * Class Filesystem
16
 * @package IQParts\Content
17
 */
18
final class Filesystem
19
{
20
    /**
21
     * @var FlySystem
22
     */
23
    private $flySystem;
24
25
    /**
26
     * Filesystem constructor.
27
     * @param AdapterInterface $adapter
28
     * @param Config $config
29
     */
30
    public function __construct(AdapterInterface $adapter, Config $config = null)
31
    {
32
        if (!$config) $config = [];
33
        $flySystem = new FlySystem($adapter, $config);
34
        $flySystem->addPlugin(new ListPaths());
35
        $this->flySystem = $flySystem;
36
    }
37
38
    /**
39
     * @param string $path
40
     * @return bool
41
     */
42
    public function exists(string $path): bool
43
    {
44
        if ($path === '/') $path = '';
45
        return $this->flySystem->has($path);
46
    }
47
48
    /**
49
     * @param string $path
50
     * @return File|Folder|false
51
     * @throws FileNotFoundException
52
     */
53
    public function get(string $path)
54
    {
55
        /**
56
         * If path = '/' -> create a folder object with all dirs and folders as children
57
         */
58
        if ($path === '/' || $path === '') {
59
            $dirs = [];
60
            $files = [];
61
            $paths = $this->flySystem->listPaths('', false);
62
            foreach ($paths as $item) {
63
                /** @var File|Directory $i */
64
                $i = $this->flySystem->get($item);
65
                if ($i->getType() === 'dir') {
0 ignored issues
show
The method getType does only exist in League\Flysystem\Directory, but not in IQParts\Content\Object\File.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
66
                    $dirs[] = base64_encode($i->getPath());
67
                } else {
68
                    $files[] = base64_encode($i->getPath());
69
                }
70
            }
71
72
            return Folder::fromVariables(base64_encode('/'), '/', '', null, $dirs, $files);
73
        } else {
74
            $item = $this->flySystem->get($path);
75
            if ($item instanceof Directory) {
76
                return new Folder($item);
77
            } else {
78
                return new File($item);
0 ignored issues
show
$item is of type object<League\Flysystem\Handler>, but the function expects a null|object<League\Flysystem\File>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
79
            }
80
        }
81
    }
82
83
    /**
84
     * @param string $path
85
     * @return bool|false|resource
86
     */
87
    public function getStream(string $path)
88
    {
89
        return $this->flySystem->readStream($path);
90
    }
91
92
    /**
93
     * @param string $path
94
     * @param bool $recursive
95
     * @return \Iterator|Folder[]|File[]
96
     */
97
    public function listDirContents(string $path, bool $recursive = false): \Iterator
98
    {
99
        if ($path === '/') $path = '';
100
        foreach ($this->flySystem->listPaths($path, $recursive) as $path) {
101
            $item = $this->flySystem->get($path);
102
            if ($item instanceof Directory) {
103
                yield new Folder($item);
104
            } else {
105
                yield new File($item);
0 ignored issues
show
$item is of type object<League\Flysystem\Handler>, but the function expects a null|object<League\Flysystem\File>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
106
            }
107
        }
108
    }
109
110
    /**
111
     * @param string $path
112
     * @param bool $recursive
113
     * @return \Iterator|Folder[]
114
     */
115
    public function listDirs(string $path, bool $recursive = false): \Iterator
116
    {
117
        if ($path === '/') $path = '';
118
        foreach ($this->flySystem->listPaths($path, $recursive) as $path) {
119
            $item = $this->flySystem->get($path);
120
            if ($item instanceof Directory) {
121
                yield new Folder($item);
122
            }
123
        }
124
    }
125
126
    /**
127
     * @param string $path
128
     * @param bool $recursive
129
     * @return \Iterator|File[]
130
     */
131
    public function listFiles(string $path, bool $recursive = false): \Iterator
132
    {
133
        if ($path === '/') $path = '';
134
        foreach ($this->flySystem->listContents($path, $recursive) as $i) {
135
            $item = $this->flySystem->get($i['path']);
136
            if ($item instanceof \League\Flysystem\File) yield new File($item);
137
        }
138
    }
139
140
    /**
141
     * @param string $path
142
     * @return bool
143
     */
144
    public function delete(string $path)
145
    {
146
        return $this->flySystem->delete($path);
147
    }
148
149
    /**
150
     * @param string $path
151
     * @return bool
152
     */
153
    public function deleteDir(string $path)
154
    {
155
        return $this->flySystem->deleteDir($path);
156
    }
157
158
    /**
159
     * @param string $path
160
     * @param array $config
161
     * @return bool
162
     */
163
    public function createDir(string $path, array $config = [])
164
    {
165
        return $this->flySystem->createDir($path, $config);
166
    }
167
168
    /**
169
     * @param string $path
170
     * @param $contents
171
     * @param array $config
172
     * @return bool
173
     */
174
    public function put(string $path, $contents, array $config = []): bool
175
    {
176
        return $this->flySystem->put($path, $contents, $config);
177
    }
178
179
    /**
180
     * @param string $path
181
     * @param resource $contents
182
     * @param array $config
183
     * @return bool
184
     */
185
    public function putStream(string $path, $contents, array $config = []): bool
186
    {
187
        return $this->flySystem->putStream($path, $contents, $config);
188
    }
189
190
    /**
191
     * @return FlySystem
192
     */
193
    public function getFlySystem(): FlySystem
194
    {
195
        return $this->flySystem;
196
    }
197
}