Skip to content

Commit 71166cd

Browse files
committed
feat: file security key
1 parent 7eaf62d commit 71166cd

File tree

6 files changed

+45
-13
lines changed

6 files changed

+45
-13
lines changed

module/Member/Util/MemberUtil.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,23 @@ private static function suggestUsernameNickname($memberUserId, $prefix = '用户
347347
]);
348348
}
349349

350+
public static function registerId($id, $data = [])
351+
{
352+
$memberUser = ModelUtil::insert('member_user', array_merge([
353+
'id' => $id,
354+
'status' => MemberStatus::NORMAL,
355+
'vipId' => MemberVipUtil::defaultVipId(),
356+
'groupId' => MemberGroupUtil::defaultGroupId(),
357+
'isDeleted' => false,
358+
], $data));
359+
return Response::generate(0, 'ok', $memberUser);
360+
}
361+
362+
public static function registerUsername($username)
363+
{
364+
return self::register($username, '', '', '', true);
365+
}
366+
350367
public static function registerUsernameQuick($username)
351368
{
352369
$suggestionUsername = $username;
@@ -558,6 +575,9 @@ public static function changePassword($memberUserId, $new, $old = null, $ignoreO
558575
*/
559576
public static function setAvatar($userId, $avatarData, $avatarExt = 'jpg')
560577
{
578+
if (!in_array($avatarExt, ['jpg', 'jpeg', 'png', 'gif'])) {
579+
return Response::generate(-1, '图片格式不正确');
580+
}
561581
$memberUser = self::get($userId);
562582
if (empty($memberUser)) {
563583
return Response::generate(-1, '用户不存在');

module/Vendor/Middleware/NoneLoginOperateAuthMiddleware.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ class NoneLoginOperateAuthMiddleware
2121
*/
2222
public function handle($request, \Closure $next)
2323
{
24-
$appKey = config('env.APP_KEY');
25-
BizException::throwsIfEmpty('APP_KEY为空', $appKey);
2624
$input = InputPackage::buildFromInput();
2725
$timestamp = $input->getInteger('timestamp');
2826
BizException::throwsIf('已超时效(操作时间显示为24小时内,timestamp=' . time() . '', !($timestamp <= time() && $timestamp > time() - TimeUtil::PERIOD_DAY));
@@ -34,4 +32,4 @@ public function handle($request, \Closure $next)
3432
BizException::throwsIf('sign错误', $sign != $signCalc);
3533
return $next($request);
3634
}
37-
}
35+
}

module/Vendor/Util/NoneLoginOperateUtil.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use ModStart\Core\Exception\BizException;
88
use ModStart\Core\Input\Request;
9+
use ModStart\Core\Util\EnvUtil;
910
use ModStart\Core\Util\RandomUtil;
1011

1112
class NoneLoginOperateUtil
@@ -25,8 +26,7 @@ public static function generateUrl($url, $param = [], $domainUrl = null)
2526

2627
public static function sign($url, $nonce, $timestamp, $param)
2728
{
28-
$appKey = config('env.APP_KEY');
29-
BizException::throwsIfEmpty('APP_KEY为空', $appKey);
30-
return md5($url . ':' . $appKey . ':' . $nonce . ':' . $timestamp . ':' . $param);
29+
$securityKey = EnvUtil::securityKey();
30+
return md5($url . ':' . $securityKey . ':' . $nonce . ':' . $timestamp . ':' . $param);
3131
}
3232
}

vendor/modstart/modstart/src/Command/ModuleInstallAllCommand.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ public function handle()
5050
if (ModelUtil::count('admin_user') <= 0) {
5151
foreach ($initUsers as $initUser) {
5252
Admin::add($initUser['user'], $initUser['password']);
53+
$this->warn(">>> Init User: {$initUser['user']}");
5354
}
5455
}
5556
}

vendor/modstart/modstart/src/Core/Util/EnvUtil.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,13 @@ public static function iniFileConfig($key)
3737
{
3838
return @ini_get($key);
3939
}
40+
41+
public static function securityKey()
42+
{
43+
static $key = null;
44+
if (null === $key) {
45+
$key = md5(json_encode(config('env')));
46+
}
47+
return $key;
48+
}
4049
}

vendor/modstart/modstart/src/Core/Util/FileUtil.php

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -599,9 +599,9 @@ public static function fopenGetContext()
599599
/**
600600
* 将远程文件保存为本地可用
601601
* @param $path string 可以为 http://example.com/xxxxx.xxx /data/xxxxx.xxx
602-
* @param string $ext 文件后缀
603-
* @param string $downloadStream 是否使用流下载
604-
* @return string|null 返回本地临时路径或本地文件绝对路径,注意使用safeCleanLocalTemp来清理文件,如果是本地其他路径可能会误删
602+
* @param $ext string 文件后缀
603+
* @param $downloadStream boolean 是否使用流下载,默认为false
604+
* @return string|null 返回本地临时路径或本地文件绝对路径,注意使用 safeCleanLocalTemp 来清理文件,如果是本地其他路径可能会误删
605605
*/
606606
public static function savePathToLocalTemp($path, $ext = null, $downloadStream = false)
607607
{
@@ -611,8 +611,12 @@ public static function savePathToLocalTemp($path, $ext = null, $downloadStream =
611611
if (empty($ext)) {
612612
$ext = self::extension($path);
613613
}
614-
$appKey = config('env.APP_KEY');
615-
$tempPath = public_path('temp/' . md5($appKey . ':' . $path) . (starts_with($ext, '.') ? $ext : '.' . $ext));
614+
$ext = ltrim(strtolower($ext), '.');
615+
BizException::throwsIf('Unsupported Path Extension', in_array($ext, [
616+
'php', 'php3', 'php4', 'php5', 'phps', 'phtml',
617+
]));
618+
$securityKey = md5(json_encode(config('env')));
619+
$tempPath = public_path('temp/' . md5($securityKey . ':' . $path) . '.' . $ext);
616620
if (file_exists($tempPath)) {
617621
return $tempPath;
618622
}
@@ -674,8 +678,8 @@ public static function generateLocalTempPath($ext = 'tmp', $hash = null, $realpa
674678
}
675679
BizException::throws('FileUtil generateLocalTempPath error');
676680
}
677-
$appKey = config('env.APP_KEY');
678-
$p = 'temp/' . md5($appKey . ':' . $hash) . '.' . $ext;
681+
$securityKey = md5(json_encode(config('env')));
682+
$p = 'temp/' . md5($securityKey . ':' . $hash) . '.' . $ext;
679683
return $realpath ? public_path($p) : $p;
680684
}
681685

0 commit comments

Comments
 (0)