Issues (28)

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/Cache/ArrayCache.php (1 issue)

Labels
Severity

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 BenTools\Currency\Cache;
4
5
use Psr\SimpleCache\CacheInterface;
6
use Traversable;
7
8
class ArrayCache implements CacheInterface
9
{
10
11
    private $defaultTtl;
12
    private $storage = [];
13
    private $expiries = [];
14
15
    /**
16
     * ArrayCache constructor.
17
     * @param int|null $defaultTtl
18
     */
19
    public function __construct(int $defaultTtl = null)
20
    {
21
        $this->defaultTtl = $defaultTtl;
22
    }
23
24
    /**
25
     * @inheritDoc
26
     */
27
    public function get($key, $default = null)
28
    {
29
        if ($this->has($key)) {
30
            return $this->storage[$key];
31
        }
32
        if ($this->isExpired($key)) {
33
            $this->delete($key);
34
        }
35
        return $default;
36
    }
37
38
    /**
39
     * @inheritDoc
40
     */
41
    public function set($key, $value, $ttl = null)
42
    {
43
        $this->storage[$key] = $value;
44
        $this->expiries[$key] = $this->computeExpiryTime($ttl);
0 ignored issues
show
It seems like $ttl defined by parameter $ttl on line 41 can also be of type object<DateInterval>; however, BenTools\Currency\Cache\...he::computeExpiryTime() does only seem to accept null|integer, maybe add an additional type check?

This check looks at variables that have been passed in as parameters and are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
45
    }
46
47
    /**
48
     * @inheritDoc
49
     */
50
    public function delete($key)
51
    {
52
        unset($this->storage[$key], $this->expiries[$key]);
53
    }
54
55
    /**
56
     * @inheritDoc
57
     */
58
    public function clear()
59
    {
60
        $this->storage = [];
61
        $this->expiries = [];
62
    }
63
64
    /**
65
     * @inheritDoc
66
     */
67
    public function getMultiple($keys, $default = null)
68
    {
69
        foreach ($keys as $key) {
70
            yield $key => $this->get($key, $default);
71
        }
72
    }
73
74
    /**
75
     * @inheritDoc
76
     */
77
    public function setMultiple($values, $ttl = null)
78
    {
79
        if (!$this->isIterable($values)) {
80
            throw new \InvalidArgumentException("Values must be array or Traversable");
81
        }
82
        foreach ($values as $key => $value) {
83
            $this->set($key, $value, $ttl);
84
        }
85
    }
86
87
    /**
88
     * @inheritDoc
89
     */
90
    public function deleteMultiple($keys)
91
    {
92
        foreach ($keys as $key) {
93
            $this->delete($key);
94
        }
95
    }
96
97
    /**
98
     * @inheritDoc
99
     */
100
    public function has($key)
101
    {
102
        return isset($this->storage[$key]) && !$this->isExpired($key);
103
    }
104
105
    /**
106
     * @param mixed $values
107
     * @return bool
108
     */
109
    private function isIterable($values): bool
110
    {
111
        return is_array($values) || $values instanceof Traversable;
112
    }
113
114
    /**
115
     * @param int|null $ttl
116
     * @return int|null
117
     */
118
    private function computeExpiryTime(int $ttl = null): ?int
119
    {
120
        $ttl = $ttl ?? $this->defaultTtl;
121
        if (null === $ttl) {
122
            return null;
123
        }
124
        return time() + $ttl;
125
    }
126
127
    /**
128
     * @param string $key
129
     * @return bool
130
     */
131
    private function isExpired($key): bool
132
    {
133
        if (isset($this->expiries[$key]) && null !== $this->expiries[$key]) {
134
            return time() >= $this->expiries[$key];
135
        }
136
        return false;
137
    }
138
}
139