Issues (9)

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/UploadController.php (2 issues)

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
namespace samsonphp\upload;
3
4
use samson\core\CompressableExternalModule;
5
6
/**
7
 * SamsonPHP Upload module
8
 *
9
 * @package SamsonPHP
10
 * @author Vitaly Iegorov <[email protected]>
11
 */
12
class UploadController extends CompressableExternalModule
13
{
14
    /** @var string Module identifier */
15
    public $id = 'upload';
16
17
    /** @var  callable External handler to build relative file path */
18
    public $uploadDirHandler;
19
20
    /** @var string Prefix for image path saving in db */
21
    public $pathPrefix = '/';
22
23
    /** @var callable External handler to build file name */
24
    public $fileNameHandler;
25
26
    /** @var \samsonphp\fs\FileService Pointer to file system module */
27
    public $fs;
28
29
    /**
30
     * Init current file system module and server requests handler
31
     */
32
    protected function initFileSystem()
33
    {
34
        /** @var \samsonphp\fs\FileService $fs */
35
        $fs = !isset($this->fs) ? $this->system->module('fs') : $this->fs;
0 ignored issues
show
The property system does not exist on object<samsonphp\upload\UploadController>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
36
37
        // Store pointer to file system module
38
        $this->fs = $fs;
39
    }
40
41
    /**
42
     * Initialize module
43
     * @param array $params Collection of module parameters
44
     * @return bool True if module successfully initialized
45
     */
46
    public function init(array $params = array())
47
    {
48
        // Init FileSystem and ServerHandler
49
        $this->initFileSystem();
50
51
        // If no valid handlers are passed - use generic handlers
52
        if (!isset($this->uploadDirHandler) || !is_callable($this->uploadDirHandler)) {
53
            $this->uploadDirHandler = array($this, 'defaultDirHandler');
54
        }
55
56
        // Call parent initialization
57
        parent::init($params);
58
    }
59
60
    /**
61
     * Default relative path builder handler
62
     * @return string Relative path for uploading
63
     */
64
    public function defaultDirHandler()
65
    {
66
        // Default file path
67
        $path = 'upload';
68
69
        // Create upload dir if it does not present
70
        if (!$this->fs->exists($path)) {
71
            $this->fs->mkDir($path);
72
        }
73
74
        return $path;
75
    }
76
77
    /**
78
     * Returns a file size limit in bytes based on the PHP upload_max_filesize and post_max_size
79
     * @return float Size value
80
     */
81
    public function __async_maxfilesize()
0 ignored issues
show
Method name "UploadController::__async_maxfilesize" is not in camel caps format
Loading history...
82
    {
83
        $sizeString = ini_get('post_max_size');
84
        // Start with post_max_size.
85
        $maxSize = $this->parseSize($sizeString);
86
87
        // If upload_max_size is less, then reduce. Except if upload_max_size is
88
        // zero, which indicates no limit.
89
        $uploadMax = $this->parseSize(ini_get('upload_max_filesize'));
90
        if ($uploadMax > 0 && $uploadMax < $maxSize) {
91
            $maxSize = $uploadMax;
92
            $sizeString = ini_get('upload_max_filesize');
93
        }
94
        return array('status' => true, 'maxSize' => $maxSize, 'sizeString' => $sizeString);
95
    }
96
97
    /**
98
     * Function to get size in bytes
99
     * @param string $size File size string
100
     * @return float Size number
101
     */
102
    private function parseSize($size)
103
    {
104
        // Remove the non-unit characters from the size.
105
        $unit = preg_replace('/[^bkmgtpezy]/i', '', $size);
106
        // Remove the non-numeric characters from the size.
107
        $size = preg_replace('/[^0-9\.]/', '', $size);
108
        if ($unit) {
109
            // Find the position of the unit in the ordered
110
            // string which is the power of magnitude to multiply a kilobyte by.
111
            return round($size * pow(1024, stripos('bkmgtpezy', $unit[0])));
112
        } else {
113
            return round($size);
114
        }
115
    }
116
}
117