Issues (55)

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/Http/Controllers/AuthorizationController.php (6 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
namespace CodexShaper\OAuth2\Server\Http\Controllers;
4
5
use CodexShaper\OAuth2\Server\Entities\User as UserEntity;
6
use CodexShaper\OAuth2\Server\Http\Requests\ServerRequest;
7
use CodexShaper\OAuth2\Server\Http\Responses\ServerResponse;
8
use CodexShaper\OAuth2\Server\Manager;
9
use CodexShaper\OAuth2\Server\Model;
10
use CodexShaper\OAuth2\Server\Models\User;
11
use Illuminate\Http\Request;
12
use League\OAuth2\Server\Exception\OAuthServerException;
13
14
class AuthorizationController
15
{
16
    /**
17
     * The server manager.
18
     *
19
     * @var \CodexShaper\OAuth2\Server\Manager
20
     */
21
    protected $manager;
22
23
    /**
24
     * The authorization server.
25
     *
26
     * @var \League\OAuth2\Server\AuthorizationServer
27
     */
28
    protected $server;
29
30
    /**
31
     * The psr7 server request.
32
     *
33
     * @var \CodexShaper\OAuth2\Server\Http\Requests\ServerRequest
34
     */
35
    protected $request;
36
37
    /**
38
     * The psr7 server response.
39
     *
40
     * @var \CodexShaper\OAuth2\Server\Http\Responses\ServerResponse
41
     */
42
    protected $response;
43
44
    /**
45
     * Create a new authorization controller instance.
46
     *
47
     * @return void
0 ignored issues
show
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

Loading history...
48
     */
49
    public function __construct()
50
    {
51
        $this->manager = new Manager();
52
        $this->server = $this->manager->makeAuthorizationServer();
53
        $this->request = ServerRequest::getPsrServerRequest();
54
        $this->response = ServerResponse::getPsrServerResponse();
0 ignored issues
show
Documentation Bug introduced by
It seems like \CodexShaper\OAuth2\Serv...:getPsrServerResponse() of type object<Nyholm\Psr7\Response> is incompatible with the declared type object<CodexShaper\OAuth...sponses\ServerResponse> of property $response.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
55
    }
56
57
    /**
58
     * Make authorization.
59
     *
60
     * @param \CodexShaper\OAuth2\Server\Models\User $user
61
     *
62
     * @return \League\OAuth2\Server\ResponseTypes\ResponseTypeInterface|void
63
     */
64
    public function authorize($user)
65
    {
66
        try {
67
68
            // Validate the HTTP request and return an AuthorizationRequest object.
69
            $authRequest = $this->server->validateAuthorizationRequest($this->request);
0 ignored issues
show
$this->request is of type object<CodexShaper\OAuth...Requests\ServerRequest>, but the function expects a object<Psr\Http\Message\ServerRequestInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
70
71
            // Get all validate scopes from psr request
72
            $scopes = $this->filterScopes($authRequest);
0 ignored issues
show
$scopes is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
73
74
            // Get token for current user and request client id
75
            $token = Model::findToken('clientModel', $authRequest, $user);
76
77
            if (($token) || Model::instance('clientModel')->isSkipsAuthorization()) {
78
                return $this->approve($authRequest, $user);
79
            }
80
81
            return  $authRequest;
82
        } catch (OAuthServerException $exception) {
83
84
            // All instances of OAuthServerException can be formatted into a HTTP response
85
            return $exception->generateHttpResponse($this->response);
0 ignored issues
show
$this->response is of type object<CodexShaper\OAuth...sponses\ServerResponse>, but the function expects a object<Psr\Http\Message\ResponseInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
86
        }
87
    }
88
89
    /**
90
     * Approve the authorization.
91
     *
92
     * @param \League\OAuth2\Server\RequestTypes\AuthorizationRequest $authRequest
93
     * @param \CodexShaper\OAuth2\Server\Models\User                  $user
94
     *
95
     * @return \League\OAuth2\Server\ResponseTypes\ResponseTypeInterface
96
     */
97
    public function approve($authRequest, $user)
98
    {
99
        // Once the user has logged in set the user on the AuthorizationRequest
100
        $authRequest->setUser(new UserEntity($user->getKey())); // an instance of UserEntityInterface
101
102
        // Once the user has approved or denied the client update the status
103
        // (true = approved, false = denied)
104
        $authRequest->setAuthorizationApproved(true);
105
106
        // Return the HTTP redirect response
107
        return $this->server->completeAuthorizationRequest($authRequest, $this->response);
0 ignored issues
show
$this->response is of type object<CodexShaper\OAuth...sponses\ServerResponse>, but the function expects a object<Psr\Http\Message\ResponseInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
108
    }
109
110
    /**
111
     * Deny the authorization request.
112
     *
113
     * @return void
114
     */
115
    public function deny()
116
    {
117
    }
118
119
    /**
120
     * Filter all scopes.
121
     *
122
     * @param \League\OAuth2\Server\RequestTypes\AuthorizationRequest $authRequest
123
     *
124
     * @return array
125
     */
126
    public function filterScopes($authRequest)
127
    {
128
        return array_filter($authRequest->getScopes(), function ($scope) {
129
            if (Manager::isValidateScope($scope->getIdentifier())) {
130
                return $scope->getIdentifier();
131
            }
132
        });
133
    }
134
}
135