fix(security): harden registration email code validation
This commit is contained in:
1 parent
1eb085d4c0
commit
4e9dfd6018
2 files changed
+80
-2
No files matched your search
@@ -82,10 +82,13 @@ class RegisterService
|
||||
|
||||
// 检查邮箱验证
|
||||
if ((int) admin_setting('email_verify', 0)) {
|
||||
if (empty($request->input('email_code'))) {
|
||||
$emailCode = $request->input('email_code');
|
||||
if (!is_scalar($emailCode) || !preg_match('/^\d{6}$/', (string) $emailCode)) {
|
||||
return [false, [422, __('Email verification code cannot be empty')]];
|
||||
}
|
||||
if ((string) Cache::get(CacheKey::get('EMAIL_VERIFY_CODE', $request->input('email'))) !== (string) $request->input('email_code')) {
|
||||
|
||||
$cachedEmailCode = Cache::get(CacheKey::get('EMAIL_VERIFY_CODE', $request->input('email')));
|
||||
if ($cachedEmailCode === null || !hash_equals((string) $cachedEmailCode, (string) $emailCode)) {
|
||||
return [false, [400, __('Incorrect email verification code')]];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user