Issues (100)

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/F2fpay/Kernel/AopClient.php (7 issues)

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
 * Created by PhpStorm.
4
 * User: kaylv <[email protected]>
5
 * Date: 2019/10/16
6
 * Time: 11:05
7
 */
8
9
namespace Kaylyu\Alipay\F2fpay\Kernel;
10
11
use Kaylyu\Alipay\F2fpay\Base\Aop\AopClient as BaseAopClient;
12
use Kaylyu\Alipay\Kernel\Exceptions\Exception;
13
14
class AopClient extends BaseAopClient
15
{
16
    /**
17
     * 准备请求参数
18
     * @param $request
19
     * @param null $authToken
20
     * @param null $appInfoAuthtoken
21
     * @author kaylv <[email protected]>
22
     * @return array
23
     * @throws Exception
24
     */
25
    public function requestPrepare($request, $authToken = null, $appInfoAuthtoken = null)
26
    {
27
28
        $this->setupCharsets($request);
29
30
        //		//  如果两者编码不一致,会出现签名验签或者乱码
31 View Code Duplication
        if (strcasecmp($this->fileCharset, $this->postCharset)) {
0 ignored issues
show
This code seems to be duplicated across 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...
32
33
            // writeLog("本地文件字符集编码与表单提交编码不一致,请务必设置成一样,属性名分别为postCharset!");
34
            throw new Exception("文件编码:[" . $this->fileCharset . "] 与表单提交编码:[" . $this->postCharset . "]两者不一致!");
35
        }
36
37
        $iv = null;
0 ignored issues
show
$iv is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
38
39
        if (!$this->checkEmpty($request->getApiVersion())) {
40
            $iv = $request->getApiVersion();
41
        } else {
42
            $iv = $this->apiVersion;
43
        }
44
45
        //组装系统参数
46
        $sysParams["app_id"] = $this->appId;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$sysParams was never initialized. Although not strictly required by PHP, it is generally a good practice to add $sysParams = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
47
        $sysParams["version"] = $iv;
48
        $sysParams["format"] = $this->format;
49
        $sysParams["sign_type"] = $this->signType;
50
        $sysParams["method"] = $request->getApiMethodName();
51
        $sysParams["timestamp"] = date("Y-m-d H:i:s");
52
        $sysParams["auth_token"] = $authToken;
53
        $sysParams["alipay_sdk"] = $this->alipaySdkVersion;
54
        $sysParams["terminal_type"] = $request->getTerminalType();
55
        $sysParams["terminal_info"] = $request->getTerminalInfo();
56
        $sysParams["prod_code"] = $request->getProdCode();
57
        $sysParams["notify_url"] = $request->getNotifyUrl();
58
        $sysParams["charset"] = $this->postCharset;
59
        $sysParams["app_auth_token"] = $appInfoAuthtoken;
60
61
        //获取业务参数
62
        $apiParams = $request->getApiParas();
63
64 View Code Duplication
        if (method_exists($request, "getNeedEncrypt") && $request->getNeedEncrypt()) {
0 ignored issues
show
This code seems to be duplicated across 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...
65
66
            $sysParams["encrypt_type"] = $this->encryptType;
67
68
            if ($this->checkEmpty($apiParams['biz_content'])) {
69
70
                throw new Exception(" api request Fail! The reason : encrypt request is not supperted!");
71
            }
72
73
            if ($this->checkEmpty($this->encryptKey) || $this->checkEmpty($this->encryptType)) {
74
75
                throw new Exception(" encryptType and encryptKey must not null! ");
76
            }
77
78
            if ("AES" != $this->encryptType) {
79
80
                throw new Exception("加密类型只支持AES");
81
            }
82
83
            // 执行加密
84
            $enCryptContent = \Kaylyu\Alipay\F2fpay\Base\Aop\encrypt($apiParams['biz_content'], $this->encryptKey);
85
            $apiParams['biz_content'] = $enCryptContent;
86
        }
87
        //签名
88
        $sysParams["sign"] = $this->generateSign(array_merge($apiParams, $sysParams), $this->signType);
89
90
91
        //系统参数放入GET请求串
92
        $requestUrl = $this->gatewayUrl . "?";
93 View Code Duplication
        foreach ($sysParams as $sysParamKey => $sysParamValue) {
0 ignored issues
show
This code seems to be duplicated across 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...
94
            $requestUrl .= "$sysParamKey=" . urlencode($this->characet($sysParamValue, $this->postCharset)) . "&";
95
        }
96
        $requestUrl = substr($requestUrl, 0, -1);
97
98
        return [$requestUrl, $apiParams];
99
    }
100
101
    /**
102
     * 处理响应
103
     * @param $request
104
     * @param $response
105
     * @author kaylv <[email protected]>
106
     * @return bool|mixed|\SimpleXMLElement
107
     */
108
    public function responseHandle($request, $response)
109
    {
110
        //解析AOP返回结果
111
        $respWellFormed = false;
112
113
        // 将返回结果转换本地文件编码
114
        $r = iconv($this->postCharset, $this->fileCharset . "//IGNORE", $response);
115
116
        //存放数据
117
        $signData = null;
118
        $respObject = null;
119
120 View Code Duplication
        if ("json" == $this->format) {
0 ignored issues
show
This code seems to be duplicated across 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...
121
122
            $respObject = json_decode($r);
123
            if (null !== $respObject) {
124
                $respWellFormed = true;
125
                $signData = $this->parserJSONSignData($request, $response, $respObject);
126
            }
127
        } else {
128
            if ("xml" == $this->format) {
129
130
                $respObject = @ simplexml_load_string($response);
131
                if (false !== $respObject) {
132
                    $respWellFormed = true;
133
134
                    $signData = $this->parserXMLSignData($request, $response);
135
                }
136
            }
137
        }
138
139
        //返回的HTTP文本不是标准JSON或者XML,记下错误日志
140
        if (false === $respWellFormed) {
141
            return false;
142
        }
143
144
        // 验签
145
        $this->checkResponseSign($request, $signData, $response, $respObject);
146
147
        // 解密
148 View Code Duplication
        if (method_exists($request, "getNeedEncrypt") && $request->getNeedEncrypt()) {
0 ignored issues
show
This code seems to be duplicated across 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...
149
            if ("json" == $this->format) {
150
                $resp = $this->encryptJSONSignSource($request, $response);
151
152
                // 将返回结果转换本地文件编码
153
                $r = iconv($this->postCharset, $this->fileCharset . "//IGNORE", $resp);
154
                $respObject = json_decode($r);
155
            } else {
156
                $resp = $this->encryptXMLSignSource($request, $response);
157
158
                $r = iconv($this->postCharset, $this->fileCharset . "//IGNORE", $resp);
159
                $respObject = @ simplexml_load_string($r);
160
            }
161
        }
162
163
        return $respObject;
164
    }
165
}