Issues (13)

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/Contracts/Sms.php (2 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
namespace Laravelsms\Sms\Contracts;
4
5
abstract class Sms
6
{
7
    protected $signName;
8
    protected $templateId;
9
    protected $content;
10
    protected $templateVar = [];
11
    protected $verifyCode;
12
13
    /**
14
     * @return string
15
     */
16
    private function getAgentName()
17
    {
18
        $formattedClassName = explode('\\', get_called_class());
19
        if (count($formattedClassName) > 0) {
20
            $agentFileName = end($formattedClassName);
21
            $agents = config("sms.agents");
22
            foreach ($agents as $key => $value) {
23
                if (strcmp($value['executableFile'], $agentFileName) == 0)
24
                    return $key;
25
            }
26
        }
27
        throw new \InvalidArgumentException("Unauthorized access.");
28
    }
29
30
    /**
31
     * @return string
32
     */
33
    protected function getTemplateContentByConfig()
34
    {
35
        $name = $this->getAgentName();
36
        return config("sms.agents.{$name}.templateContent");
37
    }
38
39
    /**
40
     * @param integer $time
41
     */
42
    public function setContentByVerifyCode($time = null)
43
    {
44
        $this->verifyCode = $this->makeRandom();
45
        if (empty($this->content)) {
46
            $this->content = $this->getTemplateContentByConfig();
47
        }
48
        $this->content = str_replace('{verifyCode}', $this->verifyCode, $this->content);
49
        if (!empty($time)) {
50
            $this->content = str_replace('{time}', $time, $this->content);
51
        }
52
    }
53
54
    /**
55
     * @param array $templateVar
56
     */
57
    public function setContentByCustomVar($templateVar = [])
58
    {
59
        if (empty($this->content)) {
60
            $this->content = $this->getTemplateContentByConfig();
61
        }
62
63
        $count = count($templateVar);
64
        if (is_array($templateVar) && $count > 0) {
65
            foreach ($templateVar as $key => $value) {
66
                $this->content = str_replace("{" . $key . "}", $value, $this->content);
67
            }
68
        } else {
69
            $this->content = '';
70
        }
71
    }
72
73
    /**
74
     * @param string $content
75
     */
76
    public function setContent($content)
77
    {
78
        $this->content = is_string(trim($content)) ? $content : '';
79
    }
80
81
    /**
82
     * @return string
83
     */
84
    public function getContent()
85
    {
86
        return $this->content;
87
    }
88
89
    /**
90
     * @param array $templateVar
91
     * @param bool $hasKey
92
     */
93
    public function setTemplateVar($templateVar = [], $hasKey = false)
94
    {
95
        $count = count($templateVar);
96
97
        if (is_array($templateVar) && $count > 0) {
98
            foreach ($templateVar as $key => $value) {
99
                if ($hasKey) {
100 View Code Duplication
                    if ($value == 'verifyCode') {
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...
101
                        $this->verifyCode = $this->makeRandom();
102
                        $this->templateVar[$key] = "{$this->verifyCode}";
103
                    } else {
104
                        $this->templateVar[$key] = "{$value}";
105
                    }
106 View Code Duplication
                } else {
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...
107
                    if ($value == 'verifyCode') {
108
                        $this->verifyCode = $this->makeRandom();
109
                        $this->templateVar[] = "{$this->verifyCode}";
110
                    } else {
111
                        $this->templateVar[] = "{$value}";
112
                    }
113
                }
114
            }
115
        } else {
116
            $this->templateVar = [];
117
        }
118
    }
119
120
    /**
121
     * @return string
122
     */
123
    public function getTemplateVar()
124
    {
125
        return $this->templateVar;
126
    }
127
128
    /**
129
     * @param string $signName
130
     */
131
    public function setSignName($signName = null)
132
    {
133
        $this->signName = trim($signName) ?: trim(config('sms.signName'), '{}');
134
    }
135
136
    /**
137
     * @return string
138
     */
139
    public function getSignName()
140
    {
141
        return $this->signName;
142
    }
143
144
    /**
145
     * @param mixed $id
146
     */
147
    public function setTemplateId($id = null)
148
    {
149
        $this->templateId = $id ?: 1;
150
    }
151
152
    /**
153
     * @return string
154
     */
155
    public function getTemplateId()
156
    {
157
        return $this->templateId;
158
    }
159
160
    /**
161
     * @return void
162
     */
163
    abstract protected function transformConfig();
164
165
    /**
166
     * @param string $mobile
167
     * @param bool $send
168
     * @return mixed
169
     */
170
    abstract protected function singlesSend($mobile, $send = true);
171
172
    /**
173
     * @param string $url
174
     * @param array $params
175
     * @return array
176
     */
177
    abstract protected function curl($url, $params);
178
179
    /**
180
     * @param $ch
181
     * @return array
182
     */
183
    abstract protected function transformerResponse($ch);
184
185
    /**
186
     * @param $ch
187
     * @return array
188
     */
189
    protected function httpResponse($ch)
190
    {
191
        $retry = 0;
192
        do {
193
            $jsonData = curl_exec($ch);
194
            $retry++;
195
        } while (curl_errno($ch) && $retry < 3);
196
197
        if (curl_errno($ch)) {
198
            $response = ['error' => 1, 'msg' => curl_error($ch)];
199
        } else {
200
            $response = ['error' => 0, 'jsonData' => $jsonData];
201
        }
202
203
        return $response;
204
    }
205
206
    /**
207
     * @return int
208
     */
209
    protected function makeRandom()
210
    {
211
        return random_int(100000, 999999);
212
    }
213
}
214