Issues (4)

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/Adapters/LocalAdapter.php (2 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
namespace Journey\Cache\Adapters;
4
5
use Journey\Cache\CacheAdapterInterface;
6
use Journey\Cache\CacheException;
7
8
class LocalAdapter implements CacheAdapterInterface
9
{
10
    /**
11
     * A filesystem path to store cache values.
12
     *
13
     * @var string
14
     */
15
    protected $path;
16
17
    /**
18
     * umask value to set on cache files.
19
     *
20
     * @var integer
21
     */
22
    protected $umask = 000;
23
24
    /**
25
     * Initialize a new localcache.
26
     *
27
     * @param string $filepath
28
     */
29 8
    public function __construct($filepath)
30
    {
31 8
        if (!is_dir($filepath)) {
32 1
            throw new CacheException('Cache file path is not a directory.');
33
        }
34 8
        $this->path = rtrim($filepath, "/");
35 8
    }
36
37
    /**
38
     * Must implement a set method.
39
     *
40
     * @param  string $key   key to set as the cache value.
41
     * @param  mixed  $value returns the value of the cached item.
42
     * @return $this
43
     */
44 6
    public function set($key, $value, $expiration = false)
45
    {
46 6
        $path = $this->filename($key);
47 6
        $umask = umask($this->umask);
48 6
        file_put_contents($path, $this->createValue($value, $expiration));
0 ignored issues
show
$expiration is of type boolean, but the function expects a integer.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
49 6
        umask($umask);
50 6
        return $this;
51
    }
52
53
    /**
54
     * Must implement a get method.
55
     *
56
     * @param  string $key   Get a cached item by key.
57
     * @return mixed         Returns cached item or false.
58
     */
59 5
    public function get($key)
60
    {
61 5
        $path = $this->filename($key);
62 5
        $file = @fopen($path, 'r');
63 5
        if (!$file) {
64 2
            return false;
65
        }
66 3
        $timestamp = fgets($file, 11);
67 3
        fclose($file);
68 3
        if ($timestamp > time() || $timestamp == "00000000000") {
69 2
            return substr(file_get_contents($path), 11);
70
        }
71 1
        return false;
72
    }
73
74
    /**
75
     * Must implement a delete method.
76
     *
77
     * @param  string $key delete a specific cached item by key.
78
     * @return $this
79
     */
80 1
    public function delete($key)
81
    {
82 1
        $file = $this->filename($key);
83 1
        unlink($file);
84 1
        return $this;
85
    }
86
87
    /**
88
     * Clear all of the values set by this cache instance.
89
     *
90
     * @return $this
91
     */
92 3
    public function clear()
93
    {
94 3
        $key = $this->key();
0 ignored issues
show
Are you sure the assignment to $key is correct as $this->key() (which targets Journey\Cache\Adapters\LocalAdapter::key()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
95 3
        $files = glob($this->path . "/_cache-" . $key . "*.cache");
96 3
        $this->setKey();
97 3
        $this->key(true);
98 3
        foreach ($files as $file) {
99 3
            unlink($file);
100 3
        }
101 3
        return $this;
102
    }
103
104
    /**
105
     * Returns the filename of a key.
106
     *
107
     * @param  string $key name of the key
108
     * @return void
109
     */
110 6
    public function filename($key)
111
    {
112 6
        return $this->path . "/_cache-" . $this->key() . "-" . md5($key) . ".cache";
113
    }
114
115
    /**
116
     * Create a parsable value from the data and expiration date.
117
     *
118
     * @param  string  $value      value of the store
119
     * @param  integer $expiration integer value of the expiration (unix timestamp)
120
     * @return void
121
     */
122 6
    public function createValue($value, $expiration)
123
    {
124 6
        $expiration = $expiration ? str_pad($expiration, 11, "0". STR_PAD_LEFT) : "00000000000";
125 6
        return $expiration . $value;
126
    }
127
128
    /**
129
     * Gets the current cache namespace key.
130
     *
131
     * Note: to save on time spent reading/writing to disk, this method uses
132
     * static caching. Its important that when a cache key gets reset this
133
     * method has it's local cache reset by passing `true`.
134
     *
135
     * @param  boolean $reset resets the static cache.
136
     * @return void
137
     */
138 6
    public function key($reset = false)
139
    {
140 6
        static $key;
141 6
        $key = $reset ? false : $key;
142 6
        if (!$key) {
143 4
            $path = $this->path . "/.cache_key";
144 4
            if (file_exists($path)) {
145 3
                $key = file_get_contents($path);
146 3
            } else {
147 1
                $key = $this->setKey();
148
            }
149 4
        }
150 6
        return $key;
151
    }
152
153
    /**
154
     * Set the current cache key.
155
     */
156 4
    public function setKey()
157
    {
158 4
        $path = $this->path . "/.cache_key";
159 4
        $key = bin2hex(openssl_random_pseudo_bytes(6));
160 4
        $umask = umask($this->umask);
161 4
        file_put_contents($path, $key);
162 4
        umask($umask);
163 4
        return $key;
164
    }
165
}
166