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/FileAPI.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
class FileAPI extends Api
6
{
7
    /**
8
     * receive.
9
     *
10
     * @param string $name
11
     * @return \Symfony\Component\HttpFoundation\File\UploadedFile
12
     *
13
     * @throws \Recca0120\Upload\Exceptions\ChunkedResponseException
14
     */
15 4
    public function receive($name)
16
    {
17 4
        $contentDisposition = (string) $this->request->header('content-disposition');
18 4
        if (empty($contentDisposition) === true) {
19 1
            return $this->request->file($name);
20
        }
21
22 3
        list($start, $end, $total) = $this->parseContentRange();
23 3
        $originalName = $this->getOriginalName($contentDisposition);
24 3
        $mimeType = $this->getMimeType($originalName);
25 3
        $uuid = $this->request->get('token');
26 3
        $completed = $end >= $total - 1;
27
28 3
        $chunkFile = $this->createChunkFile($originalName, $mimeType, $uuid);
0 ignored issues
show
It seems like $mimeType defined by $this->getMimeType($originalName) on line 24 can also be of type false; however, Recca0120\Upload\Api::createChunkFile() does only seem to accept string|null, did you maybe forget to handle an error condition?

This check looks for type mismatches where the missing type is false. This is usually indicative of an error condtion.

Consider the follow example

<?php

function getDate($date)
{
    if ($date !== null) {
        return new DateTime($date);
    }

    return false;
}

This function either returns a new DateTime object or false, if there was an error. This is a typical pattern in PHP programming to show that an error has occurred without raising an exception. The calling code should check for this returned false before passing on the value to another function or method that may not be able to handle a false.

Loading history...
29 3
        $chunkFile->appendStream('php://input', $start);
30
31 3
        return $completed === true
32 2
            ? $chunkFile->createUploadedFile()
33 1
            : $chunkFile->throwException([
34
                'files' => [
35 1
                    'name' => $originalName,
36 1
                    'size' => $end,
37 1
                    'type' => $chunkFile->getMimeType(),
38
                ],
39 3
            ], ['X-Last-Known-Byte' => $end]);
40
    }
41
42
    /**
43
     * getOriginalName.
44
     *
45
     * @param string $contentDisposition
46
     * @return string
47
     */
48 3
    protected function getOriginalName($contentDisposition)
49
    {
50 3
        $originalName = (string) $this->request->get('name');
51 3
        if (empty($originalName) === true) {
52 3
            list($originalName) = sscanf(
53 3
                $contentDisposition,
54 3
                'attachment; filename=%s'
55
            );
56
        }
57
58 3
        return preg_replace('/[\'"]/', '', $originalName);
59
    }
60
61
    /**
62
     * getMimeType.
63
     *
64
     * @param string $originalName
65
     * @return string
66
     */
67 3
    protected function getMimeType($originalName)
68
    {
69 3
        $mimeType = (string) $this->request->header('content-type');
70 3
        if (empty($mimeType) === true) {
71
            $mimeType = $this->files->mimeType($originalName);
72
        }
73
74 3
        return $mimeType;
75
    }
76
77
    /**
78
     * parseContentRange.
79
     *
80
     * @return array
81
     */
82 3
    protected function parseContentRange()
83
    {
84 3
        $contentRange = $this->request->header('content-range');
85 3
        if (empty($contentRange) === false) {
86 2
            return sscanf($contentRange, 'bytes %d-%d/%d');
87
        }
88
89 1
        $total = $end = (int) $this->request->header('content-length');
90
91 1
        return [0, $end, $total];
92
    }
93
}
94