Issues (129)

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/Suite/Authorization.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
2
3
namespace YEntWeChat\Suite;
4
5
use Doctrine\Common\Cache\Cache;
6
use YEntWeChat\Core\Exception;
7
use YEntWeChat\Suite\Api\BaseApi;
8
9
class Authorization
10
{
11
    const CACHE_KEY_ACCESS_TOKEN = 'YEntWeChat.suite.authorizer_access_token';
12
    const CACHE_KEY_PERMANENT_CODE = 'YEntWeChat.suite.authorizer_permanent_code';
13
14
    /**
15
     * Cache.
16
     *
17
     * @var \Doctrine\Common\Cache\Cache
18
     */
19
    protected $cache;
20
21
    /**
22
     * Base API.
23
     *
24
     * @var \EntWeChat\Suite\Api\BaseApi
25
     */
26
    protected $api;
27
28
    /**
29
     * Suite Id.
30
     *
31
     * @var string
32
     */
33
    protected $suiteId;
34
35
    /**
36
     * Authorizer Corp Id.
37
     *
38
     * @var string
39
     */
40
    protected $authorizerCorpId;
41
42
    /**
43
     * Authorization Constructor.
44
     *
45
     * @param \EntWeChat\Suite\Api\BaseApi $api
46
     * @param string                       $suiteId
47
     * @param \Doctrine\Common\Cache\Cache $cache
48
     */
49
    public function __construct(BaseApi $api, $suiteId, Cache $cache)
50
    {
51
        $this->api = $api;
0 ignored issues
show
Documentation Bug introduced by
It seems like $api of type object<YEntWeChat\Suite\Api\BaseApi> is incompatible with the declared type object<EntWeChat\Suite\Api\BaseApi> of property $api.

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...
52
        $this->suiteId = $suiteId;
53
        $this->cache = $cache;
54
    }
55
56
    /**
57
     * Gets the base api.
58
     *
59
     * @return \EntWeChat\Suite\Api\BaseApi
60
     */
61
    public function getApi()
62
    {
63
        return $this->api;
64
    }
65
66
    /**
67
     * Saves the authorizer access token in cache.
68
     *
69
     * @param string $token
70
     *
71
     * @return bool TRUE if the entry was successfully stored in the cache, FALSE otherwise
72
     */
73
    public function setAuthorizerAccessToken($token, $expires = 7200)
74
    {
75
        return $this->cache->save($this->getAuthorizerAccessTokenKey(), $token, $expires);
76
    }
77
78
    /**
79
     * Gets the authorizer access token cache key.
80
     *
81
     * @return string
82
     */
83
    public function getAuthorizerAccessTokenKey()
84
    {
85
        return self::CACHE_KEY_ACCESS_TOKEN.$this->suiteId.$this->getAuthorizerCorpId();
86
    }
87
88
    /**
89
     * Gets the authorizer corp id, or throws if not found.
90
     *
91
     * @throws \EntWeChat\Core\Exception
92
     *
93
     * @return string
94
     */
95
    public function getAuthorizerCorpId()
96
    {
97
        if (!$this->authorizerCorpId) {
98
            throw new Exception(
99
                'Authorizer Corp Id is not present, you may not make the authorization yet.'
100
            );
101
        }
102
103
        return $this->authorizerCorpId;
104
    }
105
106
    /**
107
     * Sets the authorizer corp id.
108
     *
109
     * @param string $authorizerCorpId
110
     *
111
     * @return $this
112
     */
113
    public function setAuthorizerCorpId($authorizerCorpId)
114
    {
115
        $this->authorizerCorpId = $authorizerCorpId;
116
117
        return $this;
118
    }
119
120
    /**
121
     * Gets the authorizer access token.
122
     *
123
     * @return string
124
     */
125
    public function getAuthorizerAccessToken()
126
    {
127
        return $this->cache->fetch($this->getAuthorizerAccessTokenKey());
128
    }
129
130
    /**
131
     * Saves the authorizer refresh token in cache.
132
     *
133
     * @param string $permanentCode
134
     *
135
     * @return bool TRUE if the entry was successfully stored in the cache, FALSE otherwise
136
     */
137
    public function setAuthorizerPermanentCode($permanentCode)
138
    {
139
        return $this->cache->save($this->getAuthorizerPermanentCodeKey(), $permanentCode);
140
    }
141
142
    /**
143
     * Gets the authorizer refresh token cache key.
144
     *
145
     * @return string
146
     */
147
    public function getAuthorizerPermanentCodeKey()
148
    {
149
        return self::CACHE_KEY_PERMANENT_CODE.$this->suiteId.$this->getAuthorizerCorpId();
150
    }
151
152
    /**
153
     * Gets the authorizer refresh token.
154
     *
155
     * @throws \EntWeChat\Core\Exception when refresh token is not present
156
     *
157
     * @return string
158
     */
159
    public function getAuthorizerPermanentCode()
160
    {
161
        if ($permanentCode = $this->cache->fetch($this->getAuthorizerPermanentCodeKey())) {
162
            return $permanentCode;
163
        }
164
165
        throw new Exception(
166
            'Authorizer Permanent Code is not present, you may not make the authorization yet.'
167
        );
168
    }
169
170
    /**
171
     * Removes the authorizer access token from cache.
172
     *
173
     * @return bool TRUE if the cache entry was successfully deleted, FALSE otherwise.
174
     *              Deleting a non-existing entry is considered successful
175
     */
176
    public function removeAuthorizerAccessToken()
177
    {
178
        return $this->cache->delete($this->getAuthorizerAccessTokenKey());
179
    }
180
181
    /**
182
     * Removes the authorizer refresh token from cache.
183
     *
184
     * @return bool TRUE if the cache entry was successfully deleted, FALSE otherwise.
185
     *              Deleting a non-existing entry is considered successful
186
     */
187
    public function removeAuthorizerPermanentCode()
188
    {
189
        return $this->cache->delete($this->getAuthorizerPermanentCodeKey());
190
    }
191
}
192