Skip to content

Commit c520b9a

Browse files
committed
Implement country denylist for user registration
1 parent 8d0b6b7 commit c520b9a

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

etc/config.sample.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@
4848
"user_register_requirements": {
4949
"email_enable_denylist": true,
5050
"email_validate_quick": true,
51+
"geoip_countrycode_denylist": {
52+
"CN": "China is banned from this site for spamming and registering fake accounts",
53+
"RU": "Russia is banned from this site for spamming and registering fake accounts",
54+
"UA": "Ukraine is banned from this site for association with Russia and spamming and registering fake accounts"
55+
},
5156
"password_allow_email": false,
5257
"password_allow_username": false,
5358
"password_length_max": null,
@@ -74,6 +79,9 @@
7479
},
7580
"email": {
7681
"recipient_denylist_regexp": [
82+
"/@.+\\\\.cn$/i",
83+
"/@.+\\\\.ru$/i",
84+
"/@.+\\\\.ua$/i",
7785
"/@mailinator\\.com$/i"
7886
],
7987
"recipient_from": [

src/controllers/User/Register.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ protected function tryRegister(Router &$router, UserRegisterModel &$model) {
9292
$usernamelen = strlen($username);
9393
$req = &Common::$config->bnetdocs->user_register_requirements;
9494
$email_denylist = &Common::$config->email->recipient_denylist_regexp;
95+
$countrycode_denylist = &$req->geoip_countrycode_denylist;
9596
if ($req->email_validate_quick
9697
&& !filter_var($email, FILTER_VALIDATE_EMAIL)) {
9798
$model->error = 'INVALID_EMAIL';
@@ -141,6 +142,16 @@ protected function tryRegister(Router &$router, UserRegisterModel &$model) {
141142
return;
142143
}
143144
}
145+
if (function_exists('geoip_country_code_by_name')) {
146+
$their_country = geoip_country_code_by_name(getenv('REMOTE_ADDR'));
147+
foreach ($countrycode_denylist as $bad_country => $reason) {
148+
if (strtoupper($their_country) == strtoupper($bad_country)) {
149+
$model->error = 'COUNTRY_DENIED';
150+
$model->error_extra = $reason;
151+
return;
152+
}
153+
}
154+
}
144155
if (Common::$config->bnetdocs->user_register_disabled) {
145156
$model->error = 'REGISTER_DISABLED';
146157
return;

src/templates/User/Register.phtml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,11 @@ switch ($this->getContext()->error) {
7070
$message = $this->getContext()->error_extra;
7171
if (empty($message)) $message = "The password is blacklisted.";
7272
break;
73+
case "COUNTRY_DENIED":
74+
$af = null;
75+
$message = $this->getContext()->error_extra;
76+
if (empty($message)) $message = "Your country is blacklisted.";
77+
break;
7378
case "REGISTER_DISABLED":
7479
$af = null;
7580
$message = "Creating accounts has been administratively disabled "

0 commit comments

Comments
 (0)