Skip to content

Commit 0c9d9df

Browse files
authored
Merge pull request #104 from Tinywan/main
fix:优化检测是否是合法URL Path 支持http图片链接地址
2 parents 0573741 + 308400a commit 0c9d9df

File tree

12 files changed

+46
-45
lines changed

12 files changed

+46
-45
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ src/plugin/admin/public/upload
77
src/plugin/admin/config/database.php
88
src/plugin/admin/config/thinkorm.php
99
src/plugin/admin.zip
10+
composer.lock

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
"webman/event": "^1.0",
1313
"webman/captcha": "^1.0.0",
1414
"guzzlehttp/guzzle": "^7.5",
15-
"laravel/serializable-closure": "^1.0"
15+
"laravel/serializable-closure": "^1.0",
16+
"ext-json": "*"
1617
},
1718
"autoload": {
1819
"psr-4": {

src/plugin/admin/api/Menu.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
<?php
22
namespace plugin\admin\api;
33

4-
use plugin\admin\app\model\Role;
54
use plugin\admin\app\model\Rule;
6-
use support\exception\BusinessException;
7-
use function admin;
85

96
/**
107
* 对外提供的菜单接口

src/plugin/admin/app/common/Auth.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,16 @@
22
namespace plugin\admin\app\common;
33

44

5-
use plugin\admin\app\model\Admin;
65
use plugin\admin\app\model\AdminRole;
76
use plugin\admin\app\model\Role;
8-
use plugin\admin\app\model\Rule;
97

108
class Auth
119
{
1210
/**
1311
* 获取权限范围内的所有角色id
1412
* @param bool $with_self
1513
* @return array
14+
* @throws \Exception
1615
*/
1716
public static function getScopeRoleIds(bool $with_self = false): array
1817
{
@@ -35,6 +34,7 @@ public static function getScopeRoleIds(bool $with_self = false): array
3534
* 获取权限范围内的所有管理员id
3635
* @param bool $with_self
3736
* @return array
37+
* @throws \Exception
3838
*/
3939
public static function getScopeAdminIds(bool $with_self = false): array
4040
{
@@ -62,6 +62,7 @@ public static function isSupperAdmin(int $admin_id = 0): bool
6262
* 是否是超级管理员
6363
* @param int $admin_id
6464
* @return bool
65+
* @throws \Exception
6566
*/
6667
public static function isSuperAdmin(int $admin_id = 0): bool
6768
{

src/plugin/admin/app/common/Layui.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
<?php
22
namespace plugin\admin\app\common;
33

4-
use plugin\admin\app\common\Util;
54
use support\exception\BusinessException;
65

76
class Layui

src/plugin/admin/app/common/Util.php

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ public static function passwordHash($password, string $algo = PASSWORD_DEFAULT)
2727

2828
/**
2929
* 验证密码哈希
30-
* @param $password
31-
* @param $hash
30+
* @param string $password
31+
* @param string $hash
3232
* @return bool
3333
*/
3434
public static function passwordVerify(string $password, string $hash): bool
@@ -109,7 +109,7 @@ public static function formatBytes($file_size): string
109109
*/
110110
public static function pdoQuote($var)
111111
{
112-
return Util::db()->getPdo()->quote($var, \PDO::PARAM_STR);
112+
return Util::db()->getPdo()->quote($var);
113113
}
114114

115115
/**
@@ -161,15 +161,23 @@ public static function filterNum($var)
161161
}
162162

163163
/**
164-
* 检测是否是合法URL Path
164+
* @desc 检测是否是合法URL Path
165165
* @param $var
166166
* @return string
167167
* @throws BusinessException
168168
*/
169169
public static function filterUrlPath($var): string
170170
{
171-
if (!is_string($var) || !preg_match('/^[a-zA-Z0-9_\-\/&?.]+$/', $var)) {
172-
throw new BusinessException('参数不合法');
171+
if (!is_string($var)) {
172+
throw new BusinessException('参数不合法,地址必须是一个字符串!');
173+
}
174+
175+
if (strpos($var, 'https://') === 0 || strpos($var, 'http://') === 0) {
176+
if (!filter_var($var, FILTER_VALIDATE_URL)) {
177+
throw new BusinessException('参数不合法,不是合法的URL地址!');
178+
}
179+
} elseif (!preg_match('/^[a-zA-Z0-9_\-\/&?.]+$/', $var)) {
180+
throw new BusinessException('参数不合法,不是合法的Path!');
173181
}
174182
return $var;
175183
}

src/plugin/admin/app/controller/DevController.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace plugin\admin\app\controller;
44

5-
use support\Request;
65
use support\Response;
76
use Throwable;
87

src/plugin/admin/app/controller/InstallController.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
use Illuminate\Database\Capsule\Manager;
66
use plugin\admin\app\common\Util;
7-
use plugin\admin\app\model\Admin;
87
use support\exception\BusinessException;
98
use support\Request;
109
use support\Response;

src/plugin/admin/app/controller/PluginController.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
use GuzzleHttp\Client;
66
use GuzzleHttp\Exception\GuzzleException;
77
use plugin\admin\app\common\Util;
8-
use plugin\admin\app\controller\Base;
98
use process\Monitor;
109
use support\exception\BusinessException;
1110
use support\Log;

src/plugin/admin/app/controller/RoleController.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ public function delete(Request $request): Response
188188
* 获取角色权限
189189
* @param Request $request
190190
* @return Response
191+
* @throws \Exception
191192
*/
192193
public function rules(Request $request): Response
193194
{

0 commit comments

Comments
 (0)