Rate-limit REPORT and REQUEST on the real host instead of the spoofable nick

This commit is contained in:
Jean Chevronnet 2026-07-19 13:39:03 +00:00
parent b2ffc01e52
commit 3648c48d2e
No known key found for this signature in database
8 changed files with 27 additions and 32 deletions

View file

@ -60,7 +60,7 @@ impl Service for HelpServ {
fn on_command(&mut self, from: &Sender, args: &[&str], ctx: &mut ServiceCtx, net: &dyn NetView, db: &mut dyn Store) {
let me = self.uid.as_str();
match args.first().map(|s| s.to_ascii_uppercase()).as_deref() {
Some("REQUEST") | Some("HELPME") => request::handle(me, from, &args[1..], ctx, db),
Some("REQUEST") | Some("HELPME") => request::handle(me, from, &args[1..], ctx, net, db),
Some("CANCEL") => cancel::handle(me, from, ctx, db),
Some("LIST") => list::handle(me, from, args.get(1).copied(), ctx, db),
Some("VIEW") | Some("READ") => view::handle(me, from, args.get(1).copied(), ctx, db),

View file

@ -1,19 +1,16 @@
use echo_api::{Sender, ServiceCtx, Store};
use echo_api::{NetView, Sender, ServiceCtx, Store};
// REQUEST <message> (aka HELPME): open a help-desk ticket for the staff.
pub fn handle(me: &str, from: &Sender, rest: &[&str], ctx: &mut ServiceCtx, db: &mut dyn Store) {
pub fn handle(me: &str, from: &Sender, rest: &[&str], ctx: &mut ServiceCtx, net: &dyn NetView, db: &mut dyn Store) {
let message = rest.join(" ");
if message.trim().is_empty() {
ctx.notice(me, from.uid, "Tell us what you need help with: REQUEST <message>");
return;
}
// Require identification, so the cooldown keys on a stable account rather than a
// spoofable nick a flooder can cycle to reset it.
let Some(requester) = from.account else {
ctx.notice(me, from.uid, "Please identify to NickServ before opening a ticket.");
return;
};
match db.help_request(requester, &message) {
let requester = from.account.unwrap_or(from.nick);
// Rate-limit on the real host, not the spoofable nick (see REPORT).
let cooldown_key = net.host_of(from.uid).unwrap_or(from.uid);
match db.help_request(requester, cooldown_key, &message) {
Some(id) => ctx.notice(me, from.uid, format!("Thanks — your request (\x02#{id}\x02) is in the queue. A staff member will be with you.")),
None => ctx.notice(me, from.uid, "You just opened a ticket — please wait a moment before opening another."),
}