Mercurial > prosody-modules
comparison mod_block_registrations/mod_block_registrations.lua @ 6322:f110bce35630
mod_block_registrations: Support blocking confusable usernames (UTS 39)
This prevents registering e.g. "admin" but with a Cyrillic 'a' U+0430
and other such variations, including keming like "adrnin".
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Sat, 06 Sep 2025 21:02:26 +0200 |
| parents | 2f01497b04c9 |
| children | a1df76ba4f68 |
comparison
equal
deleted
inserted
replaced
| 6321:2f01497b04c9 | 6322:f110bce35630 |
|---|---|
| 1 local st = require "util.stanza"; | |
| 2 local nodeprep = require "util.encodings".stringprep.nodeprep; | 1 local nodeprep = require "util.encodings".stringprep.nodeprep; |
| 2 | |
| 3 local normal = nodeprep; | |
| 4 if module:get_option_boolean("block_registrations_confusable", true) then | |
| 5 local confusable = require "util.encodings".confusable; | |
| 6 if not confusable then | |
| 7 module:log("error", "Prosody not built with ICU, confusables mapping is unavailable."); | |
| 8 module:log("error", "Rebuild or disable this feature with 'block_registrations_confusable = false'"); | |
| 9 end | |
| 10 function normal(username) | |
| 11 if username then | |
| 12 username = nodeprep(username); | |
| 13 end | |
| 14 if username then | |
| 15 username = confusable.skeleton(username); | |
| 16 end | |
| 17 return username; | |
| 18 end | |
| 19 end | |
| 3 | 20 |
| 4 local block_users = module:get_option_set("block_registrations_users", { | 21 local block_users = module:get_option_set("block_registrations_users", { |
| 5 "abuse", "admin", "administrator", "hostmaster", "info", "news", | 22 "abuse", "admin", "administrator", "hostmaster", "info", "news", |
| 6 "noc", "operator", "owner", "postmaster", "register", "registration", | 23 "noc", "operator", "owner", "postmaster", "register", "registration", |
| 7 "root", "security", "service", "signup", "support", "sysadmin", | 24 "root", "security", "service", "signup", "support", "sysadmin", |
| 8 "sysop", "system", "test", "trouble", "webmaster", "www", "xmpp", | 25 "sysop", "system", "test", "trouble", "webmaster", "www", "xmpp", |
| 9 }); | 26 }) / normal; |
| 10 local block_patterns = module:get_option_set("block_registrations_matching", {}); | 27 local block_patterns = module:get_option_set("block_registrations_matching", {}); |
| 11 local require_pattern = module:get_option_string("block_registrations_require"); | 28 local require_pattern = module:get_option_string("block_registrations_require"); |
| 12 | 29 |
| 13 function is_blocked(username) | 30 function is_blocked(username) |
| 14 -- Check if the username is simply blocked | 31 -- Check if the username is simply blocked |
| 15 if block_users:contains(username) then return true; end | 32 if block_users:contains(username) then return true; end |
| 33 | |
| 34 local normalized_username = normal(username); | |
| 35 if block_users:contains(normalized_username) then return true; end | |
| 16 | 36 |
| 17 for pattern in block_patterns do | 37 for pattern in block_patterns do |
| 18 if username:find(pattern) then | 38 if username:find(pattern) then |
| 19 return true; | 39 return true; |
| 20 end | 40 end |
