Issues (12)

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/Models/Image.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 HustleWorks\ChuteLaravel\Models;
4
5
use Illuminate\Database\Eloquent\Builder;
6
use Illuminate\Database\Eloquent\Model;
7
use Ramsey\Uuid\Uuid;
8
9
/**
10
 * \HustleWorks\ChuteLaravel\Models\Image
11
 *
12
 * @property int                                                                                           $id
13
 * @property int|null                                                                                      $imageable_id
14
 * @property string|null                                                                                   $imageable_type
15
 * @property string                                                                                        $name
16
 * @property string                                                                                        $filename
17
 * @property string                                                                                        $disk
18
 * @property string                                                                                        $directory
19
 * @property string                                                                                        $uuid
20
 * @property string                                                                                        $path
21
 * @property string                                                                                        $status
22
 * @property string|null                                                                                   $width
23
 * @property string|null                                                                                   $height
24
 * @property int|null                                                                                      $size_in_kilobytes
25
 * @property string|null                                                                                   $mime_type
26
 * @property string|null                                                                                   $caption
27
 * @property \Carbon\Carbon|null                                                                           $created_at
28
 * @property \Carbon\Carbon|null                                                                           $updated_at
29
 * @property-read \Illuminate\Database\Eloquent\Collection|\HustleWorks\ChuteLaravel\Models\ImageTransformation[] $imageTransformations
30
 * @property-read \Illuminate\Database\Eloquent\Model|\Eloquent                                            $imageable
31
 * @method static Builder|Image whereCaption($value)
32
 * @method static Builder|Image whereCreatedAt($value)
33
 * @method static Builder|Image whereDirectory($value)
34
 * @method static Builder|Image whereDisk($value)
35
 * @method static Builder|Image whereHeight($value)
36
 * @method static Builder|Image whereId($value)
37
 * @method static Builder|Image whereImageableId($value)
38
 * @method static Builder|Image whereImageableType($value)
39
 * @method static Builder|Image whereMimeType($value)
40
 * @method static Builder|Image whereName($value)
41
 * @method static Builder|Image wherePath($value)
42
 * @method static Builder|Image whereSizeInKilobytes($value)
43
 * @method static Builder|Image whereStatus($value)
44
 * @method static Builder|Image whereUpdatedAt($value)
45
 * @method static Builder|Image whereUuid($value)
46
 * @method static Builder|Image whereWidth($value)
47
 * @mixin \Eloquent
48
 */
49
class Image extends Model
50
{
51
    protected $fillable = [
52
        'disk',
53
        'name',
54
        'filename',
55
        'path',
56
        'size',
57
        'status',
58
        'width',
59
        'height',
60
        'mime_type',
61
        'extension',
62
        'alt',
63
        'title',
64
        'description',
65
    ];
66
67
    public function getTransformationUrl($name)
68
    {
69
        /** @var ImageTransformation $transformation */
70
        $transformation = $this->imageTransformations()->where('name', $name)->first();
71
72
        return $transformation->imageUrl();
73
    }
74
75
    public function getOriginalUrl()
76
    {
77
        return \Storage::disk($this->disk)->url("$this->path/$this->uuid/$this->filename");
78
    }
79
80
    /**
81
     * Image Transformations
82
     *
83
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
84
     */
85
    public function imageTransformations()
86
    {
87
        return $this->hasMany(ImageTransformation::class);
88
    }
89
90
    /**
91
     * Imageable
92
     *
93
     * @return \Illuminate\Database\Eloquent\Relations\MorphTo
94
     */
95
    public function imageable()
96
    {
97
        return $this->morphTo();
98
    }
99
100
    /**
101
     * The "booting" method of the model.
102
     *
103
     * @return void
104
     */
105
    protected static function boot()
106
    {
107
        parent::boot();
108
109
        static::creating(function (Image $model) {
110
            // Don't let people provide their own UUIDs, we will generate a proper one.
111
            $model->uuid = Uuid::uuid4()->toString();
112
        });
113
114
        static::saving(function (Image $model) {
115
            // What's that, trying to change the UUID huh?  Nope, not gonna happen.
116
            $original_uuid = $model->getOriginal('uuid');
117
118
            if ($original_uuid !== $model->uuid) {
119
                $model->uuid = $original_uuid;
120
            }
121
        });
122
123 View Code Duplication
        static::deleting(function (Image $image_original) {
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
124
125
            /* if the original is deleted all transformations must be deleted */
126
            foreach ($image_original->imageTransformations as $transformation) {
127
                $transformation->delete();
128
            }
129
130
            /* get the path */
131
            $path = "$image_original->directory/$image_original->uuid/$image_original->path";
132
133
            /* delete the saved file */
134
            if (\Storage::disk($image_original->disk)->exists($path)) {
135
                \Storage::disk($image_original->disk)->delete($path);
136
            }
137
138
            /* delete the directory */
139
            if (!\Storage::disk($image_original->disk)->files("$image_original->directory/$image_original->uuid")) {
140
                \Storage::disk($image_original->disk)->deleteDirectory("$image_original->directory/$image_original->uuid");
141
            }
142
        });
143
    }
144
}
145