Issues (1240)

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.

system/libraries/Cache.php (5 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 defined('SYSPATH') or die('No direct access allowed.');
2
/**
3
 * Provides a driver-based interface for finding, creating, and deleting cached
4
 * resources. Caches are identified by a unique string. Tagging of caches is
5
 * also supported, and caches can be found and deleted by id or tag.
6
 *
7
 * $Id: Cache.php 4321 2009-05-04 01:39:44Z kiall $
8
 *
9
 * @package    Cache
10
 * @author     Kohana Team
11
 * @copyright  (c) 2007-2008 Kohana Team
12
 * @license    http://kohanaphp.com/license.html
13
 */
14
class Cache_Core
15
{
16
    protected static $instances = array();
17
18
    // For garbage collection
19
    protected static $loaded;
20
21
    // Configuration
22
    protected $config;
23
24
    // Driver object
25
    protected $driver;
26
27
    /**
28
     * Returns a singleton instance of Cache.
29
     *
30
     * @param   string  configuration
31
     * @return  Cache_Core
32
     */
33 View Code Duplication
    public static function & instance($config = false)
0 ignored issues
show
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...
34
    {
35
        if (! isset(Cache::$instances[$config])) {
36
            // Create a new instance
37
            Cache::$instances[$config] = new Cache($config);
38
        }
39
40
        return Cache::$instances[$config];
41
    }
42
43
    /**
44
     * Loads the configured driver and validates it.
45
     *
46
     * @param   array|string  custom configuration or config group name
47
     * @return  void
0 ignored issues
show
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

Loading history...
48
     */
49
    public function __construct($config = false)
50
    {
51 View Code Duplication
        if (is_string($config)) {
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...
52
            $name = $config;
53
54
            // Test the config group name
55
            if (($config = Kohana::config('cache.'.$config)) === null) {
56
                throw new Kohana_Exception('cache.undefined_group', $name);
57
            }
58
        }
59
60
        if (is_array($config)) {
61
            // Append the default configuration options
62
            $config += Kohana::config('cache.default');
63
        } else {
64
            // Load the default group
65
            $config = Kohana::config('cache.default');
66
        }
67
68
        // Cache the config in the object
69
        $this->config = $config;
70
71
        // Set driver name
72
        $driver = 'Cache_'.ucfirst($this->config['driver']).'_Driver';
73
74
        // Load the driver
75 View Code Duplication
        if (! Kohana::auto_load($driver)) {
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...
76
            throw new Kohana_Exception('core.driver_not_found', $this->config['driver'], get_class($this));
77
        }
78
79
        // Initialize the driver
80
        $this->driver = new $driver($this->config['params']);
81
82
        // Validate the driver
83 View Code Duplication
        if (! ($this->driver instanceof Cache_Driver)) {
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...
84
            throw new Kohana_Exception('core.driver_implements', $this->config['driver'], get_class($this), 'Cache_Driver');
85
        }
86
87
        Kohana::log('debug', 'Cache Library initialized');
88
89
        if (Cache::$loaded !== true) {
90
            $this->config['requests'] = (int) $this->config['requests'];
91
92
            if ($this->config['requests'] > 0 and mt_rand(1, $this->config['requests']) === 1) {
93
                // Do garbage collection
94
                $this->driver->delete_expired();
95
96
                Kohana::log('debug', 'Cache: Expired caches deleted.');
97
            }
98
99
            // Cache has been loaded once
100
            Cache::$loaded = true;
101
        }
102
    }
103
104
    /**
105
     * Fetches a cache by id. NULL is returned when a cache item is not found.
106
     *
107
     * @param   string  cache id
108
     * @return  mixed   cached data or NULL
109
     */
110
    public function get($id)
111
    {
112
        // Sanitize the ID
113
        $id = $this->sanitize_id($id);
114
115
        return $this->driver->get($id);
116
    }
117
118
    /**
119
     * Fetches all of the caches for a given tag. An empty array will be
120
     * returned when no matching caches are found.
121
     *
122
     * @param   string  cache tag
123
     * @return  array   all cache items matching the tag
124
     */
125
    public function find($tag)
126
    {
127
        return $this->driver->find($tag);
128
    }
129
130
    /**
131
     * Set a cache item by id. Tags may also be added and a custom lifetime
132
     * can be set. Non-string data is automatically serialized.
133
     *
134
     * @param   string        unique cache id
135
     * @param   mixed         data to cache
136
     * @param   array|string  tags for this item
137
     * @param   integer       number of seconds until the cache expires
138
     * @return  boolean
139
     */
140
    public function set($id, $data, $tags = null, $lifetime = null)
141
    {
142
        if (is_resource($data)) {
143
            throw new Kohana_Exception('cache.resources');
144
        }
145
146
        // Sanitize the ID
147
        $id = $this->sanitize_id($id);
148
149
        if ($lifetime === null) {
150
            // Get the default lifetime
151
            $lifetime = $this->config['lifetime'];
152
        }
153
154
        return $this->driver->set($id, $data, (array) $tags, $lifetime);
155
    }
156
157
    /**
158
     * Delete a cache item by id.
159
     *
160
     * @param   string   cache id
161
     * @return  boolean
162
     */
163
    public function delete($id)
164
    {
165
        // Sanitize the ID
166
        $id = $this->sanitize_id($id);
167
168
        return $this->driver->delete($id);
169
    }
170
171
    /**
172
     * Delete all cache items with a given tag.
173
     *
174
     * @param   string   cache tag name
175
     * @return  boolean
176
     */
177
    public function delete_tag($tag)
178
    {
179
        return $this->driver->delete($tag, true);
180
    }
181
182
    /**
183
     * Delete ALL cache items items.
184
     *
185
     * @return  boolean
186
     */
187
    public function delete_all()
188
    {
189
        return $this->driver->delete(true);
190
    }
191
192
    /**
193
     * Replaces troublesome characters with underscores.
194
     *
195
     * @param   string   cache id
196
     * @return  string
197
     */
198
    protected function sanitize_id($id)
199
    {
200
        // Change slashes and spaces to underscores
201
        return str_replace(array('/', '\\', ' '), '_', $id);
202
    }
203
} // End Cache
204