Issues (32)

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/DoctrineIdentity/UserStorageProxy.php (3 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
declare(strict_types=1);
4
5
namespace SixtyEightPublishers\User\DoctrineIdentity;
6
7
use Nette\SmartObject;
8
use Nette\Security\IIdentity;
9
use Nette\Security\IUserStorage;
10
use Doctrine\ORM\EntityManagerInterface;
11
use Doctrine\Persistence\Mapping\MappingException;
12
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
13
use SixtyEightPublishers\User\DoctrineIdentity\Event\IdentityNotFoundEvent;
14
use SixtyEightPublishers\User\DoctrineIdentity\Exception\UnimplementedMethodException;
15
16
/**
17
 * @method void onIdentityNotFound(IdentityReference $identityReference)
18
 */
19
final class UserStorageProxy implements IUserStorage
20
{
21
	use SmartObject;
22
23
	/** @var \Nette\Security\IUserStorage  */
24
	private $userStorage;
25
26
	/** @var \Doctrine\ORM\EntityManagerInterface  */
27
	private $em;
28
29
	/** @var \Symfony\Contracts\EventDispatcher\EventDispatcherInterface  */
30
	private $eventDispatcher;
31
32
	/** @var \Nette\Security\Identity|NULL|bool */
33
	private $currentIdentity = FALSE;
34
35
	/** @var callable[] */
36
	public $onIdentityNotFound = [];
37
38
	/**
39
	 * @param \Nette\Security\IUserStorage                                $userStorage
40
	 * @param \Doctrine\ORM\EntityManagerInterface                        $em
41
	 * @param \Symfony\Contracts\EventDispatcher\EventDispatcherInterface $eventDispatcher
42
	 */
43
	public function __construct(IUserStorage $userStorage, EntityManagerInterface $em, EventDispatcherInterface $eventDispatcher)
44
	{
45
		$this->userStorage = $userStorage;
46
		$this->em = $em;
47
		$this->eventDispatcher = $eventDispatcher;
48
	}
49
50
	/**
51
	 * For compatibility with default implementation Nette\Http\UserStorage
52
	 *
53
	 * @param string $namespace
54
	 *
55
	 * @return \SixtyEightPublishers\User\DoctrineIdentity\UserStorageProxy
56
	 * @throws \SixtyEightPublishers\User\DoctrineIdentity\Exception\UnimplementedMethodException
57
	 */
58
	public function setNamespace(string $namespace): self
59
	{
60
		if (!is_callable([$this->userStorage, 'setNamespace'])) {
61
			throw UnimplementedMethodException::unimplementedMethod(get_class($this->userStorage), 'setNamespace');
62
		}
63
64
		$this->userStorage->setNamespace($namespace);
65
66
		return $this;
67
	}
68
69
	/**
70
	 * For compatibility with default implementation Nette\Http\UserStorage
71
	 *
72
	 * @return string
73
	 * @throws \SixtyEightPublishers\User\DoctrineIdentity\Exception\UnimplementedMethodException
74
	 */
75
	public function getNamespace(): string
76
	{
77
		if (!is_callable([$this->userStorage, 'getNamespace'])) {
78
			throw Exception\UnimplementedMethodException::unimplementedMethod(get_class($this->userStorage), 'getNamespace');
79
		}
80
81
		return $this->userStorage->getNamespace();
82
	}
83
84
	/************ interface \Nette\Security\IUserStorage ************/
85
86
	/**
87
	 * {@inheritdoc}
88
	 */
89
	public function setAuthenticated($state): self
90
	{
91
		$this->userStorage->setAuthenticated($state);
92
93
		return $this;
94
	}
95
96
	/**
97
	 * {@inheritdoc}
98
	 */
99
	public function isAuthenticated(): bool
100
	{
101
		# Get the identity as first. If the entity is not found then the user can't be authenticated.
102
		$this->getIdentity();
103
104
		return $this->userStorage->isAuthenticated();
105
	}
106
107
	/**
108
	 * {@inheritdoc}
109
	 */
110
	public function setIdentity(?IIdentity $identity = NULL): self
111
	{
112
		if (NULL !== $identity) {
113
			try {
114
				$metadata = $this->em->getMetadataFactory()->getMetadataFor(get_class($identity));
115
116
				$identity = new IdentityReference(
117
					$metadata->getName(),
118
					$metadata->getIdentifierValues($identity)
119
				);
120
			} catch (MappingException $e) {
0 ignored issues
show
The class Doctrine\Persistence\Mapping\MappingException does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
121
				# an empty catch block because we can't test if the MetadataFactory contains a metadata for identity's classname.
122
				# The classname can be a Doctrine Proxy and the method `MetadataFactory::hasMetadataFor()` doesn't convert Proxy's classname into real classname.
123
			}
124
		}
125
126
		$this->userStorage->setIdentity($identity);
127
		$this->currentIdentity = FALSE;
128
129
		return $this;
130
	}
131
132
	/**
133
	 * {@inheritdoc}
134
	 */
135
	public function getIdentity(): ?IIdentity
136
	{
137
		if (FALSE !== $this->currentIdentity) {
138
			return $this->currentIdentity;
139
		}
140
141
		$identityReference = $this->userStorage->getIdentity();
142
143
		if (!$identityReference instanceof IdentityReference) {
144
			return $identityReference;
145
		}
146
147
		$identity = $this->em->find($identityReference->getClassName(), $identityReference->getId());
148
149
		if (!$identity instanceof IIdentity) {
0 ignored issues
show
The class Nette\Security\IIdentity does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
150
			$identity = NULL;
151
152
			$this->setAuthenticated(FALSE);
153
			$this->setIdentity($identity);
154
155
			$namespace = $this->getNamespace();
156
157
			$this->eventDispatcher->dispatch(new IdentityNotFoundEvent($identityReference, empty($namespace) ? NULL : $namespace), IdentityNotFoundEvent::NAME);
158
			$this->onIdentityNotFound($identityReference);
159
		}
160
161
		return $this->currentIdentity = $identity;
0 ignored issues
show
Documentation Bug introduced by
It seems like $identity can also be of type object<Nette\Security\IIdentity>. However, the property $currentIdentity is declared as type object<Nette\Security\Identity>|null|boolean. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
162
	}
163
164
	/**
165
	 * {@inheritdoc}
166
	 */
167
	public function setExpiration($time, $flags = 0): self
168
	{
169
		$this->userStorage->setExpiration($time, $flags);
170
171
		return $this;
172
	}
173
174
	/**
175
	 * {@inheritdoc}
176
	 */
177
	public function getLogoutReason(): ?int
178
	{
179
		return $this->userStorage->getLogoutReason();
180
	}
181
}
182