Issues (94)

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/Commands/BaseImpersonationMiddleware.php (1 issue)

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 declare(strict_types=1);
2
3
namespace Limoncello\Application\Commands;
4
5
/**
6
 * Copyright 2015-2020 [email protected]
7
 *
8
 * Licensed under the Apache License, Version 2.0 (the "License");
9
 * you may not use this file except in compliance with the License.
10
 * You may obtain a copy of the License at
11
 *
12
 * http://www.apache.org/licenses/LICENSE-2.0
13
 *
14
 * Unless required by applicable law or agreed to in writing, software
15
 * distributed under the License is distributed on an "AS IS" BASIS,
16
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
 * See the License for the specific language governing permissions and
18
 * limitations under the License.
19
 */
20
21
use Closure;
22
use Limoncello\Contracts\Authentication\AccountManagerInterface;
23
use Limoncello\Contracts\Commands\IoInterface;
24
use Limoncello\Contracts\Commands\MiddlewareInterface;
25
use Limoncello\Contracts\Passport\PassportAccountInterface;
26
use Limoncello\Contracts\Settings\Packages\CommandSettingsInterface;
27
use Limoncello\Contracts\Settings\SettingsProviderInterface;
28
use Psr\Container\ContainerInterface;
29
use function array_key_exists;
30
use function assert;
31
use function call_user_func;
32
use function is_int;
33
use function is_string;
34
35
/**
36
 * @package Limoncello\Application
37
 */
38
abstract class BaseImpersonationMiddleware implements MiddlewareInterface
39
{
40
    /**
41
     * @param ContainerInterface $container
42
     *
43 1
     * @return Closure
44
     */
45
    abstract protected static function createReadScopesClosure(ContainerInterface $container): Closure;
46
47
    /**
48
     * @inheritdoc
49 1
     */
50 1
    public static function handle(
51 1
        IoInterface $inOut,
52 1
        Closure $next,
53
        ContainerInterface $container
54
    ): void {
55 1
        /** @var SettingsProviderInterface $provider */
56 1
        $provider       = $container->get(SettingsProviderInterface::class);
57 1
        $settings       = $provider->get(CommandSettingsInterface::class);
58
        $userIdentity   = $settings[CommandSettingsInterface::KEY_IMPERSONATE_AS_USER_IDENTITY] ?? null;
59
        $userProperties = $settings[CommandSettingsInterface::KEY_IMPERSONATE_WITH_USER_PROPERTIES] ?? [];
60 1
61
        /** @var AccountManagerInterface $manager */
62
        $manager = $container->get(AccountManagerInterface::class);
63
        $manager->setAccount(
64
            static::createCliPassport($userIdentity, static::createReadScopesClosure($container), $userProperties)
65
        );
66
67
        call_user_func($next, $inOut);
68
    }
69
70
    /**
71
     * @param int|string $userIdentity
72
     * @param Closure    $readUserScopes
73
     * @param array      $properties
74
     *
75
     * @return PassportAccountInterface
76
     *
77
     * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
78
     * @SuppressWarnings(PHPMD.UndefinedVariable)
79
     */
80
    protected static function createCliPassport(
81
        $userIdentity,
82
        Closure $readUserScopes,
83
        array $properties
84
    ): PassportAccountInterface {
85
        return new class ($userIdentity, $readUserScopes, $properties) implements PassportAccountInterface
86
        {
87
            /**
88
             * @var array
89
             */
90
            private $properties;
91
92
            /**
93
             * @var int
94
             */
95
            private $userIdentity;
96
97
            /**
98
             * @var Closure
99 1
             */
100
            private $readUserScopes;
101 1
102
            /**
103 1
             * @param int|string $userIdentity
104 1
             * @param Closure    $readUserScopes
105 1
             * @param array      $properties
106
             */
107
            public function __construct($userIdentity, Closure $readUserScopes, array $properties)
108
            {
109
                assert(is_int($userIdentity) === true || is_string($userIdentity) === true);
110
111 1
                $this->userIdentity   = $userIdentity;
0 ignored issues
show
Documentation Bug introduced by
It seems like $userIdentity can also be of type string. However, the property $userIdentity is declared as type integer. 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...
112
                $this->properties     = $properties;
113 1
                $this->readUserScopes = $readUserScopes;
114
            }
115
116
            /**
117
             * @inheritdoc
118
             */
119 1
            public function hasProperty($key): bool
120
            {
121 1
                return array_key_exists($key, $this->properties);
122
            }
123
124
            /**
125
             * @inheritdoc
126
             */
127 1
            public function getProperty($key)
128
            {
129 1
                return $this->properties[$key];
130
            }
131
132
            /**
133
             * @inheritdoc
134
             */
135 1
            public function hasUserIdentity(): bool
136
            {
137 1
                return true;
138
            }
139
140
            /**
141
             * @inheritdoc
142
             */
143 1
            public function getUserIdentity()
144
            {
145 1
                return $this->userIdentity;
146
            }
147
148
            /**
149
             * @inheritdoc
150
             */
151 1
            public function hasClientIdentity(): bool
152
            {
153 1
                return false;
154
            }
155
156
            /**
157
             * @inheritdoc
158
             */
159 1
            public function getClientIdentity()
160
            {
161
                return null;
162 1
            }
163
164
            /**
165
             * @inheritdoc
166
             */
167
            public function hasScope(string $scope): bool
168 1
            {
169
                // we typically do just one call during a session so it's fine to work with unsorted data.
170 1
                return in_array($scope, $this->getScopes());
171
            }
172
173
            /**
174
             * @inheritdoc
175
             */
176 1
            public function hasScopes(): bool
177
            {
178 1
                return true;
179
            }
180 1
181
            /**
182
             * @inheritdoc
183
             */
184
            public function getScopes(): array
185
            {
186
                $scopes = call_user_func($this->readUserScopes, $this->getUserIdentity());
187
188
                return $scopes;
189
            }
190
        };
191
    }
192
}
193