comparison mod_block_registrations/mod_block_registrations.lua @ 6404:a1df76ba4f68

mod_block_registrations: Add username length requirements
author Kim Alvefur <zash@zash.se>
date Sat, 14 Feb 2026 12:57:22 +0100
parents f110bce35630
children
comparison
equal deleted inserted replaced
6403:13c61a068c71 6404:a1df76ba4f68
1 local nodeprep = require "util.encodings".stringprep.nodeprep; 1 local nodeprep = require "util.encodings".stringprep.nodeprep;
2 local it = require "util.iterators";
2 3
3 local normal = nodeprep; 4 local normal = nodeprep;
4 if module:get_option_boolean("block_registrations_confusable", true) then 5 if module:get_option_boolean("block_registrations_confusable", true) then
5 local confusable = require "util.encodings".confusable; 6 local confusable = require "util.encodings".confusable;
6 if not confusable then 7 if not confusable then
24 "root", "security", "service", "signup", "support", "sysadmin", 25 "root", "security", "service", "signup", "support", "sysadmin",
25 "sysop", "system", "test", "trouble", "webmaster", "www", "xmpp", 26 "sysop", "system", "test", "trouble", "webmaster", "www", "xmpp",
26 }) / normal; 27 }) / normal;
27 local block_patterns = module:get_option_set("block_registrations_matching", {}); 28 local block_patterns = module:get_option_set("block_registrations_matching", {});
28 local require_pattern = module:get_option_string("block_registrations_require"); 29 local require_pattern = module:get_option_string("block_registrations_require");
30 local length_min = module:get_option_number("block_registrations_length_minimum", 1);
31 local length_max = module:get_option_number("block_registrations_length_maximum", 255);
29 32
30 function is_blocked(username) 33 function is_blocked(username)
31 -- Check if the username is simply blocked 34 -- Check if the username is simply blocked
32 if block_users:contains(username) then return true; end 35 if block_users:contains(username) then return true; end
36
37 -- Check how long the username is (Unicode characters)
38 local length = it.count(username:gmatch("[\000-\127\194-\253][\128-\191]*"));
39 if length < length_min or length > length_max then return true; end
33 40
34 local normalized_username = normal(username); 41 local normalized_username = normal(username);
35 if block_users:contains(normalized_username) then return true; end 42 if block_users:contains(normalized_username) then return true; end
36 43
37 for pattern in block_patterns do 44 for pattern in block_patterns do