Issues (9)

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/services/IntegrationCache.php (1 issue)

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
/**
4
 * @copyright  Copyright (c) Flipbox Digital Limited
5
 * @license    https://github.com/flipboxfactory/craft-integration/blob/master/LICENSE
6
 * @link       https://github.com/flipboxfactory/craft-integration/
7
 */
8
9
namespace flipbox\craft\integration\services;
10
11
use Craft;
12
use craft\helpers\ArrayHelper;
13
use craft\helpers\Component as ComponentHelper;
14
use flipbox\craft\psr16\SimpleCacheAdapter;
15
use Flipbox\Skeleton\Exceptions\InvalidConfigurationException;
16
use Flipbox\Skeleton\Helpers\ObjectHelper;
17
use Psr\SimpleCache\CacheInterface;
18
use yii\base\Component;
19
use yii\caching\DummyCache;
20
21
/**
22
 * @author Flipbox Factory <[email protected]>
23
 * @since 2.2.0
24
 */
25
abstract class IntegrationCache extends Component
26
{
27
    /**
28
     * The dummy cache handle
29
     */
30
    const DUMMY_CACHE = 'dummy';
31
32
    /**
33
     * The app cache handle
34
     */
35
    const APP_CACHE = 'app';
36
37
    /**
38
     * The default cache identifier
39
     */
40
    const DEFAULT_CACHE = 'DEFAULT';
41
42
    /**
43
     * The override file
44
     */
45
    public $overrideFile;
46
47
    /**
48
     *  Cache overrides
49
     *
50
     * @var array|null
51
     */
52
    private $overrides;
53
54
    /**
55
     * @var CacheInterface[]
56
     */
57
    private $cache = [];
58
59
    /**
60
     * @inheritdoc
61
     */
62
    public function init()
63
    {
64
        parent::init();
65
66
        /** @noinspection PhpUnhandledExceptionInspection */
67
        $this->cache[self::APP_CACHE] = Craft::createObject([
68
            'class' => SimpleCacheAdapter::class,
69
            'cache' => Craft::$app->getCache()
70
        ]);
71
72
        /** @noinspection PhpUnhandledExceptionInspection */
73
        $this->cache[self::DUMMY_CACHE] = Craft::createObject([
74
            'class' => SimpleCacheAdapter::class,
75
            'cache' => [
76
                'class' => DummyCache::class
77
            ]
78
        ]);
79
    }
80
81
    /**
82
     * Load override cache configurations
83
     */
84
    protected function loadOverrides()
85
    {
86
        if ($this->overrides === null) {
87
            $this->overrides = [];
88
89
            if ($this->overrideFile !== null) {
90
                $this->overrides = Craft::$app->getConfig()->getConfigFromFile($this->overrideFile);
91
            }
92
        }
93
    }
94
95
    /**
96
     * Returns any configurations from the config file.
97
     *
98
     * @param string $handle
99
     * @return array|null
100
     */
101
    public function getOverrides(string $handle)
102
    {
103
        $this->loadOverrides();
104
        return $this->overrides[$handle] ?? null;
105
    }
106
107
    /**
108
     * @return string
109
     */
110
    protected function getDefaultCache(): string
111
    {
112
        return static::DUMMY_CACHE;
113
    }
114
115
    /**
116
     * @param string $handle
117
     * @return CacheInterface|null
118
     */
119
    protected function handleCacheNotFound(string $handle)
0 ignored issues
show
The parameter $handle is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
120
    {
121
        return $this->find(static::DUMMY_CACHE);
122
    }
123
124
    /**
125
     * @param string $handle
126
     * @return CacheInterface|null
127
     */
128
    public function find(string $handle = self::DEFAULT_CACHE)
129
    {
130
        if ($handle === self::DEFAULT_CACHE) {
131
            $handle = $this->getDefaultCache();
132
        }
133
134
        if (!array_key_exists($handle, $this->cache)) {
135
            $this->cache[$handle] = $this->create(['handle' => $handle]);
136
        }
137
138
        return $this->cache[$handle];
139
    }
140
141
    /**
142
     * @param string $handle
143
     * @return CacheInterface
144
     */
145
    public function get(string $handle = self::DEFAULT_CACHE): CacheInterface
146
    {
147
        if (null === ($cache = $this->find($handle))) {
148
            return $this->handleCacheNotFound($handle);
149
        }
150
151
        return $cache;
152
    }
153
154
    /**
155
     * @param $config
156
     * @return CacheInterface|null
157
     */
158
    protected function create(array $config)
159
    {
160
        // Merge settings
161
        $config = ComponentHelper::mergeSettings($config);
162
163
        // Apply overrides
164
        if (null !== ($handle = ArrayHelper::remove($config, 'handle')) &&
165
            null !== ($override = $this->getOverrides($handle))
166
        ) {
167
            $config = array_merge($config, $override);
168
        }
169
170
        try {
171
            $cache = ObjectHelper::create(
172
                $config,
173
                CacheInterface::class
174
            );
175
        } catch (InvalidConfigurationException $e) {
176
            return null;
177
        }
178
179
        return $cache;
180
    }
181
182
    /**
183
     * @return array
184
     */
185
    public function all(): array
186
    {
187
        // Ensure configs are loaded
188
        $this->loadOverrides();
189
190
        // The handles defined in the config
191
        $handles = array_keys($this->overrides);
192
193
        // Any configured that aren't in the db
194
        foreach ($handles as $handle) {
195
            $this->cache[$handle] = $this->create(['handle' => $handle]);
196
        }
197
198
        return $this->cache;
199
    }
200
}
201