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/Asset/AssetPaths.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 namespace Anomaly\Streams\Platform\Asset;
2
3
use Anomaly\Streams\Platform\Application\Application;
4
use Illuminate\Contracts\Config\Repository;
5
use Illuminate\Http\Request;
6
7
/**
8
 * Class AssetPaths
9
 *
10
 * @link   http://pyrocms.com/
11
 * @author PyroCMS, Inc. <[email protected]>
12
 * @author Ryan Thompson <[email protected]>
13
 */
14
class AssetPaths
15
{
16
17
    /**
18
     * Predefined paths.
19
     *
20
     * @var array
21
     */
22
    protected $paths = [];
23
24
    /**
25
     * The config repository.
26
     *
27
     * @var Repository
28
     */
29
    protected $config;
30
31
    /**
32
     * The request object.
33
     *
34
     * @var Request
35
     */
36
    protected $request;
37
38
    /**
39
     * The application object.
40
     *
41
     * @var Application
42
     */
43
    protected $application;
44
45
    /**
46
     * Create a new AssetPaths instance.
47
     *
48
     * @param Repository $config
49
     * @param Request    $request
50
     */
51 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...
52
    {
53
        $this->config      = $config;
54
        $this->request     = $request;
55
        $this->application = $application;
56
57
        $this->paths = $config->get('streams::assets.paths', []);
0 ignored issues
show
Documentation Bug introduced by
It seems like $config->get('streams::assets.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...
58
    }
59
60
    /**
61
     * Get the paths.
62
     *
63
     * @return array|mixed
64
     */
65
    public function getPaths()
66
    {
67
        return $this->paths;
68
    }
69
70
    /**
71
     * Set the paths.
72
     *
73
     * @param  array $paths
74
     * @return $this
75
     */
76
    public function setPaths(array $paths)
77
    {
78
        $this->paths = $paths;
79
80
        return $this;
81
    }
82
83
    /**
84
     * Add an image path hint.
85
     *
86
     * @param $namespace
87
     * @param $path
88
     * @return $this
89
     */
90
    public function addPath($namespace, $path)
91
    {
92
        $this->paths[$namespace] = rtrim($path, '/\\');
93
94
        return $this;
95
    }
96
97
    /**
98
     * Get a single path.
99
     *
100
     * @param $namespace
101
     * @return string|null
102
     */
103
    public function getPath($namespace)
104
    {
105
        return array_get($this->paths, $namespace);
106
    }
107
108
    /**
109
     * Return the hinted extension.
110
     *
111
     * @param $path
112
     * @return string
113
     */
114
    public function hint($path)
115
    {
116
        $hint = $this->extension($path);
117
118
        foreach ($this->config->get('streams::assets.hints', []) as $extension => $hints) {
119
            if (in_array($hint, $hints)) {
120
                return $extension;
121
            }
122
        }
123
124
        return $hint;
125
    }
126
127
    /**
128
     * Return the extension of the path.
129
     *
130
     * @param $path
131
     * @return string
132
     */
133
    public function extension($path)
134
    {
135
        return pathinfo($path, PATHINFO_EXTENSION);
136
    }
137
138
    /**
139
     * Return the real path for a given path.
140
     *
141
     * @param $path
142
     * @return string
143
     * @throws \Exception
144
     */
145
    public function realPath($path)
146
    {
147
        if (str_contains($path, '::')) {
148
149
            list($namespace, $path) = explode('::', $path);
150
151
            if (!isset($this->paths[$namespace])) {
152
                throw new \Exception("Path hint [{$namespace}::{$path}] does not exist!");
153
            }
154
155
            $path = rtrim($this->paths[$namespace], '/') . '/' . $path;
156
        }
157
158
        if (strpos($path, '?v=')) {
159
            $path = substr($path, 0, strpos($path, '?v='));
160
        }
161
162
        return $path;
163
    }
164
165
    /**
166
     * Return the download path for a remote asset.
167
     *
168
     * @param         $url
169
     * @param  null   $path
170
     * @return string
171
     */
172
    public function downloadPath($url, $path = null)
173
    {
174
        if (!$path && $parsed = parse_url($url)) {
175
            $path = array_get($parsed, 'host') . '/' . basename(array_get($parsed, 'path'));
176
        }
177
178
        return $path = $this->outputPath('downloads/' . $path);
0 ignored issues
show
$path 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...
179
    }
180
181
    /**
182
     * Return the output path.
183
     *
184
     * @param $collection
185
     * @return string
186
     */
187
    public function outputPath($collection)
188
    {
189
        /*
190
         * If the path is already public
191
         * then just use it as it is.
192
         */
193
        if (str_contains($collection, public_path())) {
194
            return str_replace(public_path(), '', $collection);
195
        }
196
197
        /*
198
         * Get the real path relative to our installation.
199
         */
200
        $path = str_replace(base_path(), '', $this->realPath($collection));
201
202
        /*
203
         * Build out path parts.
204
         */
205
        $directory   = ltrim(dirname($path), '/\\') . '/';
206
        $application = $this->application->getReference();
207
        $filename    = basename($path, $this->extension($path)) . $this->hint($path);
208
209
        if (starts_with($directory, 'vendor/')) {
210
            $directory = substr($directory, 7);
211
        }
212
213
        if (starts_with($directory, './')) {
214
            $directory = in_array($this->request->segment(1), ['admin', 'installer']) ? 'admin/' : 'public/';
215
        }
216
217
        return "/app/{$application}/assets/{$directory}{$filename}";
218
    }
219
}
220