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.

Module.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
 * Module.php
4
 * @author Revin Roman http://phptime.ru
5
 */
6
7
namespace rmrevin\yii\module\File;
8
9
use yii\base\InvalidConfigException;
10
use yii\helpers\FileHelper;
11
12
/**
13
 * Class Module
14
 * @package rmrevin\yii\module\File
15
 */
16
class Module extends \yii\base\Module
17
{
18
19
    /** @var string */
20
    public $upload_alias = '@app/web/upload';
21
22
    /** @var string */
23
    public $upload_path = null;
24
25
    /** @var string */
26
    public $upload_web_alias = '/upload';
27
28
    /** @var string */
29
    public $upload_web_path = null;
30
31
    /** @var string */
32
    public $storage_alias = '@app/web/storage';
33
34
    /** @var string */
35
    public $storage_path = null;
36
37
    /** @var string */
38
    public $storage_web_alias = '/storage';
39
40
    /** @var string */
41
    public $storage_web_path = null;
42
43
    /** @var int */
44
    public $max_upload_file_size = 10; // megabytes
45
46
    /** @var string */
47
    public $no_image_alias = '@vendor/rmrevin/yii2-file/assets/no-image.png';
48
49
    /**
50
     * @inheritdoc
51
     */
52 15
    public function init()
53
    {
54 15
        parent::init();
55
56 15
        $this->checkIniSizeParam('upload_max_filesize');
57
58 15
        $this->checkIniSizeParam('post_max_size');
59
60 15
        $this->reinitAliases();
61
62 15
        if (empty($this->upload_path)) {
63 1
            throw new InvalidConfigException(\Yii::t('service-file', 'Unable to determine the path to the upload directory (FileService::$upload_path).'));
64
        }
65
66 15
        if (empty($this->storage_path)) {
67 1
            throw new InvalidConfigException(\Yii::t('service-file', 'Unable to determine the path to the storage directory (FileService::$storage_path).'));
68
        }
69
70 15
        $this->createDirectory($this->upload_path);
71
72 15
        $this->createDirectory($this->storage_path);
73
74 15
        if (!is_readable($this->upload_path)) {
75 1
            throw new \RuntimeException(\Yii::t('service-file', 'Upload directory not available for reading (FileService::$upload_path).'));
76
        }
77
78 15
        if (!is_writable($this->upload_path)) {
79 1
            throw new \RuntimeException(\Yii::t('service-file', 'Upload directory not available for writing (FileService::$upload_path).'));
80
        }
81
82 15
        if (!is_readable($this->storage_path)) {
83 1
            throw new \RuntimeException(\Yii::t('service-file', 'Storage directory not available for reading (FileService::$storage_path).'));
84
        }
85
86 15
        if (!is_writable($this->storage_path)) {
87 1
            throw new \RuntimeException(\Yii::t('service-file', 'Storage directory not available for writing (FileService::$storage_path).'));
88
        }
89 15
    }
90
91 15
    public function reinitAliases()
92
    {
93 15
        $this->storage_path = \Yii::getAlias($this->storage_alias);
94 15
        $this->storage_web_path = \Yii::getAlias($this->storage_web_alias);
95 15
        $this->upload_web_path = \Yii::getAlias($this->upload_web_alias);
96 15
        $this->upload_path = \Yii::getAlias($this->upload_alias);
97 15
    }
98
99
    /**
100
     * @return static
101
     */
102 12
    public static function module()
0 ignored issues
show
Coding Style Best Practice introduced by
Please use __construct() instead of a PHP4-style constructor that is named after the class.
Loading history...
103
    {
104 12
        return \Yii::$app->getModule(static::MODULE);
105
    }
106
107
    /**
108
     * @param string $path
109
     */
110 15
    private function createDirectory($path)
111
    {
112 15
        if (!file_exists($path) || !is_dir($path)) {
113 15
            FileHelper::createDirectory($path);
114 15
        }
115 15
    }
116
117
    /**
118
     * @param string $param
119
     */
120 15
    private function checkIniSizeParam($param)
121
    {
122 15
        if ((int)ini_get($param) < $this->max_upload_file_size) {
123 15
            \Yii::warning(sprintf('The parameter `%s` in php.ini must be equal to`%s`', $param,
124 15
                $this->max_upload_file_size . 'M'), __METHOD__);
125 15
        }
126 15
    }
127
128
    const MODULE = 'file';
129
}