Issues (19)

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/Request/PollMessagesRequest.php (1 issue)

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
 * This file is part of the slince/smartqq package.
4
 *
5
 * (c) Slince <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace Slince\SmartQQ\Request;
12
13
use GuzzleHttp\Psr7\Response;
14
use Slince\SmartQQ\Credential;
15
use Slince\SmartQQ\Exception\Code103ResponseException;
16
use Slince\SmartQQ\Exception\ResponseException;
17
use Slince\SmartQQ\Exception\RuntimeException;
18
use Slince\SmartQQ\Message\Content;
19
use Slince\SmartQQ\Message\Font;
20
use Slince\SmartQQ\Message\Response\DiscussMessage;
21
use Slince\SmartQQ\Message\Response\FriendMessage;
22
use Slince\SmartQQ\Message\Response\GroupMessage;
23
use Slince\SmartQQ\Message\Response\Message;
24
25
class PollMessagesRequest extends Request
26
{
27
    protected $uri = 'http://d1.web2.qq.com/channel/poll2';
28
29
    protected $referer = 'http://d1.web2.qq.com/proxy.html?v=20151105001&callback=1&id=2';
30
31
    protected $method = RequestInterface::REQUEST_METHOD_POST;
32
33
    public function __construct(Credential $credential)
34
    {
35
        $this->setParameter('r', \GuzzleHttp\json_encode([
36
            'ptwebqq' => '',
37
            'clientid' => $credential->getClientId(),
38
            'psessionid' => $credential->getPSessionId(),
39
            'key' => '',
40
        ]));
41
    }
42
43
    /**
44
     * 解析响应数据.
45
     *
46
     * @param Response $response
47
     *
48
     * @return Message[]
49
     */
50
    public static function parseResponse(Response $response)
51
    {
52
        $jsonData = \GuzzleHttp\json_decode($response->getBody(), true);
53
        if ($jsonData && 0 == $jsonData['retcode'] && !empty($jsonData['result'])) {
54
            $messages = [];
55
            foreach ($jsonData['result'] as $messageData) {
56
                $messages[] = static::makeResponseMessage($messageData['poll_type'], $messageData);
57
            }
58
59
            return $messages;
60
        } elseif (103 == $jsonData['retcode']) {
61
            throw new Code103ResponseException($response);
62
        }
63
        throw new ResponseException($jsonData['retcode'], $response);
64
    }
65
66
    protected static function makeResponseMessage($type, $messageData)
67
    {
68
        $contents = $messageData['value']['content'];
69
        //消息正文
70
        $content = static::parseContents($contents);
71
        switch ($messageData['poll_type']) {
72
            case Message::TYPE_FRIEND:
73
                $message = new FriendMessage(
74
                    $messageData['value']['to_uin'],
75
                    $messageData['value']['from_uin'],
76
                    $content,
77
                    $messageData['value']['time'],
78
                    $messageData['value']['msg_id'],
79
                    $messageData['value']['msg_type']
80
                );
81
                break;
82
            case Message::TYPE_GROUP:
83
                $message = new GroupMessage(
84
                    $messageData['value']['to_uin'],
85
                    $messageData['value']['from_uin'],
86
                    $messageData['value']['group_code'],
87
                    $messageData['value']['send_uin'],
88
                    $content,
89
                    $messageData['value']['time'],
90
                    $messageData['value']['msg_id'],
91
                    $messageData['value']['msg_type']
92
                );
93
                break;
94
            case Message::TYPE_DISCUSS:
95
                $message = new DiscussMessage(
96
                    $messageData['value']['to_uin'],
97
                    $messageData['value']['from_uin'],
98
                    $messageData['value']['did'],
99
                    $messageData['value']['send_uin'],
100
                    $content,
101
                    $messageData['value']['time'],
102
                    $messageData['value']['msg_id'],
103
                    $messageData['value']['msg_type']
104
                );
105
                break;
106
            default:
107
                throw new RuntimeException(sprintf('Unknown message type [%s]', $type));
108
                break;
0 ignored issues
show
break; does not seem to be reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
109
        }
110
111
        return $message;
112
    }
113
114
    /**
115
     * Parse Contents.
116
     *
117
     * @param array $contents
118
     *
119
     * @return Content
120
     */
121
    protected static function parseContents($contents)
122
    {
123
        //正文字体
124
        $fontParameters = $contents[0][1];
125
        $font = new Font(
126
            $fontParameters['name'],
127
            $fontParameters['color'],
128
            $fontParameters['size'],
129
            $fontParameters['style']
130
        );
131
        unset($contents[0]);
132
        $contentString = implode('', array_map(function ($content) {
133
            if ($content && is_array($content) && 'face' === $content[0]) { //处理表情
134
                $faceText = Content::searchFaceText($content[1]);
135
136
                return $faceText ? '['.$faceText.']' : '';
137
            } else {
138
                return (string) $content;
139
            }
140
        }, $contents));
141
142
        return new Content($contentString, $font);
143
    }
144
}
145