Issues (36)

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/AbstractCache.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
/**
4
 *
5
 * This file is part of the Apix Project.
6
 *
7
 * (c) Franck Cassedanne <franck at ouarz.net>
8
 *
9
 * @license     http://opensource.org/licenses/BSD-3-Clause  New BSD License
10
 *
11
 */
12
13
namespace Apix\Cache;
14
15
/**
16
 * Base class provides the cache wrappers structure.
17
 *
18
 * @author Franck Cassedanne <franck at ouarz.net>
19
 */
20
abstract class AbstractCache implements Adapter
21
{
22
23
    /**
24
     * Holds an injected adapter.
25
     * @var object
26
     */
27
    protected $adapter = null;
28
29
    /**
30
     * @var Serializer\Adapter
31
     */
32
    protected $serializer;
33
34
    /**
35
     * Holds some generic default options.
36
     * @var array
37
     */
38
    protected $options = array(
39
        'prefix_key'        => 'apix-cache-key:', // prefix cache keys
40
        'prefix_tag'        => 'apix-cache-tag:', // prefix cache tags
41
        'tag_enable'        => true               // wether to enable tagging
42
    );
43
44
    /**
45
     * Constructor use to set the adapter and dedicated options.
46
     *
47
     * @param object|null $adapter The adapter to set, generally an object.
48
     * @param array|null  $options The array of user options.
49
     */
50 1881
    public function __construct($adapter=null, array $options=null)
51
    {
52 1881
        $this->adapter = $adapter;
53 1881
        $this->setOptions($options);
54 1881
    }
55
56
    /**
57
     * Sets and merges the options (overriding the default options).
58
     *
59
     * @param array|null $options The array of user options.
60
     */
61 1881
    public function setOptions(array $options=null)
62
    {
63 1881
        if (null !== $options) {
64 1881
            $this->options = $options+$this->options;
65 1881
        }
66 1881
    }
67
68
    /**
69
     * Returns the named option.
70
     *
71
     * @param  string $key
72
     * @return mixed
73
     */
74 750
    public function getOption($key)
75
    {
76 750
        if (!isset($this->options[$key])) {
77 17
            throw new PsrCache\InvalidArgumentException(
78 17
                sprintf('Invalid option "%s"', $key)
79 17
            );
80
        }
81
82 733
        return $this->options[$key];
83
    }
84
85
    /**
86
     * Sets the named option.
87
     *
88
     * @param   string $key
89
     * @param   mixed  $value
90
     */
91 34
    public function setOption($key, $value)
92
    {
93 34
        return $this->options[$key] = $value;
94
    }
95
96
    /**
97
     * Returns a prefixed and sanitased cache id.
98
     *
99
     * @param  string $key The base key to prefix.
100
     * @return string
101
     */
102 1393
    public function mapKey($key)
103
    {
104 1393
        return $this->sanitise($this->options['prefix_key'] . $key);
105
    }
106
107
    /**
108
     * Returns a prefixed and sanitased cache tag.
109
     *
110
     * @param  string $tag The base tag to prefix.
111
     * @return string
112
     */
113 574
    public function mapTag($tag)
114
    {
115 574
        return $this->sanitise($this->options['prefix_tag'] . $tag);
116
    }
117
118
    /**
119
     * Returns a sanitased string for keying/tagging purpose.
120
     *
121
     * @param  string $key The string to sanitise.
122
     * @return string
123
     */
124 1473
    public function sanitise($key)
125
    {
126 1473
        return $key;
127
        // return str_replace(array('/', '\\', ' '), '_', $key);
0 ignored issues
show
Unused Code Comprehensibility introduced by
70% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
128
    }
129
130
    /**
131
     * Gets the injected adapter.
132
     *
133
     * @return object
134
     */
135 83
    public function getAdapter()
136
    {
137 83
        return $this->adapter;
138
    }
139
140
    /**
141
     * Sets the serializer.
142
     *
143
     * @param string $name
144
     */
145 94
    public function setSerializer($name)
146
    {
147 94
        if (null === $name) {
148 17
            $this->serializer = null;
149 17
        } else {
150 94
            $classname = __NAMESPACE__ . '\Serializer\\';
151 94
            $classname .= ucfirst(strtolower($name));
152 94
            $this->serializer = new $classname();
153
        }
154 94
    }
155
156
    /**
157
     * Gets the serializer.
158
     *
159
     * @return Serializer\Adapter
160
     */
161 83
    public function getSerializer()
162
    {
163 83
        return $this->serializer;
164
    }
165
166
    /**
167
     * Retrieves the cache content for the given key or the keys for a given tag.
168
     *
169
     * @param  string     $key  The cache id to retrieve.
170
     * @param  string     $type The type of the key (either 'key' or 'tag').
171
     * @return mixed|null Returns the cached data or null if not set.
172
     */
173 379
    public function load($key, $type='key')
174
    {
175 379
        return $type == 'key' ? $this->loadKey($key) : $this->loadTag($key);
176
    }
177
178
    /**
179
     * Returns the given string without the given prefix.
180
     *
181
     * @param  string $str    The subject string
182
     * @param  string $prefix The prefix to remove
183
     * @return string
184
     */
185 697
    public function removePrefix($str, $prefix)
186
    {
187 697
        return substr($str, 0, strlen($prefix)) == $prefix
188 697
                ? substr($str, strlen($prefix))
189 697
                : $str;
190
    }
191
192
    /**
193
     * Returns the given string without the internal key prefix.
194
     *
195
     * @param  string $str
196
     * @return string
197
     */
198 629
    public function removePrefixKey($str)
199
    {
200 629
        return $this->removePrefix($str, $this->options['prefix_key']);
201
    }
202
203
   /**
204
     * Returns the given string without the internal tag prefix.
205
     *
206
     * @param  string $str
207
     * @return string
208
     */
209 68
    public function removePrefixTag($str)
210
    {
211 68
        return $this->removePrefix($str, $this->options['prefix_tag']);
212
    }
213
214
}
215