Issues (8)

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/ChunkFile.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
namespace Recca0120\Upload;
4
5
use ErrorException;
6
use Recca0120\Upload\Exceptions\ChunkedResponseException;
7
8
class ChunkFile
9
{
10
    /**
11
     * TMPFILE_EXTENSION.
12
     *
13
     * @var string
14
     */
15
    const TMPFILE_EXTENSION = '.part';
16
17
    /**
18
     * $files.
19
     *
20
     * @var \Recca0120\Upload\Filesystem
21
     */
22
    protected $files;
23
24
    /**
25
     * $token.
26
     *
27
     * @var string
28
     */
29
    protected $token = null;
30
31
    /**
32
     * $chunkPath.
33
     *
34
     * @var string
35
     */
36
    protected $chunkPath = null;
37
38
    /**
39
     * $storagePath.
40
     *
41
     * @var string
42
     */
43
    protected $storagePath = null;
44
45
    /**
46
     * $name.
47
     *
48
     * @var string
49
     */
50
    protected $name = null;
51
52
    /**
53
     * $mimeType.
54
     *
55
     * @var string
56
     */
57
    protected $mimeType = null;
58
59
    /**
60
     * $tmpfilename.
61
     *
62
     * @var string
63
     */
64
    protected $tmpfilename = null;
65
66
    /**
67
     * __construct.
68
     *
69
     * @param string $name
70
     * @param string $chunkPath
71
     * @param string $storagePath
72
     * @param string $mimeType
73
     * @param string $token
74
     * @param \Recca0120\Upload\Filesystem $files
75
     */
76 5
    public function __construct($name, $chunkPath, $storagePath, $token = null, $mimeType = null, Filesystem $files = null)
77
    {
78 5
        $this->files = $files ?: new Filesystem();
79 5
        $this->name = $name;
80 5
        $this->chunkPath = $chunkPath;
81 5
        $this->storagePath = $storagePath;
82 5
        $this->token = $token;
83 5
        $this->mimeType = $mimeType;
84 5
    }
85
86
    /**
87
     * getMimeType.
88
     *
89
     * @return string
90
     */
91 1
    public function getMimeType()
92
    {
93
        try {
94 1
            return $this->mimeType ?: $this->files->mimeType($this->name);
95
        } catch (ErrorException $e) {
96
            return;
97
        }
98
    }
99
100
    /**
101
     * throwException.
102
     *
103
     * @param mixed $message
104
     * @param array $headers
105
     * @throws \Recca0120\Upload\Exceptions\ChunkedResponseException
106
     */
107 3
    public function throwException($message = '', $headers = [])
108
    {
109 3
        throw new ChunkedResponseException($message, $headers);
110
    }
111
112
    /**
113
     * appendStream.
114
     *
115
     * @param mixed $source
116
     * @param int $offset
117
     * @return $this
118
     */
119 1
    public function appendStream($source, $offset = 0)
120
    {
121 1
        $chunkFile = $this->chunkFile();
122 1
        $this->files->appendStream($chunkFile, $source, (int) $offset);
123
124 1
        return $this;
125
    }
126
127
    /**
128
     * appendFile.
129
     *
130
     * @param mixed $source
131
     * @param int $index
132
     * @return $this
133
     */
134 1
    public function appendFile($source, $index = 0)
135
    {
136 1
        $chunkFile = $this->chunkFile().'.'.$index;
137 1
        $this->files->appendStream($chunkFile, $source, 0);
138
139 1
        return $this;
140
    }
141
142
    /**
143
     * createUploadedFile.
144
     *
145
     * @return \Illuminate\Http\UploadedFile
146
     */
147 1
    public function createUploadedFile($chunks = null, $storageFile = null)
148
    {
149 1
        $chunkFile = $this->chunkFile();
150 1
        $storageFile = $storageFile ?: $this->storageFile();
151
152 1
        if (is_null($chunks) === false) {
153
            for ($i = 0; $i < $chunks; $i++) {
154
                $chunk = $chunkFile.'.'.$i;
155
                $this->files->append(
156
                    $storageFile,
157
                    $this->files->get($chunk)
158
                );
159
                $this->files->delete($chunk);
160
            }
161
        } else {
162 1
            $this->files->move($chunkFile, $storageFile);
163
        }
164
165 1
        return $this->files->createUploadedFile(
166 1
            $storageFile, $this->name, $this->getMimeType()
0 ignored issues
show
It seems like $this->getMimeType() targeting Recca0120\Upload\ChunkFile::getMimeType() can also be of type false; however, Recca0120\Upload\Filesystem::createUploadedFile() does only seem to accept string|null, did you maybe forget to handle an error condition?
Loading history...
167
        );
168
    }
169
170
    /**
171
     * tmpfilename.
172
     *
173
     * @return string
174
     */
175 3
    protected function tmpfilename()
176
    {
177 3
        if (is_null($this->tmpfilename) === true) {
178 3
            $this->tmpfilename = $this->files->tmpfilename($this->name, $this->token);
179
        }
180
181 3
        return $this->tmpfilename;
182
    }
183
184
    /**
185
     * chunkFile.
186
     *
187
     * @return string
188
     */
189 3
    protected function chunkFile()
190
    {
191 3
        return $this->chunkPath.$this->tmpfilename().static::TMPFILE_EXTENSION;
192
    }
193
194
    /**
195
     * storageFile.
196
     *
197
     * @return string
198
     */
199 1
    protected function storageFile()
200
    {
201 1
        return $this->storagePath.$this->tmpfilename();
202
    }
203
}
204