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/Contact.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 Contact.
13
 */
14
class Contact 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
     * Group ticket cache prefix.
32
     */
33
    const GROUP_TICKET_CACHE_PREFIX = 'entwechat.group_ticket.';
34
35
    /**
36
     * Api of group ticket.
37
     */
38
    const API_GROUP_TICKET = 'https://qyapi.weixin.qq.com/cgi-bin/ticket/get';
39
40
    /**
41
     * Get config json for jsapi.
42
     *
43
     * @param array $params
44
     * @param bool  $json
45
     *
46
     * @return array|string
47
     */
48
    public function config(array $params, $json = true)
49
    {
50
        $signPackage = $this->signature();
51
52
        $config = array_merge($signPackage, ['params' => $params]);
53
54
        return $json ? json_encode($config) : $config;
55
    }
56
57
    /**
58
     * Return jsapi config as a PHP array.
59
     *
60
     * @param array $params
61
     *
62
     * @return array
63
     */
64
    public function getConfigArray(array $params)
65
    {
66
        return $this->config($params, false);
67
    }
68
69
    /**
70
     * Get ticket.
71
     *
72
     * @param bool $forceRefresh
73
     *
74
     * @return string
75
     */
76 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...
77
    {
78
        $key = self::GROUP_TICKET_CACHE_PREFIX.$this->getAccessToken()->getFingerprint();
79
        $ticket = $this->getCache()->fetch($key);
80
81
        if (!$forceRefresh && !empty($ticket)) {
82
            return $ticket;
83
        }
84
85
        $result = $this->parseJSON('get', [self::API_GROUP_TICKET, ['type' => 'contact']]);
86
87
        $this->getCache()->save($key, $result, $result['expires_in'] - 500);
88
89
        return $result;
90
    }
91
92
    /**
93
     * Build signature.
94
     *
95
     * @param string $url
96
     * @param string $nonce
97
     * @param int    $timestamp
98
     *
99
     * @return array
100
     */
101
    public function signature($url = null, $nonce = null, $timestamp = null)
102
    {
103
        $url = $url ? $url : $this->getUrl();
104
        $nonce = $nonce ? $nonce : Str::quickRandom(10);
105
        $timestamp = $timestamp ? $timestamp : time();
106
        $ticket = $this->ticket();
107
108
        $sign = [
109
            'groupId'   => $ticket['group_id'],
110
            'nonceStr'  => $nonce,
111
            'timestamp' => $timestamp,
112
            'signature' => $this->getSignature($ticket['ticket'], $nonce, $timestamp, $url),
113
        ];
114
115
        return $sign;
116
    }
117
118
    /**
119
     * Sign the params.
120
     *
121
     * @param string $ticket
122
     * @param string $nonce
123
     * @param int    $timestamp
124
     * @param string $url
125
     *
126
     * @return string
127
     */
128
    public function getSignature($ticket, $nonce, $timestamp, $url)
129
    {
130
        return sha1("group_ticket={$ticket}&noncestr={$nonce}&timestamp={$timestamp}&url={$url}");
131
    }
132
133
    /**
134
     * Set current url.
135
     *
136
     * @param string $url
137
     *
138
     * @return Contact
139
     */
140
    public function setUrl($url)
141
    {
142
        $this->url = $url;
143
144
        return $this;
145
    }
146
147
    /**
148
     * Get current url.
149
     *
150
     * @return string
151
     */
152
    public function getUrl()
153
    {
154
        if ($this->url) {
155
            return $this->url;
156
        }
157
158
        return UrlHelper::current();
159
    }
160
161
    /**
162
     * Set cache manager.
163
     *
164
     * @param \Doctrine\Common\Cache\Cache $cache
165
     *
166
     * @return $this
167
     */
168
    public function setCache(Cache $cache)
169
    {
170
        $this->cache = $cache;
171
172
        return $this;
173
    }
174
175
    /**
176
     * Return cache manager.
177
     *
178
     * @return \Doctrine\Common\Cache\Cache
179
     */
180
    public function getCache()
181
    {
182
        return $this->cache ?: $this->cache = new FilesystemCache(sys_get_temp_dir());
183
    }
184
}
185