Issues (7)

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/Provider/WebProvider.php (2 issues)

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
4
namespace Oakhope\OAuth2\Client\Provider;
5
6
use League\OAuth2\Client\Grant\AbstractGrant;
7
use League\OAuth2\Client\Provider\AbstractProvider;
8
use League\OAuth2\Client\Provider\Exception\IdentityProviderException;
9
use League\OAuth2\Client\Provider\ResourceOwnerInterface;
10
use League\OAuth2\Client\Token\AccessToken;
11
use League\OAuth2\Client\Tool\ArrayAccessorTrait;
12
use Psr\Http\Message\ResponseInterface;
13
14
class WebProvider extends AbstractProvider
15
{
16
    use ArrayAccessorTrait;
17
18
    protected $appid;
19
    protected $secret;
20
    protected $redirect_uri;
21
22
    /**
23
     * Returns the base URL for authorizing a client.
24
     *
25
     * @return string
26
     */
27 9
    public function getBaseAuthorizationUrl()
28
    {
29 9
        return 'https://open.weixin.qq.com/connect/qrconnect';
30
    }
31
32
    /**
33
     * Returns authorization parameters based on provided options.
34
     *
35
     * @param  array $options
36
     * @return array Authorization parameters
37
     */
38 9
    protected function getAuthorizationParameters(array $options)
39
    {
40
        $options += [
41 9
            'appid' => $this->appid
42 6
        ];
43
44 9
        if (!isset($options['redirect_uri'])) {
45 9
            $options['redirect_uri'] = $this->redirect_uri;
46 6
        }
47
48
        $options += [
49 3
            'response_type'   => 'code'
50 6
        ];
51
52 9
        if (empty($options['scope'])) {
53 6
            $options['scope'] = 'snsapi_login';
54 4
        }
55
56 9
        if (is_array($options['scope'])) {
57 3
            $separator = $this->getScopeSeparator();
58 3
            $options['scope'] = implode($separator, $options['scope']);
59 2
        }
60
61 9
        if (empty($options['state'])) {
62 9
            $options['state'] = $this->getRandomState().'#wechat_redirect';
63 6
        }
64
65
        // Store the state as it may need to be accessed later on.
66 9
        $this->state = $options['state'];
67
68 9
        return $options;
69
    }
70
71
    /**
72
     * Returns the base URL for requesting an access token.
73
     *
74
     * @param array $params
75
     * @return string
76
     */
77 12
    public function getBaseAccessTokenUrl(array $params)
78
    {
79 12
        return 'https://api.weixin.qq.com/sns/oauth2/access_token';
80
    }
81
82
    /**
83
     * Requests an access token using a specified grant and option set.
84
     *
85
     * @param  mixed $grant
86
     * @param  array $options
87
     * @return AccessToken
88
     */
89 9
    public function getAccessToken($grant, array $options = [])
90
    {
91 9
        $grant = $this->verifyGrant($grant);
92
        $params = [
93 9
            'appid'     => $this->appid,
94 9
            'secret' => $this->secret
95 6
        ];
96
97 9
        $params   = $grant->prepareRequestParameters($params, $options);
98 9
        $request  = $this->getAccessTokenRequest($params);
99 9
        $response = $this->getParsedResponse($request);
100 9
        $prepared = $this->prepareAccessTokenResponse($response);
0 ignored issues
show
It seems like $response defined by $this->getParsedResponse($request) on line 99 can also be of type null or string; however, League\OAuth2\Client\Pro...reAccessTokenResponse() does only seem to accept array, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
101 9
        $token    = $this->createAccessToken($prepared, $grant);
102
103 9
        return $token;
104
    }
105
106
    /**
107
     * Creates an access token from a response.
108
     *
109
     * The grant that was used to fetch the response can be used to provide
110
     * additional context.
111
     *
112
     * @param  array $response
113
     * @param  AbstractGrant $grant
114
     * @return AccessToken
115
     */
116 9
    protected function createAccessToken(array $response, AbstractGrant $grant)
117
    {
118 9
        return new AccessToken($response);
119
    }
120
121
    /**
122
     * Returns the URL for requesting the resource owner's details.
123
     *
124
     * @param AccessToken $token
125
     * @return string
126
     */
127 6
    public function getResourceOwnerDetailsUrl(AccessToken $token)
128
    {
129
        return 'https://api.weixin.qq.com/sns/userinfo?access_token='.
130 6
            $token->getToken().'&openid='.$token->getValues()['openid'];
131
    }
132
133
    /**
134
     * Returns the default scopes used by this provider.
135
     *
136
     * This should only be the scopes that are required to request the details
137
     * of the resource owner, rather than all the available scopes.
138
     *
139
     * @return array
140
     */
141
    protected function getDefaultScopes()
142
    {
143
        return ['snsapi_userinfo'];
144
    }
145
146
    /**
147
     * Checks a provider response for errors.
148
     *
149
     * @throws IdentityProviderException
150
     * @param  ResponseInterface $response
151
     * @param  array|string|\Psr\Http\Message\ResponseInterface $data Parsed response data
152
     * @return void
153
     */
154 9
    protected function checkResponse(ResponseInterface $response, $data)
155
    {
156 9
        $errcode = $this->getValueByKey($data, 'errcode');
157 9
        $errmsg = $this->getValueByKey($data, 'errmsg');
158
159 9
        if ($errcode || $errmsg) {
160 3
            throw new IdentityProviderException($errmsg, $errcode, $response);
0 ignored issues
show
$response is of type object<Psr\Http\Message\ResponseInterface>, but the function expects a array|string.

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...
161
        };
162 9
    }
163
164
    /**
165
     * Generates a resource owner object from a successful resource owner
166
     * details request.
167
     *
168
     * @param  array $response
169
     * @param  AccessToken $token
170
     * @return ResourceOwnerInterface
171
     */
172 6
    protected function createResourceOwner(array $response, AccessToken $token)
173
    {
174 6
        return new WebResourceOwner($response);
175
    }
176
}
177