Issues (47)

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/ClassCache.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
4
namespace Maslosoft\Addendum\Cache;
5
6
7
use function get_class;
8
use function is_object;
9
use Maslosoft\Addendum\Addendum;
10
use Maslosoft\Addendum\Cache\PhpCache\Checker;
11
use Maslosoft\Addendum\Cache\PhpCache\Cleaner;
12
use Maslosoft\Addendum\Cache\PhpCache\Reader;
13
use Maslosoft\Addendum\Cache\PhpCache\Writer;
14
use Maslosoft\Addendum\Helpers\Cacher;
15
use Maslosoft\Addendum\Interfaces\AnnotatedInterface;
16
use Maslosoft\Addendum\Options\MetaOptions;
17
use Maslosoft\Cli\Shared\ConfigDetector;
18
use UnexpectedValueException;
19
20
class ClassCache
21
{
22
	/**
23
	 * @var string
24
	 */
25
	private static $runtimePath = null;
26
27
	/**
28
	 * @var string
29
	 */
30
	private $className = '';
31
32
	/**
33
	 * Root path of storage
34
	 * @var string
35
	 */
36
	private $storagePath = '';
37
38
	/**
39
	 * Base path for current meta class
40
	 * @var string
41
	 */
42
	private $basePath = '';
43
44
	/**
45
	 * @var string
46
	 */
47
	private $metaClass = '';
48
49
	/**
50
	 * @var NsCache
51
	 */
52
	private $nsCache;
53
54
	/**
55
	 * @var Addendum
56
	 */
57
	private $addendum;
58
59
	/**
60
	 * @var Writer
61
	 */
62
	private $writer;
63
64
	/**
65
	 * @var Checker
66
	 */
67
	private $checker;
68
69
	/**
70
	 * @var Reader
71
	 */
72
	private $reader;
73
74
	/**
75
	 * @var Cleaner
76
	 */
77
	private $cleaner;
78
79
	/**
80
	 *
81
	 * @param string                           $metaClass
82
	 * @param AnnotatedInterface|object|string $component
83
	 * @param MetaOptions|Addendum             $options
84
	 */
85 1
	public function __construct(string $metaClass, $component, $options = null)
86
	{
87 1
		if (null === self::$runtimePath)
88
		{
89 1
			self::$runtimePath = (new ConfigDetector)->getRuntimePath();
90
		}
91 1
		$this->storagePath = self::$runtimePath . '/addendum';
92 1
		$this->metaClass = $metaClass;
93 1
		if(is_object($component))
94
		{
95 1
			$component = get_class($component);
96
		}
97 1
		$this->className = $component;
98 1
		$this->setOptions($options);
0 ignored issues
show
It seems like $options defined by parameter $options on line 85 can also be of type object<Maslosoft\Addendum\Addendum>; however, Maslosoft\Addendum\Cache\ClassCache::setOptions() does only seem to accept null|object<Maslosoft\Ad...um\Options\MetaOptions>, 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...
99
100 1
		$this->reader = new Reader($this->basePath);
101 1
		$this->writer = new Writer($this->basePath);
102 1
		$this->cleaner = new Cleaner($this->basePath);
103 1
		$this->checker = new Checker($this->basePath);
104 1
	}
105
106 37
	public function get($className)
107
	{
108 37
		assert(!empty($className));
109 37
		if($this->addendum->checkMTime)
110
		{
111
			if(!$this->checker->isValid($className))
112
			{
113
				return false;
114
			}
115
		}
116 37
		$data = $this->reader->read($className);
117
118 37
		return $data;
119
	}
120
121 30
	public function set($className, $data): bool
122
	{
123 30
		$this->cleaner->clean($className);
124 30
		return $this->writer->write($className, $data);
125
	}
126
127 37
	public function setOptions(MetaOptions $options = null)
128
	{
129 37
		$instanceId = $this->getInstanceId($options);
130 37
		$this->addendum = Addendum::fly($instanceId);
131 37
		$this->basePath = sprintf('%s/%s@%s',
132 37
			$this->storagePath,
133 37
			Cacher::classToFile($this->metaClass),
134 37
			$instanceId
135
		);
136 37
		$this->nsCache = new NsCache($this->basePath, $this->addendum);
137 37
		$this->nsCache->setOptions($options);
138 37
	}
139
140 37
	private function getInstanceId(MetaOptions $options = null)
141
	{
142 37
		if (empty($options))
143
		{
144 33
			$instanceId = Addendum::DefaultInstanceId;
145
		}
146 4
		elseif ($options instanceof Addendum)
147
		{
148
			$instanceId = $options->getInstanceId();
149
		}
150 4
		elseif ($options instanceof MetaOptions)
151
		{
152 4
			$instanceId = $options->instanceId;
153
		}
154
		else
155
		{
156
			throw new UnexpectedValueException('Unknown options');
157
		}
158 37
		return $instanceId;
159
	}
160
}