Captcha
2 years ago
Blacklist.php
3 years ago
CaptchaFormRenderer.php
3 years ago
Comment.php
3 years ago
Form.php
3 years ago
Manage.php
3 years ago
ManageSubscriptionFormRenderer.php
3 years ago
Pages.php
2 years ago
Registration.php
3 years ago
SubscriptionUrlFactory.php
3 years ago
Throttling.php
3 years ago
index.php
3 years ago
Blacklist.php
52 lines
| 1 | <?php // phpcs:ignore SlevomatCodingStandard.TypeHints.DeclareStrictTypes.DeclareStrictTypesMissing |
| 2 | |
| 3 | namespace MailPoet\Subscription; |
| 4 | |
| 5 | if (!defined('ABSPATH')) exit; |
| 6 | |
| 7 | |
| 8 | class Blacklist { |
| 9 | const SALT = 'mailpoet'; |
| 10 | |
| 11 | private $blacklistedEmails = [ |
| 12 | 'e60c6e0e73997c92d4ceac78a6b6cbbe6249244c4106a3c31de421fc50370ecd' => 1, |
| 13 | '4a7fb8fba0a800ad5cf324704d3510d019586765aef6d5081fa5aed3f93d9dce' => 1, |
| 14 | '7151c278028263ace958b66616e69a438f23e5058a5df42ed734e9e6704f8332' => 1, |
| 15 | ]; |
| 16 | |
| 17 | private $blacklistedDomains = [ |
| 18 | '2ea570cf0c440b2ec7d6e1335108625a5f62162b2116a25c9c909dc5b54c213f' => 1, |
| 19 | '1e10eb32b615217baa4d8f54191891e107851a2057d1128f067f1df096896e45' => 1, |
| 20 | 'dc2bfb04e38d3c25c8a465a5fed841a1cb1685044d12241efe01f0fc044f2182' => 1, |
| 21 | 'f17c13fe5a1d8cd2e78a04528377cc607881ad12b6295b6fa8b6a789d1d04c10' => 1, |
| 22 | '813cbef72da3542e783470ecd62589bceb3883d15ab2435ec2486f9762602b8c' => 1, |
| 23 | ]; |
| 24 | |
| 25 | public function __construct( |
| 26 | array $blacklistedEmails = null, |
| 27 | array $blacklistedDomains = null |
| 28 | ) { |
| 29 | if ($blacklistedEmails) { |
| 30 | $this->blacklistedEmails = array_fill_keys(array_map([$this, 'hash'], $blacklistedEmails), 1); |
| 31 | } |
| 32 | if ($blacklistedDomains) { |
| 33 | $this->blacklistedDomains = array_fill_keys(array_map([$this, 'hash'], $blacklistedDomains), 1); |
| 34 | } |
| 35 | } |
| 36 | |
| 37 | public function isBlacklisted($email) { |
| 38 | $hashedEmail = $this->hash($email); |
| 39 | if (isset($this->blacklistedEmails[$hashedEmail])) { |
| 40 | return true; |
| 41 | } |
| 42 | $emailParts = explode('@', $email); |
| 43 | $domain = end($emailParts); |
| 44 | $hashedDomain = $this->hash($domain); |
| 45 | return isset($this->blacklistedDomains[$hashedDomain]); |
| 46 | } |
| 47 | |
| 48 | private function hash($key) { |
| 49 | return hash('sha256', $key . self::SALT); |
| 50 | } |
| 51 | } |
| 52 |