Issues (69)

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/Traits/BasicClientAuthenticationTrait.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\Passport\Traits;
4
5
/**
6
 * Copyright 2015-2019 [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 Limoncello\OAuthServer\Contracts\ClientInterface;
22
use Limoncello\OAuthServer\Exceptions\OAuthTokenBodyException;
23
use Limoncello\Passport\Contracts\PassportServerIntegrationInterface;
24
use Psr\Http\Message\ServerRequestInterface;
25
use function array_key_exists;
26
use function assert;
27
use function base64_decode;
28
use function count;
29
use function explode;
30
use function is_string;
31
use function substr;
32
33
/**
34
 * @package Limoncello\Passport
35
 */
36
trait BasicClientAuthenticationTrait
37
{
38
    /**
39
     * @param PassportServerIntegrationInterface $integration
40
     * @param ServerRequestInterface             $request
41
     * @param array                              $parameters
42
     * @param string                             $realm
43
     *
44
     * @return ClientInterface|null
0 ignored issues
show
Consider making the return type a bit more specific; maybe use \Limoncello\Passport\Con...es\ClientInterface|null.

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
45
     *
46
     * @SuppressWarnings(PHPMD.ElseExpression)
47
     * @SuppressWarnings(PHPMD.NPathComplexity)
48
     * @SuppressWarnings(PHPMD.CyclomaticComplexity)
49
     */
50 13
    protected function determineClient(
51
        PassportServerIntegrationInterface $integration,
52
        ServerRequestInterface $request,
53
        array $parameters,
54
        $realm = 'OAuth'
55
    ): ?ClientInterface {
56
        // A client may use Basic authentication.
57
        //
58
        // Or
59
        //
60
        // A client MAY use the "client_id" request parameter to identify itself
61
        // when sending requests to the token endpoint.
62
        // @link https://tools.ietf.org/html/rfc6749#section-3.2.1
63
64 13
        $authorizationHeader = $request->getHeader('Authorization');
65
66
        // try to parse `Authorization` header for client ID and credentials
67 13
        $clientId          = null;
68 13
        $clientCredentials = null;
69 13
        $errorHeaders      = ['WWW-Authenticate' => 'Basic realm="' . $realm . '"'];
70 13
        if (empty($headerArray = $authorizationHeader) === false) {
71 6
            $errorCode = OAuthTokenBodyException::ERROR_INVALID_CLIENT;
72 6
            if (empty($authHeader = $headerArray[0]) === true ||
73 6
                ($tokenPos = strpos($authHeader, 'Basic ')) === false ||
74 6
                $tokenPos !== 0 ||
75 6
                ($authValue = substr($authHeader, 6)) === '' ||
76 6
                $authValue === false ||
77 6
                ($decodedValue = base64_decode($authValue, true)) === false ||
78 6
                ($idAndCredentials = explode(':', $decodedValue, 2)) === false
79
            ) {
80 1
                throw new OAuthTokenBodyException($errorCode, null, 401, $errorHeaders);
81
            }
82 5
            $headerPartsCount = count($idAndCredentials);
83
            switch ($headerPartsCount) {
84 5
                case 1:
85 2
                    $clientId = $idAndCredentials[0];
86 2
                    break;
87 3
                case 2:
88
                default:
89 3
                    $clientId          = $idAndCredentials[0];
90 3
                    $clientCredentials = $idAndCredentials[1];
91 3
                    break;
92
            }
93
        }
94
95
        // check if client ID was specified in parameters it should match
96 12
        if (array_key_exists('client_id', $parameters) === true &&
97 12
            is_string($value = $parameters['client_id']) === true
98
        ) {
99 5
            if ($clientId !== null && $clientId !== $value) {
100 1
                $errorCode = OAuthTokenBodyException::ERROR_INVALID_REQUEST;
101 1
                throw new OAuthTokenBodyException($errorCode, null, 400, $errorHeaders);
102
            }
103
104 4
            $clientId = $value;
105 4
            unset($value);
106
        }
107
108
        // when we are here we know if any client ID and credentials were given
109
110 11
        $client = null;
111 11
        if ($clientId !== null) {
112 8
            assert(is_string($clientId));
113 8
            $errorCode = OAuthTokenBodyException::ERROR_INVALID_CLIENT;
114 8
            if (($client = $integration->getClientRepository()->read($clientId)) === null) {
115 1
                throw new OAuthTokenBodyException($errorCode, null, 401, $errorHeaders);
116
            }
117
118
            // check credentials
119 7
            if ($clientCredentials !== null) {
120 2
                assert(is_string($clientCredentials));
121
                // we got the password
122 2
                if ($integration->verifyClientCredentials($client, $clientCredentials) === false) {
123 2
                    throw new OAuthTokenBodyException($errorCode, null, 401, $errorHeaders);
124
                }
125
            } else {
126
                // no password provided
127 5
                if ($client->isConfidential() === true || $client->hasCredentials() === true) {
128 1
                    throw new OAuthTokenBodyException($errorCode, null, 401, $errorHeaders);
129
                }
130
            }
131
        }
132
133 8
        return $client;
134
    }
135
}
136