Issues (1191)

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/Image/ImagePaths.php (7 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 namespace Anomaly\Streams\Platform\Image;
2
3
use Anomaly\FilesModule\File\Contract\FileInterface;
4
use Anomaly\Streams\Platform\Application\Application;
5
use Illuminate\Contracts\Config\Repository;
6
use Illuminate\Http\Request;
7
8
/**
9
 * Class ImagePaths
10
 *
11
 * @link   http://pyrocms.com/
12
 * @author PyroCMS, Inc. <[email protected]>
13
 * @author Ryan Thompson <[email protected]>
14
 */
15
class ImagePaths
16
{
17
18
    /**
19
     * Predefined paths.
20
     *
21
     * @var array
22
     */
23
    protected $paths = [];
24
25
    /**
26
     * The config repository.
27
     *
28
     * @var Repository
29
     */
30
    protected $config;
31
32
    /**
33
     * The request object.
34
     *
35
     * @var Request
36
     */
37
    protected $request;
38
39
    /**
40
     * The application object.
41
     *
42
     * @var Application
43
     */
44
    protected $application;
45
46
    /**
47
     * Create a new ImagePaths instance.
48
     *
49
     * @param Repository  $config
50
     * @param Request     $request
51
     * @param Application $application
52
     */
53 View Code Duplication
    public function __construct(Repository $config, Request $request, Application $application)
0 ignored issues
show
You have injected the Request via parameter $request. This is generally not recommended as there might be multiple instances during a request cycle (f.e. when using sub-requests). Instead, it is recommended to inject the RequestStack and retrieve the current request each time you need it via getCurrentRequest().
Loading history...
This method seems to be duplicated in 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...
54
    {
55
        $this->config      = $config;
56
        $this->request     = $request;
57
        $this->application = $application;
58
59
        $this->paths = $config->get('streams::images.paths', []);
0 ignored issues
show
Documentation Bug introduced by
It seems like $config->get('streams::images.paths', array()) of type * is incompatible with the declared type array of property $paths.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
60
    }
61
62
    /**
63
     * Get the paths.
64
     *
65
     * @return array|mixed
66
     */
67
    public function getPaths()
68
    {
69
        return $this->paths;
70
    }
71
72
    /**
73
     * Set the paths.
74
     *
75
     * @param  array $paths
76
     * @return $this
77
     */
78
    public function setPaths(array $paths)
79
    {
80
        $this->paths = $paths;
81
82
        return $this;
83
    }
84
85
    /**
86
     * Add an image path hint.
87
     *
88
     * @param $namespace
89
     * @param $path
90
     * @return $this
91
     */
92
    public function addPath($namespace, $path)
93
    {
94
        $this->paths[$namespace] = rtrim($path, '/\\');
95
96
        return $this;
97
    }
98
99
    /**
100
     * Return the real path for a given path.
101
     *
102
     * @param $path
103
     * @return string
104
     * @throws \Exception
105
     */
106
    public function realPath($path)
107
    {
108
        if (str_contains($path, '::')) {
109
            list($namespace, $path) = explode('::', $path);
110
111
            if (!isset($this->paths[$namespace])) {
112
                throw new \Exception("Path hint [{$namespace}::{$path}] does not exist!");
113
            }
114
115
            return rtrim($this->paths[$namespace], '/') . '/' . $path;
116
        }
117
118
        return $path;
119
    }
120
121
    /**
122
     * Return the output path for an image.
123
     *
124
     * @param $path
125
     * @return string
126
     */
127
    public function outputPath(Image $image)
128
    {
129
        $path = $image->getImage();
130
131
        if ($path instanceof FileInterface) {
0 ignored issues
show
The class Anomaly\FilesModule\File\Contract\FileInterface does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
132
            $path = $path->path();
133
        }
134
135
        /*
136
         * If the path is already public
137
         * then just use it as it is.
138
         */
139
        if (str_contains($path, public_path())) {
140
            return str_replace(public_path(), '', $path);
141
        }
142
143
        /*
144
         * If the path is a file or file path then
145
         * put it in /app/{$application}/files/disk/folder/filename.ext
146
         */
147
        if (is_string($path) && str_is('*://*', $path)) {
148
149
            $application = $this->application->getReference();
150
151
            list($disk, $folder, $filename) = explode('/', str_replace('://', '/', $path));
152
153 View Code Duplication
            if ($image->getAlterations() || $image->getQuality()) {
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...
154
                $filename = md5(
155
                        var_export([$path, $image->getAlterations()], true) . $image->getQuality()
156
                    ) . '.' . $image->getExtension();
157
            }
158
            
159
            if ($rename = $image->getFilename()) {
160
161
                $filename = $rename;
162
163
                if (strpos($filename, DIRECTORY_SEPARATOR)) {
164
                    $directory = null;
0 ignored issues
show
$directory is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
165
                }
166
            }
167
168
            return "/app/{$application}/files/{$disk}/{$folder}/{$filename}";
169
        }
170
171
        /*
172
         * Get the real path relative to our installation.
173
         */
174
        $path = str_replace(base_path(), '', $this->realPath($path));
175
176
        /*
177
         * Build out path parts.
178
         */
179
        $filename    = basename($path);
180
        $directory   = ltrim(dirname($path), '/\\') . '/';
181
        $application = $this->application->getReference();
182
183 View Code Duplication
        if ($image->getAlterations() || $image->getQuality()) {
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...
184
            $filename = md5(
185
                    var_export([$path, $image->getAlterations()], true) . $image->getQuality()
186
                ) . '.' . $image->getExtension();
187
        }
188
189
        if ($rename = $image->getFilename()) {
190
            $directory = null;
191
            $filename  = ltrim($rename, '/\\');
192
        }
193
194
        return "/app/{$application}/assets/{$directory}{$filename}";
195
    }
196
}
197