Issues (13)

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/storage/FileSystemStorage.php (1 issue)

Labels
Severity

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
 * Yii2 Pages Module
4
 *
5
 * @link      https://github.com/hiqdev/yii2-module-pages
6
 * @package   yii2-module-pages
7
 * @license   BSD-3-Clause
8
 * @copyright Copyright (c) 2016-2017, HiQDev (http://hiqdev.com/)
9
 */
10
11
namespace hiqdev\yii2\modules\pages\storage;
12
13
use creocoder\flysystem\Filesystem;
14
use hiqdev\yii2\collection\BaseObject;
15
use hiqdev\yii2\modules\pages\interfaces\PageInterface;
16
use hiqdev\yii2\modules\pages\interfaces\StorageInterface;
17
use hiqdev\yii2\modules\pages\models\AbstractPage;
18
use hiqdev\yii2\modules\pages\models\PagesList;
19
use Yii;
20
21
class FileSystemStorage extends BaseObject implements StorageInterface
22
{
23
    /** @var string|Filesystem */
24
    private $fileSystem;
25
26
    /** @var string */
27
    private $path;
28
29
    private $pageClasses = [
30
        ''      => \hiqdev\yii2\modules\pages\models\OtherPage::class,
31
        'md'    => \hiqdev\yii2\modules\pages\models\MarkdownPage::class,
32
        'php'   => \hiqdev\yii2\modules\pages\models\PhpPage::class,
33
        'twig'  => \hiqdev\yii2\modules\pages\models\TwigPage::class,
34
        'feature' => \hiqdev\yii2\modules\pages\models\BehatPage::class,
35
    ];
36
37
    /**
38
     * @param string $page
39
     * @return AbstractPage|null
40
     * @throws \yii\base\InvalidConfigException
41
     */
42
    public function getPage(string $page): ?PageInterface
43
    {
44
        if ($this->isDir($page)) {
45
            foreach (['index', 'README'] as $name) {
46
                $index = $this->getPage($page . '/' . $name);
0 ignored issues
show
Are you sure the assignment to $index is correct as $this->getPage($page . '/' . $name) (which targets hiqdev\yii2\modules\page...ystemStorage::getPage()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
47
                if ($index) {
48
                    return $index;
49
                }
50
            }
51
        }
52
53
        foreach (array_keys($this->pageClasses) as $extension) {
54
            $path = $page . '.' . $extension;
55
            if ($this->getFileSystem()->has($path)) {
56
                return AbstractPage::createFromFile($path, $this);
57
            }
58
        }
59
60
        return null;
61
    }
62
63
    public function getList(string $path = null): ?PagesList
64
    {
65
        if (!is_null($path) && $this->isDir($path)) {
66
            return PagesList::createFromDir($path, $this);
67
        }
68
69
        return null;
70
    }
71
72
    /**
73
     * @param string $page
74
     * @return bool|null
75
     * @throws \yii\base\InvalidConfigException
76
     */
77
    public function isDir(string $page): ?bool
78
    {
79
        if (!$this->getFileSystem()->has($page)) {
80
            return null;
81
        }
82
        $meta = $this->getMetadata($page);
83
84
        return $meta['type'] === 'dir';
85
    }
86
87
    /**
88
     * @param $page
89
     * @return array|false
90
     * @throws \yii\base\InvalidConfigException
91
     */
92
    public function getMetadata($page)
93
    {
94
        return $this->getFileSystem()->getMetadata($page);
95
    }
96
97
    /**
98
     * @param mixed $fileSystem
99
     */
100
    public function setFileSystem($fileSystem): void
101
    {
102
        $this->fileSystem = $fileSystem;
103
    }
104
105
    /**
106
     * @param string $path
107
     */
108
    public function setPath(string $path): void
109
    {
110
        $this->path = $path;
111
    }
112
113
    /**
114
     * @return string
115
     */
116
    public function getPath(): string
117
    {
118
        return $this->path;
119
    }
120
121
    /**
122
     * @param string $path
123
     * @return null|string
124
     * @throws \yii\base\InvalidConfigException
125
     */
126
    public function read(string $path): ?string
127
    {
128
        return $this->getFileSystem()->read($path);
129
    }
130
131
    /**
132
     * @param string $extension
133
     * @return string
134
     */
135
    public function findPageClass(string $extension): string
136
    {
137
        if (empty($this->pageClasses[$extension])) {
138
            $extension = '';
139
        }
140
141
        return $this->pageClasses[$extension];
142
    }
143
144
    /**
145
     * Reads given path as array of already rtrimmed lines.
146
     * @param string $path
147
     * @return false|string[]
148
     */
149
    public function readArray(string $path)
150
    {
151
        return preg_split("/((\r?\n)|(\r\n?))/", $this->fileSystem->read($path));
152
    }
153
154
    /**
155
     * @param $filePath
156
     * @return string
157
     */
158
    public function getLocalPath($filePath): string
159
    {
160
        return $this->path . '/' . $filePath;
161
    }
162
163
    /**
164
     * @return Filesystem
165
     * @throws \yii\base\InvalidConfigException
166
     */
167
    public function getFileSystem(): Filesystem
168
    {
169
        if (!is_object($this->fileSystem)) {
170
            $this->fileSystem = Yii::createObject([
171
                'class' => $this->fileSystem,
172
                'path' => $this->path,
173
            ]);
174
        }
175
176
        return $this->fileSystem;
177
    }
178
}
179