Issues (165)

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/Cache/CFileCache.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
namespace Anax\Cache;
4
5
/**
6
 * File based cache.
7
 *
8
 */
9
class CFileCache
10
{
11
    use \Anax\TConfigure;
12
13
14
15
    /**
16
     * Create a key to use for the cache.
17
     *
18
     * @param string $class name of the class, including
19
     *                      namespace.
20
     * @param string $id    unique id for item in each class.
21
     *
22
     * @return string the filename.
23
     */
24
    public function createKey($class, $id)
25
    {
26
        return str_replace('\\', '-', $class) . '#' . $id;
27
    }
28
29
30
31
    /**
32
     * Generate a filename for the cached object.
33
     *
34
     * @param string $key to the cached object.
35
     *
36
     * @return string the filename.
37
     */
38
    public function filename($key)
39
    {
40
        return $this->config['basepath'] . '/' . $key;
41
    }
42
43
44
45
    /**
46
     * Get an item from the cache if available.
47
     *
48
     * @param string  $key to the cached object.
49
     * @param boolean $age check the age or not, defaults to
50
     *                     false.
51
     *
52
     * @return mixed the cached object or false if it has aged
53
     *               or null if it does not exists.
54
     */
55
    public function get($key, $age = false)
56
    {
57
        $file = $this->filename($key);
58
59
        if (is_file($file)) {
60
            if ($age) {
61
                $age = filemtime($file) + $this->config['age'] > time();
62
            }
63
64
            if (!$age) {
65
                // json
66
                // text
67
                return unserialize(file_get_contents($file));
68
            }
69
            return false;
70
        }
71
        return null;
72
    }
73
74
75
76
    /**
77
     * Put an item to the cache.
78
     *
79
     * @param string $key  to the cached object.
80
     * @param mixed  $item the object to be cached.
81
     *
82
     * @throws Exception if failing to write to cache.
83
     *
84
     * @return void
85
     */
86
    public function put($key, $item)
87
    {
88
        $file = $this->filename($key);
89
90
        // json
91
        // text
92
        if (!file_put_contents($file, serialize($item))) {
93
            throw new \Exception(
94
                t("Failed writing cache object '!key'.", [
95
                    '!key' => $key
96
                ])
97
            );
98
        }
99
    }
100
101
102
103
    /**
104
     * Prune a item from cache.
105
     *
106
     * @param string $key to the cached object.
107
     *
108
     * @return void
109
     */
110
    public function prune($key)
111
    {
112
        @unlink($this->filename($key));
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
113
    }
114
115
116
117
    /**
118
     * Prune all items from cache.
119
     *
120
     * @return int number of items removed.
121
     */
122
    public function pruneAll()
123
    {
124
        $files = glob($this->config['basepath'] . '/*');
125
        $items = count($files);
126
        array_map('unlink', $files);
127
        return $items;
128
    }
129
}
130