Procházet zdrojové kódy

Try to fix the email leak in register form

Visman před 4 roky
rodič
revize
8213f1a4eb

+ 78 - 3
app/Models/Pages/Register.php

@@ -32,7 +32,7 @@ class Register extends Page
                 'token'    => 'token:RegisterForm',
                 'agree'    => 'required|token:Register',
                 'on'       => 'integer',
-                'email'    => 'required_with:on|string:trim|email:noban,unique',
+                'email'    => 'required_with:on|string:trim|email:noban', // ???? noban
                 'username' => 'required_with:on|string:trim|username',
                 'password' => 'required_with:on|string|min:16|password',
                 'register' => 'required|string',
@@ -52,7 +52,13 @@ class Register extends Page
         if ($v->validation($_POST, true)) {
             // завершение регистрации
             if (1 === $v->on) {
-                return $this->regEnd($v);
+                $userInDB =  $this->c->users->loadByEmail($v->email);
+
+                if ($userInDB instanceof User) {
+                    return $this->regDupe($v, $userInDB);
+                } else {
+                    return $this->regEnd($v);
+                }
             }
         } else {
             $this->fIswev = $v->getErrors();
@@ -186,7 +192,6 @@ class Register extends Page
             $this->c->Lang->load('common', $this->c->config->o_default_lang);
 
             $tplData = [
-                'fTitle'    => $this->c->config->o_board_title,
                 'fRootLink' => $this->c->Router->link('Index'),
                 'fMailer'   => __('Mailer', $this->c->config->o_board_title),
                 'username'  => $v->username,
@@ -276,6 +281,76 @@ class Register extends Page
         }
     }
 
+    /**
+     * Делает вид, что пользователь зарегистрирован (для предотвращения утечки email)
+     */
+    protected function regDupe(Validator $v, User $userInDB): Page
+    {
+        $this->c->Log->warning('Registriaton: dupe', [
+            'user'     => $this->user->fLog(), // ????
+            'attacked' => $userInDB->fLog(),
+            'form'     => $v->getData(false, ['token', 'password']),
+        ]);
+
+        // уведомление о дубликате email
+        if (
+            '1' == $this->c->config->o_regs_report
+            && '' != $this->c->config->o_mailing_list
+        ) {
+            $this->c->Lang->load('common', $this->c->config->o_default_lang);
+
+            $tplData = [
+                'fRootLink' => $this->c->Router->link('Index'),
+                'fMailer'   => __('Mailer', $this->c->config->o_board_title),
+                'username'  => $v->username,
+                'ip'        => $this->user->ip,
+                'userInDB'  => $userInDB->username,
+            ];
+
+            try {
+                $this->c->Mail
+                    ->reset()
+                    ->setMaxRecipients((int) $this->c->config->i_email_max_recipients)
+                    ->setFolder($this->c->DIR_LANG)
+                    ->setLanguage($this->c->config->o_default_lang)
+                    ->setTo($this->c->config->o_mailing_list)
+                    ->setFrom($this->c->config->o_webmaster_email, $tplData['fMailer'])
+                    ->setTpl('dupe_email_register.tpl', $tplData)
+                    ->send();
+            } catch (MailException $e) {
+                $this->c->Log->error('Registration: notification to admins, MailException', [
+                    'exception' => $e,
+                    'headers'   => false,
+                ]);
+            }
+        }
+
+        $this->c->Lang->load('common', $this->user->language);
+        $this->c->Lang->load('register');
+
+        // фейк отправки письма активации аккаунта
+        if ('1' == $this->c->config->o_regs_verify) {
+            $isSent = true;
+
+            // письмо активации аккаунта отправлено
+            if ($isSent) {
+                return $this->c->Message->message(__('Reg email', $this->c->config->o_admin_email), false, 200);
+            // форма сброса пароля
+            } else {
+                $auth         = $this->c->Auth;
+                $auth->fIswev = ['w', __('Error welcom mail', $this->c->config->o_admin_email)];
+
+                return $auth->forget([], 'GET', $v->email);
+            }
+        // форма логина
+        } else {
+            $auth         = $this->c->Auth;
+            $auth->fIswev = ['s', __('Reg complete')];
+
+            return $auth->login([], 'GET', $v->username);
+        }
+    }
+
     /**
      * Активация аккаунта
      */

+ 3 - 3
app/lang/en/mail/dupe_email_register.tpl

@@ -1,9 +1,9 @@
 Subject: Alert - Duplicate email detected
 
-User {!username!} registered with an email address that also belongs to: {!dupe_list!}
+User '{!username!}' [{!ip!}] tries to register with an email address that belongs to user '{!userInDB!}'.
 
-User profile: {!profile_url!}
+Forums at {!fRootLink!}
 
 --
-{!board_mailer!} Mailer
+{!fMailer!} Mailer
 (Do not reply to this message)

+ 3 - 3
app/lang/ru/mail/dupe_email_register.tpl

@@ -1,9 +1,9 @@
 Subject: Внимание - Обнаружено повторение адреса email
 
-Пользователь {!username!} зарегистрировался с указанием адреса email на принадлежащий также: {!dupe_list!}
+Пользователь '{!username!}' [{!ip!}] пытается зарегистрироваться с адресом email, который принадлежит пользователю  '{!userInDB!}'.
 
-Адрес профиля пользователя: {!profile_url!}
+Форум по адресу {!fRootLink!}
 
 --
-Отправитель {!board_mailer!}
+Отправитель {!fMailer!}
 (Не отвечайте на это сообщение)