Mercurial > prosody-modules
annotate mod_block_registrations/mod_block_registrations.lua @ 6371:caaa9ea58bec
mod_auth_sql: Document database table in README
| author | Christian Weiske <cweiske@cweiske.de> |
|---|---|
| date | Tue, 27 Jan 2026 21:12:21 +0100 |
| parents | f110bce35630 |
| children | a1df76ba4f68 |
| rev | line source |
|---|---|
|
1053
cabbcc1997d9
mod_block_registrations: Allow restricting registrations of certain user accounts, and/or ensure that registered accounts conform to a given pattern
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1 local nodeprep = require "util.encodings".stringprep.nodeprep; |
|
cabbcc1997d9
mod_block_registrations: Allow restricting registrations of certain user accounts, and/or ensure that registered accounts conform to a given pattern
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2 |
|
6322
f110bce35630
mod_block_registrations: Support blocking confusable usernames (UTS 39)
Kim Alvefur <zash@zash.se>
parents:
6321
diff
changeset
|
3 local normal = nodeprep; |
|
f110bce35630
mod_block_registrations: Support blocking confusable usernames (UTS 39)
Kim Alvefur <zash@zash.se>
parents:
6321
diff
changeset
|
4 if module:get_option_boolean("block_registrations_confusable", true) then |
|
f110bce35630
mod_block_registrations: Support blocking confusable usernames (UTS 39)
Kim Alvefur <zash@zash.se>
parents:
6321
diff
changeset
|
5 local confusable = require "util.encodings".confusable; |
|
f110bce35630
mod_block_registrations: Support blocking confusable usernames (UTS 39)
Kim Alvefur <zash@zash.se>
parents:
6321
diff
changeset
|
6 if not confusable then |
|
f110bce35630
mod_block_registrations: Support blocking confusable usernames (UTS 39)
Kim Alvefur <zash@zash.se>
parents:
6321
diff
changeset
|
7 module:log("error", "Prosody not built with ICU, confusables mapping is unavailable."); |
|
f110bce35630
mod_block_registrations: Support blocking confusable usernames (UTS 39)
Kim Alvefur <zash@zash.se>
parents:
6321
diff
changeset
|
8 module:log("error", "Rebuild or disable this feature with 'block_registrations_confusable = false'"); |
|
f110bce35630
mod_block_registrations: Support blocking confusable usernames (UTS 39)
Kim Alvefur <zash@zash.se>
parents:
6321
diff
changeset
|
9 end |
|
f110bce35630
mod_block_registrations: Support blocking confusable usernames (UTS 39)
Kim Alvefur <zash@zash.se>
parents:
6321
diff
changeset
|
10 function normal(username) |
|
f110bce35630
mod_block_registrations: Support blocking confusable usernames (UTS 39)
Kim Alvefur <zash@zash.se>
parents:
6321
diff
changeset
|
11 if username then |
|
f110bce35630
mod_block_registrations: Support blocking confusable usernames (UTS 39)
Kim Alvefur <zash@zash.se>
parents:
6321
diff
changeset
|
12 username = nodeprep(username); |
|
f110bce35630
mod_block_registrations: Support blocking confusable usernames (UTS 39)
Kim Alvefur <zash@zash.se>
parents:
6321
diff
changeset
|
13 end |
|
f110bce35630
mod_block_registrations: Support blocking confusable usernames (UTS 39)
Kim Alvefur <zash@zash.se>
parents:
6321
diff
changeset
|
14 if username then |
|
f110bce35630
mod_block_registrations: Support blocking confusable usernames (UTS 39)
Kim Alvefur <zash@zash.se>
parents:
6321
diff
changeset
|
15 username = confusable.skeleton(username); |
|
f110bce35630
mod_block_registrations: Support blocking confusable usernames (UTS 39)
Kim Alvefur <zash@zash.se>
parents:
6321
diff
changeset
|
16 end |
|
f110bce35630
mod_block_registrations: Support blocking confusable usernames (UTS 39)
Kim Alvefur <zash@zash.se>
parents:
6321
diff
changeset
|
17 return username; |
|
f110bce35630
mod_block_registrations: Support blocking confusable usernames (UTS 39)
Kim Alvefur <zash@zash.se>
parents:
6321
diff
changeset
|
18 end |
|
f110bce35630
mod_block_registrations: Support blocking confusable usernames (UTS 39)
Kim Alvefur <zash@zash.se>
parents:
6321
diff
changeset
|
19 end |
|
f110bce35630
mod_block_registrations: Support blocking confusable usernames (UTS 39)
Kim Alvefur <zash@zash.se>
parents:
6321
diff
changeset
|
20 |
|
5065
368bf9b06484
mod_block_registrations: Expand default list of blocked usernames (RFC 2142)
Matthew Wild <mwild1@gmail.com>
parents:
1697
diff
changeset
|
21 local block_users = module:get_option_set("block_registrations_users", { |
|
368bf9b06484
mod_block_registrations: Expand default list of blocked usernames (RFC 2142)
Matthew Wild <mwild1@gmail.com>
parents:
1697
diff
changeset
|
22 "abuse", "admin", "administrator", "hostmaster", "info", "news", |
|
368bf9b06484
mod_block_registrations: Expand default list of blocked usernames (RFC 2142)
Matthew Wild <mwild1@gmail.com>
parents:
1697
diff
changeset
|
23 "noc", "operator", "owner", "postmaster", "register", "registration", |
|
368bf9b06484
mod_block_registrations: Expand default list of blocked usernames (RFC 2142)
Matthew Wild <mwild1@gmail.com>
parents:
1697
diff
changeset
|
24 "root", "security", "service", "signup", "support", "sysadmin", |
|
368bf9b06484
mod_block_registrations: Expand default list of blocked usernames (RFC 2142)
Matthew Wild <mwild1@gmail.com>
parents:
1697
diff
changeset
|
25 "sysop", "system", "test", "trouble", "webmaster", "www", "xmpp", |
|
6322
f110bce35630
mod_block_registrations: Support blocking confusable usernames (UTS 39)
Kim Alvefur <zash@zash.se>
parents:
6321
diff
changeset
|
26 }) / normal; |
|
1053
cabbcc1997d9
mod_block_registrations: Allow restricting registrations of certain user accounts, and/or ensure that registered accounts conform to a given pattern
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
27 local block_patterns = module:get_option_set("block_registrations_matching", {}); |
|
cabbcc1997d9
mod_block_registrations: Allow restricting registrations of certain user accounts, and/or ensure that registered accounts conform to a given pattern
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
28 local require_pattern = module:get_option_string("block_registrations_require"); |
|
cabbcc1997d9
mod_block_registrations: Allow restricting registrations of certain user accounts, and/or ensure that registered accounts conform to a given pattern
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
29 |
|
cabbcc1997d9
mod_block_registrations: Allow restricting registrations of certain user accounts, and/or ensure that registered accounts conform to a given pattern
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
30 function is_blocked(username) |
|
6321
2f01497b04c9
mod_block_registrations: Fix indentation
Kim Alvefur <zash@zash.se>
parents:
5065
diff
changeset
|
31 -- Check if the username is simply blocked |
|
2f01497b04c9
mod_block_registrations: Fix indentation
Kim Alvefur <zash@zash.se>
parents:
5065
diff
changeset
|
32 if block_users:contains(username) then return true; end |
|
1053
cabbcc1997d9
mod_block_registrations: Allow restricting registrations of certain user accounts, and/or ensure that registered accounts conform to a given pattern
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
33 |
|
6322
f110bce35630
mod_block_registrations: Support blocking confusable usernames (UTS 39)
Kim Alvefur <zash@zash.se>
parents:
6321
diff
changeset
|
34 local normalized_username = normal(username); |
|
f110bce35630
mod_block_registrations: Support blocking confusable usernames (UTS 39)
Kim Alvefur <zash@zash.se>
parents:
6321
diff
changeset
|
35 if block_users:contains(normalized_username) then return true; end |
|
f110bce35630
mod_block_registrations: Support blocking confusable usernames (UTS 39)
Kim Alvefur <zash@zash.se>
parents:
6321
diff
changeset
|
36 |
|
6321
2f01497b04c9
mod_block_registrations: Fix indentation
Kim Alvefur <zash@zash.se>
parents:
5065
diff
changeset
|
37 for pattern in block_patterns do |
|
2f01497b04c9
mod_block_registrations: Fix indentation
Kim Alvefur <zash@zash.se>
parents:
5065
diff
changeset
|
38 if username:find(pattern) then |
|
2f01497b04c9
mod_block_registrations: Fix indentation
Kim Alvefur <zash@zash.se>
parents:
5065
diff
changeset
|
39 return true; |
|
2f01497b04c9
mod_block_registrations: Fix indentation
Kim Alvefur <zash@zash.se>
parents:
5065
diff
changeset
|
40 end |
|
2f01497b04c9
mod_block_registrations: Fix indentation
Kim Alvefur <zash@zash.se>
parents:
5065
diff
changeset
|
41 end |
|
2f01497b04c9
mod_block_registrations: Fix indentation
Kim Alvefur <zash@zash.se>
parents:
5065
diff
changeset
|
42 -- Not blocked, but check that username matches allowed pattern |
|
2f01497b04c9
mod_block_registrations: Fix indentation
Kim Alvefur <zash@zash.se>
parents:
5065
diff
changeset
|
43 if require_pattern and not username:match(require_pattern) then |
|
2f01497b04c9
mod_block_registrations: Fix indentation
Kim Alvefur <zash@zash.se>
parents:
5065
diff
changeset
|
44 return true; |
|
2f01497b04c9
mod_block_registrations: Fix indentation
Kim Alvefur <zash@zash.se>
parents:
5065
diff
changeset
|
45 end |
|
1053
cabbcc1997d9
mod_block_registrations: Allow restricting registrations of certain user accounts, and/or ensure that registered accounts conform to a given pattern
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
46 end |
|
cabbcc1997d9
mod_block_registrations: Allow restricting registrations of certain user accounts, and/or ensure that registered accounts conform to a given pattern
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
47 |
|
1331
dbaa67babeb4
mod_block_registrations: Switch to using the 'user-registering' event
Kim Alvefur <zash@zash.se>
parents:
1053
diff
changeset
|
48 module:hook("user-registering", function(event) |
|
6321
2f01497b04c9
mod_block_registrations: Fix indentation
Kim Alvefur <zash@zash.se>
parents:
5065
diff
changeset
|
49 local username = event.username; |
|
2f01497b04c9
mod_block_registrations: Fix indentation
Kim Alvefur <zash@zash.se>
parents:
5065
diff
changeset
|
50 if is_blocked(username) then |
|
2f01497b04c9
mod_block_registrations: Fix indentation
Kim Alvefur <zash@zash.se>
parents:
5065
diff
changeset
|
51 event.allowed = false; |
|
2f01497b04c9
mod_block_registrations: Fix indentation
Kim Alvefur <zash@zash.se>
parents:
5065
diff
changeset
|
52 return true; |
|
2f01497b04c9
mod_block_registrations: Fix indentation
Kim Alvefur <zash@zash.se>
parents:
5065
diff
changeset
|
53 end |
|
1053
cabbcc1997d9
mod_block_registrations: Allow restricting registrations of certain user accounts, and/or ensure that registered accounts conform to a given pattern
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
54 end, 10); |
