Issues (2366)

Branch: master

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/Eccube/Util/Str.php (28 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
 * This file is part of EC-CUBE
4
 *
5
 * Copyright(c) 2000-2015 LOCKON CO.,LTD. All Rights Reserved.
6
 *
7
 * http://www.lockon.co.jp/
8
 *
9
 * This program is free software; you can redistribute it and/or
10
 * modify it under the terms of the GNU General Public License
11
 * as published by the Free Software Foundation; either version 2
12
 * of the License, or (at your option) any later version.
13
 *
14
 * This program is distributed in the hope that it will be useful,
15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 * GNU General Public License for more details.
18
 *
19
 * You should have received a copy of the GNU General Public License
20
 * along with this program; if not, write to the Free Software
21
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22
 */
23
24
namespace Eccube\Util;
25
26
use Doctrine\Common\Collections\ArrayCollection;
27
28
class Str
0 ignored issues
show
Missing class doc comment
Loading history...
29
{
30
31
    /**
32
     * The MIT License (MIT)
33
     *
34
     * Copyright (c) <Taylor Otwell>
35
     *
36
     * Permission is hereby granted, free of charge, to any person obtaining a copy
37
     * of this software and associated documentation files (the "Software"), to deal
38
     * in the Software without restriction, including without limitation the rights
39
     * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
40
     * copies of the Software, and to permit persons to whom the Software is
41
     * furnished to do so, subject to the following conditions:
42
     *
43
     * The above copyright notice and this permission notice shall be included in
44
     * all copies or substantial portions of the Software.
45
     *
46
     * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
47
     * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
48
     * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
49
     * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
50
     * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
51
     * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
52
     * THE SOFTWARE
53
     *
54
     * Generate a more truly "random" alpha-numeric string.
55
     *
56
     * @param  int $length
57
     * @return string
58
     *
59
     * @throws \RuntimeException
60
     */
61 59
    public static function random($length = 16)
62
    {
63
        if (function_exists('openssl_random_pseudo_bytes')) {
64
            $bytes = openssl_random_pseudo_bytes($length * 2);
65
66 59
            if ($bytes === false) {
67
                throw new \RuntimeException('Unable to generate random string.');
68
            }
69
70
            return substr(str_replace(array('/', '+', '='), '', base64_encode($bytes)), 0, $length);
71
        }
72
73
        return static::quickRandom($length);
74 1
    }
75
76
    /**
77
     * The MIT License (MIT)
78
     *
79
     * Copyright (c) <Taylor Otwell>
80
     *
81
     * Permission is hereby granted, free of charge, to any person obtaining a copy
82
     * of this software and associated documentation files (the "Software"), to deal
83
     * in the Software without restriction, including without limitation the rights
84
     * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
85
     * copies of the Software, and to permit persons to whom the Software is
86
     * furnished to do so, subject to the following conditions:
87
     *
88
     * The above copyright notice and this permission notice shall be included in
89
     * all copies or substantial portions of the Software.
90
     *
91
     * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
92
     * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
93
     * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
94
     * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
95
     * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
96
     * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
97
     * THE SOFTWARE
98
     *
99
     * Generate a "random" alpha-numeric string.
100
     *
101
     * Should not be considered sufficient for cryptography, etc.
102
     *
103
     * @param  int $length
104
     * @return string
105
     */
106 2
    public static function quickRandom($length = 16)
107
    {
108 2
        $pool = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
109
110
        return substr(str_shuffle(str_repeat($pool, $length)), 0, $length);
111 1
    }
112
113
114
    /**
0 ignored issues
show
Doc comment for parameter "$value" missing
Loading history...
115
     * 改行コードの変換
116
     *
117
     * @param $value
0 ignored issues
show
Missing parameter name
Loading history...
118
     * @param string $lf
119
     * @return string
120
     */
121 1
    public static function convertLineFeed($value, $lf = "\n")
122
    {
123 1
        if (empty($value)) {
124 1
            return '';
125
        }
126
        return strtr($value, array_fill_keys(array("\r\n", "\r", "\n"), $lf));
0 ignored issues
show
Missing blank line before return statement
Loading history...
127 1
    }
128
129
    /**
0 ignored issues
show
Doc comment for parameter "$value" missing
Loading history...
Doc comment for parameter "$encoding" missing
Loading history...
130
     * 文字コードの判定
131
     *
132
     * @param $value
0 ignored issues
show
Missing parameter name
Loading history...
133
     * @return string
134
     */
135 3
    public static function characterEncoding($value, $encoding = array('UTF-8', 'SJIS', 'EUC-JP', 'ASCII', 'JIS', 'sjis-win'))
136
    {
137
        foreach ($encoding as $encode) {
138
            if (mb_convert_encoding($value, $encode, $encode) == $value) {
139 2
                return $encode;
140
            }
141 1
        }
142
143 1
        return null;
144
145 3
    }
146
147
    /**
148
     * 指定した文字列以上ある場合、「...」を付加する
149
     * lengthに7を指定すると、「1234567890」は「1234567...」と「...」を付与して出力される
150
     *
151
     * @param string $value
152
     * @param int $length
0 ignored issues
show
Expected 4 spaces after parameter type; 1 found
Loading history...
153
     * @param string $end
154
     * @return string
155
     */
156 1
    public static function ellipsis($value, $length = 100, $end = '...')
157
    {
158
        if (mb_strlen($value) <= $length) {
159 1
            return $value;
160
        }
161
162
        return rtrim(mb_substr($value, 0, $length, 'UTF-8')) . $end;
0 ignored issues
show
Concat operator must not be surrounded by spaces
Loading history...
163
    }
164
165
166
    /**
0 ignored issues
show
Doc comment for parameter "$date" missing
Loading history...
167
     * 現在からの経過時間を書式化する.
168
     *
169
     * @param $date
0 ignored issues
show
Missing parameter name
Loading history...
170
     * @return string
171
     */
172 1
    public static function timeAgo($date)
173
    {
174
        if (empty($date)) {
175 1
            return '';
176
        }
177
178
        $now = new \DateTime();
179
        if (!($date instanceof \DateTime)) {
180
            $date = new \DateTime($date);
181
        }
182
        $diff = $date->diff($now, true);
183
        if ($diff->y > 0) {
184
            // return $date->format("Y/m/d H:i");
0 ignored issues
show
Unused Code Comprehensibility introduced by
70% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
185
            return $date->format("Y/m/d");
186
        }
187
        if ($diff->m == 1 || $diff->days > 0) {
188
            if ($diff->days <= 31) {
189
                return $diff->days . '日前';
0 ignored issues
show
Concat operator must not be surrounded by spaces
Loading history...
190
            }
191
            // return $date->format("Y/m/d H:i");
0 ignored issues
show
Unused Code Comprehensibility introduced by
70% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
192
            return $date->format("Y/m/d");
193
        }
194
        if ($diff->h > 0) {
195
            return $diff->h . "時間前";
0 ignored issues
show
Concat operator must not be surrounded by spaces
Loading history...
196
        }
197
        if ($diff->i > 0) {
198
            return $diff->i . "分前";
0 ignored issues
show
Concat operator must not be surrounded by spaces
Loading history...
199
        }
200
        return $diff->s . "秒前";
0 ignored issues
show
Missing blank line before return statement
Loading history...
Concat operator must not be surrounded by spaces
Loading history...
201
    }
202
203
    /**
204
     * 変数が空白かどうかをチェックする.
205
     *
206
     * 引数 $value が空白かどうかをチェックする. 空白の場合は true.
207
     * 以下の文字は空白と判断する.
208
     * - ' ' (ASCII 32 (0x20)), 通常の空白
209
     * - "\t" (ASCII 9 (0x09)), タブ
210
     * - "\n" (ASCII 10 (0x0A)), リターン
211
     * - "\r" (ASCII 13 (0x0D)), 改行
212
     * - "\0" (ASCII 0 (0x00)), NULバイト
213
     * - "\x0B" (ASCII 11 (0x0B)), 垂直タブ
214
     *
215
     * 引数 $value がオブジェクト型、配列の場合は非推奨とし、 E_USER_DEPRECATED をスローする.
216
     * EC-CUBE2系からの互換性、ビギナー層を配慮し、以下のような実装とする.
217
     * 引数 $value が配列の場合は, 空の配列の場合 true を返す.
218
     * 引数 $value が ArrayCollection::isEmpty() == true の場合 true を返す.
219
     * 引数 $value が上記以外のオブジェクト型の場合は false を返す.
220
     *
221
     * 引数 $greedy が true の場合は, 全角スペース, ネストした空の配列も
222
     * 空白と判断する.
223
     *
224
     * @param string $value チェック対象の変数. 文字型以外も使用できるが、非推奨.
0 ignored issues
show
Expected 2 spaces after parameter type; 1 found
Loading history...
Expected 2 spaces after parameter name; 1 found
Loading history...
225
     * @param boolean $greedy '貧欲'にチェックを行う場合 true, デフォルト false
226
     * @return boolean $value が空白と判断された場合 true
227
     */
228 47
    public static function isBlank($value, $greedy = false)
229
    {
230 47
        $deprecated = '\Eccube\Util\Str::isBlank() の第一引数は文字型、数値を使用してください';
231
        // テストカバレッジを上げるために return の前で trigger_error をスローしている
232
        if (is_object($value)) {
233 3
            if ($value instanceof ArrayCollection) {
234
                if ($value->isEmpty()) {
235
                    trigger_error($deprecated, E_USER_DEPRECATED);
236
237 1
                    return true;
238
                } else {
239
                    trigger_error($deprecated, E_USER_DEPRECATED);
240
241 1
                    return false;
242
                }
243
            }
244
            trigger_error($deprecated, E_USER_DEPRECATED);
245 1
            return false;
0 ignored issues
show
Missing blank line before return statement
Loading history...
246
        }
247
        if (is_array($value)) {
248 3
            if ($greedy) {
249 1
                if (empty($value)) {
250
                    trigger_error($deprecated, E_USER_DEPRECATED);
251
252 1
                    return true;
253
                }
254
                $array_result = true;
255
                foreach ($value as $in) {
256
                    $array_result = self::isBlank($in, $greedy);
257
                    if (!$array_result) {
258
                        trigger_error($deprecated, E_USER_DEPRECATED);
259
260
                        return false;
261
                    }
262
                }
263
                trigger_error($deprecated, E_USER_DEPRECATED);
264
265
                return $array_result;
266
            } else {
267
                trigger_error($deprecated, E_USER_DEPRECATED);
268
269 2
                return empty($value);
270
            }
271
        }
272
273 43
        if ($greedy) {
274
            $value = preg_replace('/ /', '', $value);
275
        }
276
277
        $value = trim($value);
278
        if (strlen($value) > 0) {
0 ignored issues
show
Blank line found at start of control structure
Loading history...
279
280 42
            return false;
281
        }
282
283 1
        return true;
284 4
    }
285
286
    /**
0 ignored issues
show
Doc comment for parameter "$value" missing
Loading history...
Doc comment for parameter "$greedy" missing
Loading history...
287
     * @param $value
0 ignored issues
show
Missing parameter name
Loading history...
288
     * @return bool
289
     */
290 42
    public static function isNotBlank($value, $greedy = false)
291
    {
292
        return !self::isBlank($value, $greedy);
293 42
    }
294
295
    /**
0 ignored issues
show
Doc comment for parameter "$value" missing
Loading history...
296
     * 両端にある全角スペース、半角スペースを取り除く
297
     *
298
     * @param $value
0 ignored issues
show
Missing parameter name
Loading history...
299
     * @return string
300
     */
301 1
    public static function trimAll($value)
302
    {
303
        if ($value === '') {
304 1
            return '';
305
        }
306
        if ($value === 0) {
307 1
            return 0;
308
        }
309
        if ($value == null) {
310 1
            return null;
311
        }
312
        return preg_replace('/(^\s+)|(\s+$)/u', '', $value);
0 ignored issues
show
Missing blank line before return statement
Loading history...
313
    }
314
}
315