Issues (25)

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.

models/File.php (1 issue)

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
 * File.php
4
 * @author Revin Roman http://phptime.ru
5
 */
6
7
namespace rmrevin\yii\module\File\models;
8
9
use yii\base\ModelEvent;
10
use yii\helpers\FileHelper;
11
use yii\helpers\StringHelper;
12
13
/**
14
 * Class File
15
 * @package rmrevin\yii\module\File\models
16
 *
17
 * @property integer $id
18
 * @property string $mime
19
 * @property integer $size
20
 * @property string $name
21
 * @property string $origin_name
22
 * @property string $sha1
23
 * @property boolean $image_bad
24
 *
25
 * @method \rmrevin\yii\module\File\models\queries\FileQuery hasMany($class, $link)
26
 * @method \rmrevin\yii\module\File\models\queries\FileQuery hasOne($class, $link)
27
 */
28
class File extends \yii\db\ActiveRecord
29
{
30
31
    /** @var string */
32
    public $path;
33
34
    /**
35
     * @inheritdoc
36
     */
37 6
    public function init()
38
    {
39 6
        parent::init();
40
41 6
        $this->events();
42 6
    }
43
44
    /**
45
     * @return string
46
     */
47 1
    public function __toString()
48
    {
49 1
        return $this->getWebPath();
50
    }
51
52
    /**
53
     * @param bool $recalculate
54
     * @return integer
55
     */
56 1
    public function getSize($recalculate = false)
57
    {
58 1
        return true === $recalculate ? filesize($this->getAbsolutePath()) : $this->size;
59
    }
60
61
    /**
62
     * @param bool $recalculate
63
     * @return string
64
     * @throws \yii\base\InvalidConfigException.
65
     */
66 1
    public function getMime($recalculate = false)
67
    {
68 1
        return true === $recalculate ? FileHelper::getMimeType($this->getAbsolutePath()) : $this->mime;
69
    }
70
71
    /**
72
     * @param bool $recalculate
73
     * @return string
74
     */
75 1
    public function getSha1($recalculate = false)
76
    {
77 1
        return true === $recalculate ? sha1_file($this->getAbsolutePath()) : $this->sha1;
78
    }
79
80
    /**
81
     * @return string
82
     */
83 1
    public function getWebPath()
84
    {
85 1
        $upload_path = \rmrevin\yii\module\File\Module::module()->upload_web_path;
86
87 1
        $p1 = StringHelper::byteSubstr($this->name, 0, 2);
88 1
        $p2 = StringHelper::byteSubstr($this->name, 2, 2);
89
90 1
        return $upload_path . '/' . $p1 . '/' . $p2 . '/' . $this->name;
91
    }
92
93
    /**
94
     * @return string
95
     */
96 4
    public function getAbsolutePath()
97
    {
98 4
        $upload_path = \rmrevin\yii\module\File\Module::module()->upload_path;
99
100 4
        $p1 = StringHelper::byteSubstr($this->name, 0, 2);
101 4
        $p2 = StringHelper::byteSubstr($this->name, 2, 2);
102
103 4
        return $upload_path . DIRECTORY_SEPARATOR . $p1 . DIRECTORY_SEPARATOR . $p2 . DIRECTORY_SEPARATOR . $this->name;
104
    }
105
106
    /**
107
     * @param \rmrevin\yii\module\File\resources\ResourceInterface $Resource
108
     * @return static
109
     * @throws \Exception
110
     */
111 6
    public static function push(\rmrevin\yii\module\File\resources\ResourceInterface $Resource)
112
    {
113 6
        $id = basename($Resource->getTemp());
114 6
        \Yii::beginProfile('pushing file `' . $id . '`', __METHOD__);
115
116 6
        $NewModel = new static();
117 6
        $NewModel->path = $Resource->getTemp();
118
119 6
        $Model = static::find()->bySha1($Resource->getSha1())->one();
120
121 6
        if ($Model instanceof static) {
122 1
            $NewModel = $Model;
123 1
        } else {
124 6
            $result = $Resource->moveToUpload();
125 6
            if (false !== $result) {
126 5
                $NewModel->name = basename($result);
127 5
                $NewModel->origin_name = $Resource->getName();
128 5
                $NewModel->path = $result;
129 5
                $NewModel->insert();
130 5
            } else {
131 1
                throw new \RuntimeException(\Yii::t('service-file', 'Failed to bring the resource directory of uploaded files.'));
132
            }
133
        }
134 5
        \Yii::endProfile('pushing file `' . $id . '`', __METHOD__);
135
136 5
        return $NewModel;
137
    }
138
139
    /**
140
     * @return static
141
     */
142 2
    public static function getNoImage()
143
    {
144 2
        $image = \Yii::getAlias(\rmrevin\yii\module\File\Module::module()->no_image_alias);
145 2
        $Resource = new \rmrevin\yii\module\File\resources\InternalResource($image);
146
147 2
        return static::push($Resource);
148
    }
149
150
    /**
151
     * @return \rmrevin\yii\module\File\ImageWrapper
152
     * @throws \Exception
153
     */
154 4
    public function image()
155
    {
156 4
        \Yii::beginProfile('manipulating with file `' . $this->id . '`', 'services\File\models\File');
157
158 4
        $result = null;
0 ignored issues
show
$result 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...
159 4
        if ($this->isImage()) {
160 3
            $result = \rmrevin\yii\module\File\ImageWrapper::load($this);
161 3
        } else {
162 1
            $File = static::getNoImage();
163 1
            $result = \rmrevin\yii\module\File\ImageWrapper::load($File);
164 1
            $this->image_bad = true;
165 1
            $this->update();
166
        }
167
168 4
        return $result;
169
    }
170
171
    /**
172
     * @return bool
173
     */
174 4
    public function isImage()
175
    {
176 4
        return @getimagesize($this->getAbsolutePath()) !== false;
177
    }
178
179
    /**
180
     * @return \rmrevin\yii\module\File\models\queries\FileQuery|\yii\db\ActiveQuery
181
     */
182 6
    public static function find()
183
    {
184 6
        return new queries\FileQuery(get_called_class());
185
    }
186
187
    /**
188
     * @inheritdoc
189
     */
190 6
    public static function tableName()
191
    {
192 6
        return '{{%file}}';
193
    }
194
195
    /**
196
     * Events
197
     */
198
    private function events()
199
    {
200 6
        $this->on(static::EVENT_BEFORE_INSERT, function (ModelEvent $Event) {
201
            /** @var static $Model */
202 5
            $Model = $Event->sender;
203 5
            $Model->size = filesize($Model->path);
204 5
            $Model->mime = FileHelper::getMimeType($Model->path);
205 5
            $Model->sha1 = sha1_file($Model->path);
206 6
        });
207
    }
208
}