Issues (233)

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/Utils/Menu/MagicAttributes.php (2 issues)

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
 * MagicAttributes.php
4
 *
5
 * @author Tian.
6
 */
7
8
namespace Wechat\Utils\Menu;
9
10
use InvalidArgumentException;
11
12
/**
13
 * 用于操作通用数组式属性的工具类
14
 */
15
abstract class MagicAttributes
16
{
17
18
    /**
19
     * 允许设置的属性名称
20
     *
21
     * @var array
22
     */
23
    protected $attributes = [];
24
25
    /**
26
     * 方法名转换缓存
27
     *
28
     * @var array
29
     */
30
    protected static $snakeCache = [];
31
32
    /**
33
     * 设置属性
34
     *
35
     * @param $attribute
36
     * @param $value
37
     *
38
     * @return \Wechat\Utils\Menu\MagicAttributes
39
     */
40
    public function setAttribute($attribute, $value)
41
    {
42
        return $this->with($attribute, $value);
43
    }
44
45
    /**
46
     * 设置属性
47
     *
48
     * @param string $attribute
49
     * @param mixed  $value
50
     *
51
     * @return MagicAttributes
52
     */
53
    public function with($attribute, $value)
54
    {
55
        $attribute = $this->snake($attribute);
56
57
        if (!$this->validate($attribute, $value)) {
58
            throw new InvalidArgumentException("错误的属性值'{$attribute}'");
59
        }
60
61
        $this->attributes[$attribute] = $value;
62
63
        return $this;
64
    }
65
66
    /**
67
     * 生成数组
68
     *
69
     * @return array
70
     */
71
    public function toArray()
72
    {
73
        return $this->attributes;
74
    }
75
76
    /**
77
     * 验证
78
     *
79
     * @param string $attribute
80
     * @param mixed  $value
81
     *
82
     * @return bool
83
     */
84
    protected function validate($attribute, $value)
0 ignored issues
show
The parameter $attribute is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
The parameter $value is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
85
    {
86
        return true;
87
    }
88
89
    /**
90
     * 调用不存在的方法
91
     *
92
     * @param string $method
93
     * @param array  $args
94
     *
95
     * @return MagicAttributes
96
     */
97
    public function __call($method, $args)
98
    {
99
        if (stripos($method, 'with') === 0) {
100
            $method = substr($method, 4);
101
        }
102
103
        return $this->with($method, array_shift($args));
104
    }
105
106
    /**
107
     * 魔术读取
108
     *
109
     * @param $property
110
     *
111
     * @return null
112
     */
113
    public function __get($property)
114
    {
115
        return !isset($this->attributes[$property]) ? null : $this->attributes[$property];
116
    }
117
118
    /**
119
     * 魔术写入
120
     *
121
     * @param $property
122
     * @param $value
123
     *
124
     * @return \Wechat\Utils\Menu\MagicAttributes
125
     */
126
    public function __set($property, $value)
127
    {
128
        return $this->with($property, $value);
129
    }
130
131
    /**
132
     * 转换为下划线模式字符串
133
     *
134
     * @param string $value
135
     * @param string $delimiter
136
     *
137
     * @return string
138
     */
139
    protected function snake($value, $delimiter = '_')
140
    {
141
        $key = $value . $delimiter;
142
143
        if (isset(static::$snakeCache[$key])) {
144
            return static::$snakeCache[$key];
145
        }
146
147
        if (!ctype_lower($value)) {
148
            $value = strtolower(preg_replace('/(.)(?=[A-Z])/', '$1' . $delimiter, $value));
149
        }
150
151
        return static::$snakeCache[$key] = $value;
152
    }
153
}
154