nickserv/chanserv: catch styled/fullwidth look-alike names too, and add a [register] confusable_check toggle (REHASH-reloadable)
All checks were successful
CI / check (push) Successful in 3m48s

This commit is contained in:
Jean Chevronnet 2026-07-19 00:15:08 +00:00
parent c2b70f5004
commit 89ac01d0b0
No known key found for this signature in database
11 changed files with 72 additions and 12 deletions

View file

@ -1935,6 +1935,11 @@ pub trait Store {
// Whether account identity is owned externally (website); when true, IRC // Whether account identity is owned externally (website); when true, IRC
// can't register or change credentials — it only authenticates. // can't register or change credentials — it only authenticates.
fn external_accounts(&self) -> bool; fn external_accounts(&self) -> bool;
// Whether REGISTER should reject look-alike / mixed-script names ([register]
// confusable_check). Defaults on; a mock store need not override it.
fn confusable_check_enabled(&self) -> bool {
true
}
// Staff notes on accounts/channels (oper-only), shown in INFO to operators. // Staff notes on accounts/channels (oper-only), shown in INFO to operators.
fn set_account_note(&mut self, account: &str, note: Option<String>) -> bool; fn set_account_note(&mut self, account: &str, note: Option<String>) -> bool;
fn account_note(&self, account: &str) -> Option<String>; fn account_note(&self, account: &str) -> Option<String>;
@ -2175,6 +2180,12 @@ pub fn confusable_reason(name: &str) -> Option<&'static str> {
fn is_invisible(cp: u32) -> bool { fn is_invisible(cp: u32) -> bool {
matches!(cp, 0xAD | 0x180E | 0x200B..=0x200F | 0x202A..=0x202E | 0x2060 | 0x2066..=0x2069 | 0xFEFF) matches!(cp, 0xAD | 0x180E | 0x200B..=0x200F | 0x202A..=0x202E | 0x2060 | 0x2066..=0x2069 | 0xFEFF)
} }
// "Styled" Latin that renders as normal-looking ASCII: fullwidth (),
// mathematical alphanumerics (𝐚𝐝𝐦𝐢𝐧), and enclosed/circled/squared letters.
// Nobody types a whole name this way except to imitate one.
fn is_fancy_latin(cp: u32) -> bool {
matches!(cp, 0xFF21..=0xFF5A | 0x1D400..=0x1D7FF | 0x1F130..=0x1F189 | 0x24B6..=0x24E9 | 0x2460..=0x24FF)
}
// Non-Latin letters that look like an ASCII Latin letter — the homoglyphs a // Non-Latin letters that look like an ASCII Latin letter — the homoglyphs a
// spoofer swaps in. Catches an all-look-alike name that pure script-mixing // spoofer swaps in. Catches an all-look-alike name that pure script-mixing
// would miss (e.g. an entirely-Cyrillic name that reads as Latin). // would miss (e.g. an entirely-Cyrillic name that reads as Latin).
@ -2198,6 +2209,9 @@ pub fn confusable_reason(name: &str) -> Option<&'static str> {
if is_invisible(cp) { if is_invisible(cp) {
return Some("That name uses invisible or text-direction characters. Please choose a plain name."); return Some("That name uses invisible or text-direction characters. Please choose a plain name.");
} }
if is_fancy_latin(cp) {
return Some("That name uses styled look-alike letters (fullwidth or symbol fonts). Please choose a plain name.");
}
if let Some((script, id)) = script_id(cp) { if let Some((script, id)) = script_id(cp) {
letters += 1; letters += 1;
if script == Script::Latin { if script == Script::Latin {
@ -2349,6 +2363,8 @@ mod tests {
"аеосх", // all-Cyrillic Latin look-alikes — homoglyph "аеосх", // all-Cyrillic Latin look-alikes — homoglyph
"ad\u{200b}min", // zero-width space "ad\u{200b}min", // zero-width space
"\u{202e}nimda", // right-to-left override "\u{202e}nimda", // right-to-left override
"", // fullwidth Latin
"\u{1D41A}\u{1D41D}\u{1D426}\u{1D422}\u{1D427}", // 𝐚𝐝𝐦𝐢𝐧 mathematical bold
] { ] {
assert!(confusable_reason(bad).is_some(), "should be rejected: {bad}"); assert!(confusable_reason(bad).is_some(), "should be rejected: {bad}");
} }

View file

@ -103,3 +103,12 @@ protocol = 1206 # InspIRCd link protocol version (1206 = insp4, 1205
# channel is unaffected; keep this off if you don't want echo talking to dict.org. # channel is unaffected; keep this off if you don't want echo talking to dict.org.
# [dictserv] # [dictserv]
# server = "dict.org:2628" # server = "dict.org:2628"
# Registration policy. The look-alike guard refuses REGISTER of a nick or channel
# that mixes alphabets (Cyrillic "аdmin"), is built from homoglyphs or styled
# (fullwidth/math) letters imitating Latin, or hides invisible/bidi characters —
# while genuine monolingual text (including accented French) passes. It's on by
# default; turn it off for a community that legitimately uses mixed/non-Latin
# names. Reloadable with OperServ REHASH.
# [register]
# confusable_check = false

View file

@ -132,10 +132,12 @@ impl Service for ChanServ {
return; return;
} }
// Refuse a look-alike / mixed-script channel name (e.g. a Cyrillic // Refuse a look-alike / mixed-script channel name (e.g. a Cyrillic
// homoglyph of a real channel). // homoglyph of a real channel), unless the guard is turned off.
if let Some(reason) = echo_api::confusable_reason(chan) { if db.confusable_check_enabled() {
ctx.notice(me, from.uid, reason); if let Some(reason) = echo_api::confusable_reason(chan) {
return; ctx.notice(me, from.uid, reason);
return;
}
} }
match db.register_channel(chan, account) { match db.register_channel(chan, account) {
Ok(()) => { Ok(()) => {

View file

@ -110,7 +110,7 @@ impl Service for NickServ {
return; return;
} }
match cmd.as_deref() { match cmd.as_deref() {
Some("REGISTER") => register::handle(me, from, args, ctx), Some("REGISTER") => register::handle(me, from, args, ctx, db),
Some("IDENTIFY") | Some("ID") => identify::handle(me, from, args, ctx, db), Some("IDENTIFY") | Some("ID") => identify::handle(me, from, args, ctx, db),
Some("LOGOUT") | Some("LOGOFF") => logout::handle(me, &self.guest_nick, &mut self.guest_seq, from, ctx), Some("LOGOUT") | Some("LOGOFF") => logout::handle(me, &self.guest_nick, &mut self.guest_seq, from, ctx),
Some("CERT") => cert::handle(me, from, args, ctx, db), Some("CERT") => cert::handle(me, from, args, ctx, db),

View file

@ -1,9 +1,9 @@
use echo_api::{Sender, ServiceCtx}; use echo_api::{Sender, ServiceCtx, Store};
use echo_api::RegReply; use echo_api::RegReply;
// REGISTER <password> [email]: register the sender's current nick. The engine // REGISTER <password> [email]: register the sender's current nick. The engine
// derives the password off-thread, commits, and answers. // derives the password off-thread, commits, and answers.
pub fn handle(me: &str, from: &Sender, args: &[&str], ctx: &mut ServiceCtx) { pub fn handle(me: &str, from: &Sender, args: &[&str], ctx: &mut ServiceCtx, db: &dyn Store) {
let Some(password) = args.get(1) else { let Some(password) = args.get(1) else {
ctx.notice(me, from.uid, "Syntax: REGISTER <password> [email]"); ctx.notice(me, from.uid, "Syntax: REGISTER <password> [email]");
return; return;
@ -12,10 +12,13 @@ pub fn handle(me: &str, from: &Sender, args: &[&str], ctx: &mut ServiceCtx) {
ctx.notice(me, from.uid, reason); ctx.notice(me, from.uid, reason);
return; return;
} }
// Refuse a look-alike / mixed-script nick before it can be used to impersonate. // Refuse a look-alike / mixed-script nick before it can be used to impersonate,
if let Some(reason) = echo_api::confusable_reason(from.nick) { // unless the guard is turned off.
ctx.notice(me, from.uid, reason); if db.confusable_check_enabled() {
return; if let Some(reason) = echo_api::confusable_reason(from.nick) {
ctx.notice(me, from.uid, reason);
return;
}
} }
let email = args.get(2).map(|s| s.to_string()); let email = args.get(2).map(|s| s.to_string());
ctx.defer_register(from.nick, *password, email, RegReply::NickServ { ctx.defer_register(from.nick, *password, email, RegReply::NickServ {

View file

@ -49,6 +49,9 @@ pub struct Config {
// not load and echo makes no outbound lookup requests. Opt-in on purpose. // not load and echo makes no outbound lookup requests. Opt-in on purpose.
#[serde(default)] #[serde(default)]
pub dictserv: Option<Dict>, pub dictserv: Option<Dict>,
// Registration policy. Absent = defaults (the look-alike guard is on).
#[serde(default)]
pub register: Register,
// Which InspIRCd matching-extbans AKICK may use. Absent = every extban echo // Which InspIRCd matching-extbans AKICK may use. Absent = every extban echo
// knows (full compatibility). List `enabled` to restrict it — e.g. drop the // knows (full compatibility). List `enabled` to restrict it — e.g. drop the
// ones your ircd doesn't provide. // ones your ircd doesn't provide.
@ -85,6 +88,22 @@ fn default_dict_server() -> String {
"dict.org:2628".to_string() "dict.org:2628".to_string()
} }
// Registration policy.
#[derive(Debug, Deserialize, Clone)]
#[serde(default)]
pub struct Register {
// Reject look-alike / mixed-script / invisible registration names. On by
// default; turn it off for a community that legitimately uses mixed or
// non-Latin names. Reloadable with REHASH.
pub confusable_check: bool,
}
impl Default for Register {
fn default() -> Self {
Self { confusable_check: true }
}
}
// Account-authority configuration. // Account-authority configuration.
#[derive(Debug, Deserialize, Clone)] #[derive(Debug, Deserialize, Clone)]
pub struct Auth { pub struct Auth {

View file

@ -1056,6 +1056,7 @@ pub struct Db {
// website): IRC can't register or change credentials, only authenticate // website): IRC can't register or change credentials, only authenticate
// against accounts pushed in (via the gRPC Accounts API). Node-local config. // against accounts pushed in (via the gRPC Accounts API). Node-local config.
external_accounts: bool, external_accounts: bool,
confusable_check: bool, // reject look-alike / mixed-script REGISTER names
} }
// A juped server: the held name, the fake server id we allocated for it, and why. // A juped server: the held name, the fake server id we allocated for it, and why.
@ -1124,7 +1125,7 @@ impl Db {
apply(&mut accounts, &mut channels, &mut grouped, &mut bots, &mut host_cfg, &mut net, event); apply(&mut accounts, &mut channels, &mut grouped, &mut bots, &mut host_cfg, &mut net, event);
} }
tracing::info!(accounts = accounts.len(), channels = channels.len(), "account store loaded"); tracing::info!(accounts = accounts.len(), channels = channels.len(), "account store loaded");
Self { accounts, channels, grouped, log, extban_enabled: None, notify_exclude: Vec::new(), live_extbans: None, live_chanmodes: None, scram_iterations: scram::DEFAULT_ITERATIONS, email_enabled: false, email_brand: "Network Services".to_string(), email_accent: "#4f46e5".to_string(), email_logo: String::new(), codes: HashMap::new(), auth_fails: HashMap::new(), vhost_req_times: HashMap::new(), report_times: HashMap::new(), bots, host_cfg, net, ignores: Vec::new(), defcon: 5, external_accounts: false } Self { accounts, channels, grouped, log, extban_enabled: None, notify_exclude: Vec::new(), live_extbans: None, live_chanmodes: None, scram_iterations: scram::DEFAULT_ITERATIONS, email_enabled: false, email_brand: "Network Services".to_string(), email_accent: "#4f46e5".to_string(), email_logo: String::new(), codes: HashMap::new(), auth_fails: HashMap::new(), vhost_req_times: HashMap::new(), report_times: HashMap::new(), bots, host_cfg, net, ignores: Vec::new(), defcon: 5, external_accounts: false, confusable_check: true }
} }
/// Fold an entry authored by another node into the store — the services-side /// Fold an entry authored by another node into the store — the services-side

View file

@ -338,6 +338,11 @@ impl Db {
self.external_accounts = on; self.external_accounts = on;
} }
/// Toggle the look-alike / mixed-script REGISTER guard (from `[register]`).
pub fn set_confusable_check(&mut self, on: bool) {
self.confusable_check = on;
}
/// The network defence level (5 = normal, 1 = full lockdown). /// The network defence level (5 = normal, 1 = full lockdown).
pub fn defcon(&self) -> u8 { pub fn defcon(&self) -> u8 {
self.defcon self.defcon

View file

@ -320,6 +320,9 @@ impl Store for Db {
fn external_accounts(&self) -> bool { fn external_accounts(&self) -> bool {
Db::external_accounts(self) Db::external_accounts(self)
} }
fn confusable_check_enabled(&self) -> bool {
self.confusable_check
}
fn set_account_note(&mut self, account: &str, note: Option<String>) -> bool { fn set_account_note(&mut self, account: &str, note: Option<String>) -> bool {
Db::set_account_note(self, account, note) Db::set_account_note(self, account, note)
} }

View file

@ -897,6 +897,7 @@ impl Engine {
self.set_standard_replies(cfg.server.standard_replies); self.set_standard_replies(cfg.server.standard_replies);
self.set_log_channel(cfg.log.as_ref().map(|l| l.channel.clone())); self.set_log_channel(cfg.log.as_ref().map(|l| l.channel.clone()));
self.db.set_notify_exclude(cfg.log.as_ref().map(|l| l.notify_exclude.clone()).unwrap_or_default()); self.db.set_notify_exclude(cfg.log.as_ref().map(|l| l.notify_exclude.clone()).unwrap_or_default());
self.db.set_confusable_check(cfg.register.confusable_check);
self.set_guest_nick(&cfg.server.guest_nick); self.set_guest_nick(&cfg.server.guest_nick);
if let Some(expire) = &cfg.expire { if let Some(expire) = &cfg.expire {
self.set_expiry(expire.account_ttl(), expire.channel_ttl(), expire.warn_ttl()); self.set_expiry(expire.account_ttl(), expire.channel_ttl(), expire.warn_ttl());

View file

@ -186,6 +186,7 @@ async fn main() -> Result<()> {
db.set_outbound(gossip_tx.clone()); db.set_outbound(gossip_tx.clone());
db.set_email_enabled(cfg.email.is_some()); db.set_email_enabled(cfg.email.is_some());
db.set_external_accounts(cfg.auth.as_ref().is_some_and(|a| a.external)); db.set_external_accounts(cfg.auth.as_ref().is_some_and(|a| a.external));
db.set_confusable_check(cfg.register.confusable_check);
match cfg.extban.as_ref().map(|e| e.enabled.as_slice()) { match cfg.extban.as_ref().map(|e| e.enabled.as_slice()) {
Some(list) if !list.is_empty() => { Some(list) if !list.is_empty() => {
db.set_extban_enabled(list.to_vec()); db.set_extban_enabled(list.to_vec());