Issues (116)

Security Analysis    not enabled

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/NwLaravel/OAuth/OAuthProxy.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
namespace NwLaravel\OAuth;
4
5
use GuzzleHttp\Client;
6
use GuzzleHttp\Exception\RequestException;
7
use GuzzleHttp\Psr7\Response as GuzzleResponse;
8
use Psr\Http\Message\ResponseInterface;
9
10
/**
11
 * Class Proxy
12
 *
13
 * @package NwLaravel\OAuth
14
 */
15
class OAuthProxy
16
{
17
    /**
18
     * @var OAuthClientEntity
19
     */
20
    protected $oauthClient;
21
22
    /**
23
     * @var Client
24
     */
25
    protected $clientHttp;
26
27
    /**
28
     * @var string
29
     */
30
    protected $proxyUrl;
31
32
    /**
33
     * Construct
34
     *
35
     * @param OAuthClientEntity $oauthClient OAuth Client Entity
36
     * @param Client            $clientHttp  Client Http
37
     */
38 5
    public function __construct(OAuthClientEntity $oauthClient, Client $clientHttp)
39
    {
40 5
        $this->oauthClient = $oauthClient;
41 5
        $this->clientHttp = $clientHttp;
42 5
        $this->proxyUrl = sprintf('%s%s', config('app.url'), config('nwlaravel.oauth.urlToken', '/oauth/access-token'));
43 5
    }
44
45
    /**
46
     * Attempt Login Password
47
     *
48
     * @param string $client_id   Client Id
49
     * @param array  $credentials Credentials
50
     *
51
     * @return Response
52
     */
53 3
    public function attemptLogin($client_id, array $credentials)
54
    {
55 3
        return $this->proxy('password', $client_id, $credentials);
56
    }
57
58
    /**
59
     * Attempt Refresh Token
60
     *
61
     * @param string $client_id   Client Id
62
     * @param array  $credentials Credentials
63
     *
64
     * @return Response
65
     */
66 1
    public function attemptRefresh($client_id, array $credentials)
67
    {
68 1
        return $this->proxy('refresh_token', $client_id, $credentials);
69
    }
70
71
    /**
72
     * Proxy
73
     *
74
     * @param string $grantType String Grant Type
75
     * @param string $client_id String Client Id
76
     * @param array  $data      Array Data
77
     *
78
     * @return Response
79
     */
80 4
    private function proxy($grantType, $client_id, array $data = array())
81
    {
82
        try {
83 4
            $data = array_merge([
84 4
                'client_id'     => $client_id,
85 4
                'client_secret' => $this->getClientSecret($client_id),
86
                'grant_type'    => $grantType
87 4
            ], $data);
88
89 4
            $guzzleResponse = $this->clientHttp->post($this->proxyUrl, ['json' => $data]);
90
91 4
        } catch (RequestException $e) {
92 1
            $body = sprintf('{"error": "%s", "error_description": "%s"}', get_class($e), $e->getMessage());
93 1
            $guzzleResponse = $e->hasResponse() ? $e->getResponse() : new GuzzleResponse(500, [], $body);
94
95 2
        } catch (\Exception $e) {
96 1
            $body = sprintf('{"error": "%s", "error_description": "%s"}', get_class($e), $e->getMessage());
97 1
            $guzzleResponse = new GuzzleResponse(500, [], $body);
98
        }
99
100 4
        return $this->parseResponse($guzzleResponse);
101
    }
102
103
    /**
104
     * Get Client Secret
105
     *
106
     * @param  string $client_id Client Id
107
     * @return string
108
     */
109 4
    private function getClientSecret($client_id)
110
    {
111 4
        $client_secret = '';
112 4
        $client = $this->oauthClient->where('id', $client_id)->first();
113 4
        if ($client) {
114 4
            $client_secret = $client->secret;
115 4
        }
116
117 4
        return $client_secret;
118
    }
119
120
    /**
121
     * Parse Response
122
     *
123
     * @param ResponseInterface $guzzleResponse
124
     * @return string
125
     */
126 4
    private function parseResponse(ResponseInterface $guzzleResponse)
127
    {
128 4
        $body = json_decode($guzzleResponse->getBody());
129 4
        $response = response()->json($body);
0 ignored issues
show
The method json does only exist in Illuminate\Contracts\Routing\ResponseFactory, but not in Illuminate\Http\Response.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
130 4
        $response->setStatusCode($guzzleResponse->getStatusCode());
131
132 4
        $headers = $guzzleResponse->getHeaders();
133 4
        foreach ($headers as $headerType => $headerValue) {
134 2
            $response->header($headerType, $headerValue);
135 4
        }
136
137 4
        return $response;
138
    }
139
}
140