mode: cap mode changes per MODE command (modes=, default 20) and advertise it as the MODES= ISUPPORT token — an uncapped modestring like MODE #c +bbbb… dispatched a handler per letter, each fanning out to the whole channel and every S2S link (amplification DoS); matches InspIRCd's MODES limit
This commit is contained in:
parent
11cec9fc36
commit
c72b966e0a
2 changed files with 11 additions and 1 deletions
|
|
@ -119,11 +119,20 @@ pub fn apply_mode(s: &mut Server, uid: Uid, params: &[String]) -> CmdResult {
|
|||
let mut echoed: Vec<String> = Vec::new();
|
||||
// (sign, letter, displayed-param) per applied change — for hidemode filtering
|
||||
let mut changes: Vec<(char, char, Option<String>)> = Vec::new();
|
||||
// Cap mode changes per command (advertised as MODES=, default 20 like InspIRCd):
|
||||
// otherwise `MODE #c +bbbb…` in one line dispatches hundreds of handlers, each
|
||||
// fanning out to the whole channel and every link — a cheap amplification flood.
|
||||
let max_modes = s.conf_num("modes", 20usize).max(1);
|
||||
let mut processed = 0usize;
|
||||
for c in modestring.chars() {
|
||||
if c == '+' || c == '-' {
|
||||
sign = c;
|
||||
continue;
|
||||
}
|
||||
if processed >= max_modes {
|
||||
break;
|
||||
}
|
||||
processed += 1;
|
||||
let adding = sign == '+';
|
||||
let Some(handler) = chan_mode(c) else {
|
||||
s.numeric(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue