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/ImageProcessor.php (4 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
3
4
namespace HustleWorks\Chute;
5
6
use HustleWorks\Chute\DTO\ImageConfiguration;
7
use HustleWorks\Chute\DTO\ImageRecord;
8
use HustleWorks\Chute\Contracts\ImageRepositoryInterface;
9
use HustleWorks\Chute\Contracts\ImageTransformationRepositoryInterface;
10
use HustleWorks\Chute\Contracts\StorageInterface;
11
use HustleWorks\Chute\ImageEditor;
12
13
abstract class ImageProcessor
14
{
15
    /**
16
     * @var StorageInterface
17
     */
18
    private $storage;
19
20
    /**
21
     * @var ImageRepositoryInterface
22
     */
23
    private $image_repo;
24
25
    /**
26
     * @var ImageTransformationRepositoryInterface
27
     */
28
    private $image_transformation_repo;
29
30
    /**
31
     * ImageProcessor constructor.
32
     *
33
     * @param StorageInterface $storage
34
     * @param                  $image_repo
35
     * @param                  $image_transformation_repo
36
     */
37
    public function __construct(
38
        StorageInterface $storage,
39
        ImageRepositoryInterface $image_repo,
40
        ImageTransformationRepositoryInterface $image_transformation_repo
41
    )
42
    {
43
        $this->storage                   = $storage;
44
        $this->image_repo                = $image_repo;
45
        $this->image_transformation_repo = $image_transformation_repo;
46
    }
47
48
    /**
49
     * Handle Processing
50
     *
51
     * @param ImageRecord        $record
52
     * @param ImageConfiguration $config
53
     * @return StandardServiceResponse
54
     */
55
    public function handle(ImageRecord $record, ImageConfiguration $config)
56
    {
57
        /* build path */
58
        $path_to_record = "$record->path/$record->uuid/$record->filename";
59
60
        /* get file from storage */
61
        $image = $this->storage->get($record->disk, $path_to_record);
0 ignored issues
show
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...
62
63
        /* move file to primary storage if not already there */
64
        if ($record->disk !== $config->primary_disk) {
0 ignored issues
show
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...
65
            $this->storage->move($path_to_record, $path_to_record, $record->disk, $config->primary_disk);
0 ignored issues
show
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...
66
            $this->image_repo->update($record, ['disk' => $config->primary_disk]);
67
        }
68
69
        /* create transformation for each size */
70
        $transformation_records = $this->_createTransformations($image, $config, $record);
71
72
        $this->image_repo->update($record, ['status' => 'complete']);
73
74
        return new StandardServiceResponse(
75
            true,
76
            ['image' => $record, 'image_transformations' => $transformation_records],
77
            'Image processing completed successfully'
78
        );
79
    }
80
81
    /**
82
     * Create Transformations
83
     *
84
     * @param                    $image
85
     * @param ImageConfiguration $config
86
     * @param ImageRecord        $image_record
87
     * @return array
88
     */
89
    private function _createTransformations($image, ImageConfiguration $config, ImageRecord $image_record)
90
    {
91
        foreach ($config->sizes as $size) {
92
            /* create filename */
93
            $fn = $size->prefix .
94
                str_replace(".$image_record->extension", '', $image_record->filename) .
95
                "$size->suffix.$image_record->extension";
96
97
            /* initialize fluent image editor */
98
            $editor = new ImageEditor($image);
99
100
            /* create transformation */
101
            $transformed_image = $editor->resize($size->width, $size->height)->setQuality($size->quality)->getStream();
102
103
            /* store on disk */
104
            $size_on_disk = $this->storage->put($transformed_image, $config->primary_disk, "$image_record->path/$image_record->uuid", $fn);
105
106
            /* create record */
107
            $transformation_records[] = $this->image_transformation_repo->create([
0 ignored issues
show
Coding Style Comprehensibility introduced by
$transformation_records was never initialized. Although not strictly required by PHP, it is generally a good practice to add $transformation_records = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
108
                'name'     => $size->name,
109
                'filename' => $fn,
110
                'disk'     => $config->primary_disk,
111
                'width'    => $size->width ?? round($size->height / $image_record->height * $image_record->width),
112
                'height'   => $size->height ?? round($size->width / $image_record->width * $image_record->height),
113
                'quality'  => $size->quality,
114
                'size'     => $size_on_disk,
115
            ], $image_record);
116
        }
117
118
        return $transformation_records ?? [];
119
    }
120
}