Issues (108)

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/Js/Js.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 EntWeChat\Js;
4
5
use Doctrine\Common\Cache\Cache;
6
use Doctrine\Common\Cache\FilesystemCache;
7
use EntWeChat\Core\AbstractAPI;
8
use EntWeChat\Support\Str;
9
use EntWeChat\Support\Url as UrlHelper;
10
11
/**
12
 * Class Js.
13
 */
14
class Js extends AbstractAPI
15
{
16
    /**
17
     * Cache.
18
     *
19
     * @var Cache
20
     */
21
    protected $cache;
22
23
    /**
24
     * Current URI.
25
     *
26
     * @var string
27
     */
28
    protected $url;
29
30
    /**
31
     * Ticket cache prefix.
32
     */
33
    const TICKET_CACHE_PREFIX = 'entwechat.jsapi_ticket.';
34
35
    /**
36
     * Api of ticket.
37
     */
38
    const API_TICKET = 'https://qyapi.weixin.qq.com/cgi-bin/get_jsapi_ticket';
39
40
    /**
41
     * Get config json for jsapi.
42
     *
43
     * @param array $APIs
44
     * @param bool  $debug
45
     * @param bool  $beta
46
     * @param bool  $json
47
     *
48
     * @return array|string
49
     */
50
    public function config(array $APIs, $debug = false, $beta = false, $json = true)
51
    {
52
        $signPackage = $this->signature();
53
54
        $base = [
55
            'debug' => $debug,
56
            'beta'  => $beta,
57
        ];
58
        $config = array_merge($base, $signPackage, ['jsApiList' => $APIs]);
59
60
        return $json ? json_encode($config) : $config;
61
    }
62
63
    /**
64
     * Return jsapi config as a PHP array.
65
     *
66
     * @param array $APIs
67
     * @param bool  $debug
68
     * @param bool  $beta
69
     *
70
     * @return array
71
     */
72
    public function getConfigArray(array $APIs, $debug = false, $beta = false)
73
    {
74
        return $this->config($APIs, $debug, $beta, false);
75
    }
76
77
    /**
78
     * Get jsticket.
79
     *
80
     * @param bool $forceRefresh
81
     *
82
     * @return string
83
     */
84 View Code Duplication
    public function ticket($forceRefresh = false)
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
85
    {
86
        $key = self::TICKET_CACHE_PREFIX.$this->getAccessToken()->getFingerprint();
87
        $ticket = $this->getCache()->fetch($key);
88
89
        if (!$forceRefresh && !empty($ticket)) {
90
            return $ticket;
91
        }
92
93
        $result = $this->parseJSON('get', [self::API_TICKET]);
94
95
        $this->getCache()->save($key, $result['ticket'], $result['expires_in'] - 500);
96
97
        return $result['ticket'];
98
    }
99
100
    /**
101
     * Build signature.
102
     *
103
     * @param string $url
104
     * @param string $nonce
105
     * @param int    $timestamp
106
     *
107
     * @return array
108
     */
109
    public function signature($url = null, $nonce = null, $timestamp = null)
110
    {
111
        $url = $url ? $url : $this->getUrl();
112
        $nonce = $nonce ? $nonce : Str::quickRandom(10);
113
        $timestamp = $timestamp ? $timestamp : time();
114
        $ticket = $this->ticket();
115
116
        $sign = [
117
            'appId'     => $this->getAccessToken()->getCorpId(),
118
            'nonceStr'  => $nonce,
119
            'timestamp' => $timestamp,
120
            'url'       => $url,
121
            'signature' => $this->getSignature($ticket, $nonce, $timestamp, $url),
122
        ];
123
124
        return $sign;
125
    }
126
127
    /**
128
     * Sign the params.
129
     *
130
     * @param string $ticket
131
     * @param string $nonce
132
     * @param int    $timestamp
133
     * @param string $url
134
     *
135
     * @return string
136
     */
137
    public function getSignature($ticket, $nonce, $timestamp, $url)
138
    {
139
        return sha1("jsapi_ticket={$ticket}&noncestr={$nonce}&timestamp={$timestamp}&url={$url}");
140
    }
141
142
    /**
143
     * Set current url.
144
     *
145
     * @param string $url
146
     *
147
     * @return Js
148
     */
149
    public function setUrl($url)
150
    {
151
        $this->url = $url;
152
153
        return $this;
154
    }
155
156
    /**
157
     * Get current url.
158
     *
159
     * @return string
160
     */
161
    public function getUrl()
162
    {
163
        if ($this->url) {
164
            return $this->url;
165
        }
166
167
        return UrlHelper::current();
168
    }
169
170
    /**
171
     * Set cache manager.
172
     *
173
     * @param \Doctrine\Common\Cache\Cache $cache
174
     *
175
     * @return $this
176
     */
177
    public function setCache(Cache $cache)
178
    {
179
        $this->cache = $cache;
180
181
        return $this;
182
    }
183
184
    /**
185
     * Return cache manager.
186
     *
187
     * @return \Doctrine\Common\Cache\Cache
188
     */
189
    public function getCache()
190
    {
191
        return $this->cache ?: $this->cache = new FilesystemCache(sys_get_temp_dir());
192
    }
193
}
194