Issues (126)

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.

code/CloudAssets.php (6 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
 * Central interface for cloud assets module.
4
 *
5
 * @author Mark Guinn <[email protected]>
6
 * @date 01.10.2014
7
 * @package cloudassets
8
 */
9
class CloudAssets extends SS_Object
10
{
11
    /** @var bool - kill switch via config - if true the module will ignore all cloud buckets */
12
    private static $disabled = false;
13
14
    /** @var bool - kill switch for uploading local changes to the cdn - useful for safeguarding local development environments */
15
    private static $uploads_disabled = false;
16
17
    /** @var bool - if this is set to true, the uploads will only occur when running UpdateCloudAssetsTask or CloudAssetsFullCheckTask */
18
    // COMING SOON
19
    //private static $offline_uploads_only = false;
20
21
    /** @var bool - you probably want this true overall, but in some cases like BuildTasks we may not want that */
22
    // COMING SOON
23
    //private static $fail_silently = true;
24
25
    /** @var string - if you have Monolog or something registered with the Injector - anything with info, error, and debug methods */
26
    private static $logger = '';
27
28
    /** @var array */
29
    private static $map = array(
30
        //'assets/folder/path' => array(
31
        //  'Type'      => 'RackspaceBucket',
32
        //  'BaseURL'   => 'http://cdnurl.com/',
33
        //  'SecureURL' => 'https://cdnurl.com/',
34
        //  'Container' => 'container-name',
35
        //  'UserID'    => 'username',
36
        //  'ApiKey'    => 'key',
37
        //  'LocalCopy' => true,
38
        //);
39
    );
40
41
    /** @var array - merged in with all bucket configs */
42
    private static $defaults = array();
43
44
    /** @var array - add to this if you have other file subclasses floating around */
45
    private static $wrappers = array(
46
        'File'              => 'CloudFile',
47
        'Image'             => 'CloudImage',
48
        'CloudImageCached'  => 'CloudImageCached', // this is awkward but prevents it from trying to transform Image_Cached
49
    );
50
51
    /** @var string - placeholder string used for local files */
52
    private static $file_placeholder = 'CloudFile';
53
54
    /** @var string - if an image is missing on the remote (usually when creating a thumbnail) use this instead */
55
    private static $missing_image = 'cloudassets/images/missing.svg';
56
57
    /** @var array - only keep one instance of each bucket */
58
    protected $bucketCache = array();
59
60
61
    /**
62
     * @return CloudAssets
63
     */
64
    public static function inst()
65
    {
66
        return Injector::inst()->get('CloudAssets');
67
    }
68
69
70
    /**
71
     * @param string|File $filename
72
     * @return CloudBucket
73
     */
74
    public function map($filename)
75
    {
76
        if (Config::inst()->get('CloudAssets', 'disabled')) {
77
            return null;
78
        }
79
        if (is_object($filename)) {
80
            $filename = $filename->getFilename();
81
        }
82
        $maps = Config::inst()->get('CloudAssets', 'map');
83
84
        foreach ($maps as $path => $cfg) {
0 ignored issues
show
The expression $maps of type array|integer|double|string|boolean is not guaranteed to be traversable. How about adding an additional type check?

There are different options of fixing this problem.

  1. If you want to be on the safe side, you can add an additional type-check:

    $collection = json_decode($data, true);
    if ( ! is_array($collection)) {
        throw new \RuntimeException('$collection must be an array.');
    }
    
    foreach ($collection as $item) { /** ... */ }
    
  2. If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:

    /** @var array $collection */
    $collection = json_decode($data, true);
    
    foreach ($collection as $item) { /** .. */ }
    
  3. Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.

Loading history...
85
            $this->getLogger()->debug("checking $path against $filename => ".strpos($filename, $path));
86
            if (strpos($filename, $path) === 0) {
87
                if (!isset($this->bucketCache[$path])) {
88
                    // merge in default config if needed
89
                    $defaults = Config::inst()->get('CloudAssets', 'defaults');
90
                    if (!empty($defaults) && is_array($defaults)) {
91
                        $cfg = array_merge($defaults, $cfg);
92
                    }
93
                    if (empty($cfg[ CloudBucket::TYPE ])) {
94
                        continue;
95
                    }
96
97
                    // instantiate the bucket
98
                    $this->bucketCache[$path] = Injector::inst()->create($cfg[CloudBucket::TYPE], $path, $cfg);
99
                }
100
101
                $this->getLogger()->debug("CloudAssets: Mapping $filename to bucket $path");
102
                return $this->bucketCache[$path];
103
            }
104
        }
105
106
        $this->getLogger()->debug("CloudAssets: No mapping found for $filename - ");
107
        return null;
108
    }
109
110
111
    /**
112
     * Updates the cloud status of all files (used in tests and cron job)
113
     */
114
    public function updateAllFiles()
115
    {
116
        foreach (File::get() as $f) {
117
            $f->updateCloudStatus();
118
        }
119
    }
120
121
122
    /**
123
     * @param string $className
124
     * @return string
125
     */
126
    public function getWrapperClass($className)
127
    {
128
        $wrappers = Config::inst()->get('CloudAssets', 'wrappers');
129
        // Needs to be wrapped
130
        if (isset($wrappers[$className])) {
131
            return $wrappers[$className];
132
        }
133
        // Already wrapped
134
        if (in_array($className, $wrappers, true)) {
135
            return $className;
136
        }
137
        // Can't be wrapped
138
        return null;
139
    }
140
141
142
    /**
143
     * Wipes out any buckets we've saved
144
     */
145
    public function clearBucketCache()
146
    {
147
        $this->bucketCache = array();
148
    }
149
150
151
    /**
152
     * @return object
153
     */
154
    public function getLogger()
155
    {
156
        $service = Config::inst()->get('CloudAssets', 'logger');
157
        $inj = Injector::inst();
158
        if (!empty($service) && $inj->hasService($service)) {
159
            return $inj->get($service);
160
        } else {
161
            return $inj->get('CloudAssets_NullLogger');
162
        }
163
    }
164
}
165
166
167
class CloudAssets_NullLogger
168
{
169
    public function log($str)
0 ignored issues
show
The parameter $str is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
170
    {
171
    }
172
    public function info($str)
0 ignored issues
show
The parameter $str is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
173
    {
174
    }
175
    public function debug($str)
0 ignored issues
show
The parameter $str is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
176
    {
177
    }
178
    public function warn($str)
0 ignored issues
show
The parameter $str is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
179
    {
180
    }
181
    public function error($str)
0 ignored issues
show
The parameter $str is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
182
    {
183
    }
184
}
185