Issues (65)

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/Traits/UploadStorageTrait.php (1 issue)

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
namespace Sco\Admin\Traits;
4
5
use Illuminate\Http\UploadedFile;
6
use Illuminate\Support\Facades\Storage;
7
8
trait UploadStorageTrait
9
{
10
    /**
11
     * @var string storage disk name
12
     */
13
    protected $disk;
14
15
    /**
16
     * @var string|\Closure|null The relative path of file
17
     */
18
    protected $uploadPath;
19
20
    /**
21
     * @var \Closure|null The rule of generate file name
22
     */
23
    protected $uploadFileNameRule;
24
25
    /**
26
     * Get Filesystem Disk of the upload file.
27
     *
28
     * @return string
29
     */
30
    public function getDisk()
31
    {
32
        if ($this->disk) {
33
            return $this->disk;
34
        }
35
36
        return $this->getDefaultDisk();
37
    }
38
39
    protected function getDefaultDisk()
40
    {
41
        return config('admin.upload.disk', 'public');
42
    }
43
44
    /**
45
     * Set Filesystem Disk of the upload file.
46
     *
47
     * @param string $value
48
     *
49
     * @return $this
50
     */
51
    public function setDisk($value)
52
    {
53
        $this->disk = $value;
54
55
        return $this;
56
    }
57
58
    /**
59
     * Get a default relative path of the upload file.
60
     *
61
     * @param \Illuminate\Http\UploadedFile $file
62
     *
63
     * @return string
64
     */
65
    protected function getDefaultUploadPath(UploadedFile $file)
0 ignored issues
show
The parameter $file is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
66
    {
67
        $root = config('admin.upload.directory', 'admin/uploads');
68
69
        return trim($root, '/') . date('/Y/m/d');
70
    }
71
72
    /**
73
     * Get relative path of the upload file.
74
     *
75
     * @param \Illuminate\Http\UploadedFile $file
76
     *
77
     * @return \Closure|mixed|null|string
78
     */
79
    public function getUploadPath(UploadedFile $file)
80
    {
81
        if (($path = $this->uploadPath)) {
82
            if (is_callable($path)) {
83
                $path = call_user_func($path, $file);
84
            }
85
86
            return trim($path, '/');
87
        }
88
89
        return $this->getDefaultUploadPath($file);
90
    }
91
92
    /**
93
     * Set relative path of the upload file.
94
     *
95
     * @param string|\Closure $value
96
     *
97
     * @return $this
98
     */
99
    public function setUploadPath($value)
100
    {
101
        $this->uploadPath = $value;
102
103
        return $this;
104
    }
105
106
    /**
107
     * Get a file name of the upload file.
108
     *
109
     * @param \Illuminate\Http\UploadedFile $file
110
     *
111
     * @return mixed|string
112
     */
113
    public function getUploadFileName(UploadedFile $file)
114
    {
115
        if (is_callable($this->uploadFileNameRule)) {
116
            return call_user_func($this->uploadFileNameRule, $file);
117
        }
118
119
        return $this->getDefaultFileName($file);
120
    }
121
122
    /**
123
     * Get a default name of the upload file.
124
     *
125
     * @param \Illuminate\Http\UploadedFile $file
126
     *
127
     * @return string
128
     */
129
    protected function getDefaultFileName(UploadedFile $file)
130
    {
131
        return $file->hashName();
132
    }
133
134
    /**
135
     * Set the generation rule for the filename of the uploaded file
136
     *
137
     * @param \Closure $value
138
     *
139
     * @return $this
140
     */
141
    public function setUploadFileNameRule(\Closure $value)
142
    {
143
        $this->uploadFileNameRule = $value;
144
145
        return $this;
146
    }
147
148
    protected function existsFile($path)
149
    {
150
        return Storage::disk($this->getDisk())->exists($path);
151
    }
152
153
    protected function getFileUrl($path)
154
    {
155
        if (($disk = $this->getDisk())) {
156
            $url = Storage::disk($disk)->url($path);
157
        } else {
158
            $url = asset($path);
159
        }
160
161
        return $url;
162
    }
163
}
164