Issues (663)

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.

pay/alipay/alipay_notify.php (24 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
 * 类名 alipay_notify
4
 * 功能  支付宝外部服务接口控制
5
 * 版本  0.6
6
 * 日期  2006-6-10
7
 * 作者   http://www.buybay.org
8
  * 联系   Email: [email protected]  Homepage:http://www.buybay.org
9
 * 版权   Copyright2006 Buybay NetTech
10
 */
11
12 View Code Duplication
class alipay_notify {
0 ignored issues
show
This class 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...
13
	var $gateway;
14
	var $security_code;  	//安全校验码
15
	var $partner;
16
	var $sign_type;
17
	var $mysign;
18
	var $_input_charset ;
19
	var $transport;
20
	function alipay_notify($partner,$security_code,$sign_type = "MD5",$_input_charset = "utf-8",$transport= "https") {
0 ignored issues
show
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
21
		$this->partner     =   $partner;
22
		$this->security_code = $security_code;
23
		$this->sign_type = $sign_type;
24
		$this->mysign = "";
25
		$this->_input_charset = $_input_charset ;
26
		$this->transport = $transport;
27
		if($this->transport == "https") {
28
			$this->gateway = "https://www.alipay.com/cooperate/gateway.do?";
29
		} else $this->gateway = "http://notify.alipay.com/trade/notify_query.do?";
30
31
	}
32
	function notify_verify() {   //对notify_url的认证
0 ignored issues
show
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
33
		if($this->transport == "https") {
34
			$veryfy_url = $this->gateway. "service=notify_verify" ."&partner=" .$this->partner. "&notify_id=".$_POST["notify_id"];
35
		} else {
36
			$veryfy_url = $this->gateway. "notify_id=".$_POST["notify_id"]."&partner=" .$this->partner;
37
		}
38
		$veryfy_result = $this->get_verify($veryfy_url);
39
		$post = $this->para_filter($_POST);
40
		$sort_post = $this->arg_sort($post);
41
		while (list ($key, $val) = each ($sort_post)) {
42
			$arg.=$key."=".$val."&";
0 ignored issues
show
The variable $arg does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
43
		}
44
		$prestr = substr($arg,0,count($arg)-2);  //去掉最后一个&号
45
		$this->mysign = $this->sign($prestr.$this->security_code);
46
		if (eregi("true$",$veryfy_result) && $this->mysign == $_POST["sign"])  {
47
			return true;
48
		} else return false;
49
	}
50
	function return_verify() {   //对return_url的认证
0 ignored issues
show
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
51
        if($this->transport == "https") {
52
			$veryfy_url = $this->gateway. "service=notify_verify" ."&partner=" .$this->partner. "&notify_id=".$_GET["notify_id"];
53
		} else {
54
			$veryfy_url = $this->gateway. "notify_id=".$_GET["notify_id"]."&partner=" .$this->partner;
55
		}
56
		$veryfy_result = $this->get_verify($veryfy_url);
57
		$GET = $this->para_filter($_GET);
0 ignored issues
show
$GET 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...
58
		$sort_get= $this->arg_sort($_GET);
59
		while (list ($key, $val) = each ($sort_get)) {
60
			if($key != "sign" && $key != "sign_type")
61
			$arg.=$key."=".$val."&";
0 ignored issues
show
The variable $arg does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
62
		}
63
		$prestr = substr($arg,0,count($arg)-2);  //去掉最后一个&号
64
		$this->mysign = $this->sign($prestr.$this->security_code);
65
	
66
	log_result("return_url_log=".$_GET["sign"]."-------------------".$this->mysign."&".$this->charset_decode(implode(",",$_GET),$this->_input_charset ));
67
	//**********************************上面写日志
68
		if (eregi("true$",$veryfy_result) && $this->mysign == $_GET["sign"])  {
69
			return true;
70
		}else return false;
71
	}
72
73
	function get_verify($url,$time_out = "60") {
0 ignored issues
show
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
74
		$urlarr = parse_url($url);
75
		$errno = "";
76
		$errstr = "";
77
		$transports = "";
0 ignored issues
show
$transports 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...
78
		if($urlarr["scheme"] == "https") {
79
			$transports = "ssl://";
80
			$urlarr["port"] = "443";
81
		} else {
82
			$transports = "tcp://";
83
			$urlarr["port"] = "80";
84
		}
85
		$fp=@fsockopen($transports . $urlarr['host'],$urlarr['port'],$errno,$errstr,$time_out);
86
		if(!$fp) {
87
			die("ERROR: $errno - $errstr<br />\n");
88
		} else {
89
			fputs($fp, "POST ".$urlarr["path"]." HTTP/1.1\r\n");
90
			fputs($fp, "Host: ".$urlarr["host"]."\r\n");
91
			fputs($fp, "Content-type: application/x-www-form-urlencoded\r\n");
92
			fputs($fp, "Content-length: ".strlen($urlarr["query"])."\r\n");
93
			fputs($fp, "Connection: close\r\n\r\n");
94
			fputs($fp, $urlarr["query"] . "\r\n\r\n");
95
			while(!feof($fp)) {
96
				$info[]=@fgets($fp, 1024);
0 ignored issues
show
Coding Style Comprehensibility introduced by
$info was never initialized. Although not strictly required by PHP, it is generally a good practice to add $info = 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...
97
			}
98
99
			fclose($fp);
100
			$info = implode(",",$info);
0 ignored issues
show
The variable $info does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
101
			while (list ($key, $val) = each ($_POST)) {
102
				$arg.=$key."=".$val."&";
0 ignored issues
show
The variable $arg does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
103
			}
104
105
106
			log_result("return_url_log=".$url.$this->charset_decode($info,$this->_input_charset));
107
			log_result("return_url_log=".$this->charset_decode($arg,$this->_input_charset));
108
			return $info;
109
		}
110
111
	}
112
113
	function arg_sort($array) {
0 ignored issues
show
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
114
		ksort($array);
115
		reset($array);
116
		return $array;
117
118
	}
119
120
	function sign($prestr) {
0 ignored issues
show
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
121
		$sign='';
0 ignored issues
show
$sign 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...
122
		if($this->sign_type == 'MD5') {
123
			$sign = md5($prestr);
124
		}elseif($this->sign_type =='DSA') {
125
			//DSA 签名方法待后续开发
126
			die("DSA 签名方法待后续开发,请先使用MD5签名方式");
127
		}else {
128
			die("支付宝暂不支持".$this->sign_type."类型的签名方式");
129
		}
130
		return $sign;
131
132
	}
133
	function para_filter($parameter) { //除去数组中的空值和签名模式
0 ignored issues
show
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
134
		$para = array();
135
		while (list ($key, $val) = each ($parameter)) {
136
			if($key == "sign" || $key == "sign_type" || $val == "")continue;
137
			else	$para[$key] = $parameter[$key];
138
139
		}
140
		return $para;
141
	}
142
143
	//实现多种字符编码方式
144
	function charset_encode($input,$_output_charset ,$_input_charset ="utf-8" ) {
0 ignored issues
show
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
145
		$output = "";
0 ignored issues
show
$output 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...
146
		if(!isset($_output_charset) )$_output_charset  = $this->parameter['_input_charset '];
0 ignored issues
show
The property parameter does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
147
		if($_input_charset == $_output_charset || $input ==null ) {
148
			$output = $input;
149
		} elseif (function_exists("mb_convert_encoding")){
150
			$output = mb_convert_encoding($input,$_output_charset,$_input_charset);
151
		} elseif(function_exists("iconv")) {
152
			$output = iconv($_input_charset,$_output_charset,$input);
153
		} else die("sorry, you have no libs support for charset change.");
154
		return $output;
155
	}
156
157
	//实现多种字符解码方式
158
	function charset_decode($input,$_input_charset ,$_output_charset="utf-8"  ) {
0 ignored issues
show
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
159
		$output = "";
0 ignored issues
show
$output 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...
160
		if(!isset($_input_charset) )$_input_charset  = $this->_input_charset ;
161
		if($_input_charset == $_output_charset || $input ==null ) {
162
			$output = $input;
163
		} elseif (function_exists("mb_convert_encoding")){
164
			$output = mb_convert_encoding($input,$_output_charset,$_input_charset);
165
		} elseif(function_exists("iconv")) {
166
			$output = iconv($_input_charset,$_output_charset,$input);
167
		} else die("sorry, you have no libs support for charset changes.");
168
		return $output;
169
	}
170
}
171
172
?>
0 ignored issues
show
It is not recommended to use PHP's closing tag ?> in files other than templates.

Using a closing tag in PHP files that only contain PHP code is not recommended as you might accidentally add whitespace after the closing tag which would then be output by PHP. This can cause severe problems, for example headers cannot be sent anymore.

A simple precaution is to leave off the closing tag as it is not required, and it also has no negative effects whatsoever.

Loading history...
173