Issues (14)

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.

src/ImageUploader.php (2 issues)

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 HustleWorks\Chute;
4
5
use HustleWorks\Chute\DTO\ImageConfiguration;
6
use HustleWorks\Chute\Contracts\ImageValidatorInterface;
7
use HustleWorks\Chute\Contracts\ImageRepositoryInterface;
8
use HustleWorks\Chute\Contracts\StorageInterface;
9
use HustleWorks\Chute\DTO\ImageFile;
10
use HustleWorks\Chute\ServiceResponse;
11
use HustleWorks\Chute\StandardServiceResponse;
12
13
abstract class ImageUploader
14
{
15
    /**
16
     * @var ImageValidatorInterface
17
     */
18
    protected $validator;
19
20
    /**
21
     * @var StorageInterface
22
     */
23
    protected $storage;
24
25
    /**
26
     * @var ImageRepositoryInterface
27
     */
28
    protected $image_repo;
29
30
    /**
31
     * ImageUploader constructor.
32
     *
33
     * @param ImageValidatorInterface  $validator
34
     * @param StorageInterface         $storage
35
     * @param ImageRepositoryInterface $image_repo
36
     */
37
    public function __construct(
38
        ImageValidatorInterface $validator,
39
        StorageInterface $storage,
40
        ImageRepositoryInterface $image_repo
41
    )
42
    {
43
        $this->validator  = $validator;
44
        $this->storage    = $storage;
45
        $this->image_repo = $image_repo;
46
    }
47
48
    /**
49
     * Handle Image Upload
50
     *
51
     * @param mixed              $framework_file
52
     * @param ImageConfiguration $config
53
     * @param array              $optional_data
54
     * @return ServiceResponse
55
     */
56
    public function handle($framework_file, ImageConfiguration $config, array $optional_data = [])
57
    {
58
        /* Create ImageFile object for processing */
59
        $image_file = $this->prepareImageFile($framework_file);
60
61
        /* run validation on upload */
62
        $response = $this->validator->validate($image_file, $config->rules);
63
64
        /* if valid create database entry, store image to disk and generate response */
65
        if ($response->success()) {
66
67
            if ($record = $this->image_repo->findExistingImageable($config->optional_data)) {
68
                $this->image_repo->delete($record);
69
            }
70
71
            $record = $this->image_repo->create([
72
                'name'        => $config->image_name,
73
                'disk'        => $config->temp_disk,
74
                'filename'    => $image_file->filename,
75
                'path'        => $config->directory,
76
                'status'      => 'pending',
77
                'width'       => $image_file->width,
78
                'height'      => $image_file->height,
79
                'mime_type'   => $image_file->mime_type,
80
                'extension'   => $image_file->extension,
81
                'size'        => $image_file->size,
82
                'alt'         => $optional_data['alt'] ?? null,
83
                'title'       => $optional_data['title'] ?? null,
84
                'description' => $optional_data['description'] ?? null,
85
            ]);
86
87
            $this->storage->put($image_file->stream, $record->disk, "$record->path/$record->uuid", $record->filename);
0 ignored issues
show
The property $stream is declared protected in HustleWorks\Chute\DTO\ImageFile. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.

Since your code implements the magic setter _set, this function will be called for any write 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.");
        }
    }

}

Since the property has write access only, you can use the @property-write 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...
The property $disk is declared protected in HustleWorks\Chute\DTO\ImageRecord. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.

Since your code implements the magic setter _set, this function will be called for any write 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.");
        }
    }

}

Since the property has write access only, you can use the @property-write 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...
88
            $response = new StandardServiceResponse(true, [
89
                'image' => $record,
90
            ], 'File successfully uploaded');
91
        }
92
93
        return $response;
94
    }
95
96
97
    /**
98
     * Prepare Image File
99
     *
100
     * Take raw upload and convert it to an image file
101
     *
102
     * @param $framework_file
103
     * @return ImageFile
104
     */
105
    abstract protected function prepareImageFile($framework_file): ImageFile;
106
}