← All writing

Suggestions leak too

A staff command refused members, as it should. But while a member was typing it, the list of suggestions under the box showed them names anyway. The check was on the door and not on the window.

·2 min read

Slash commands in Discord can suggest values while you type. You start typing a name, and a list appears under the box. Bots fill that list themselves: Discord sends “this person has typed re”, and the bot answers with up to 25 choices.

My bot has commands for the staff and commands for everyone. Staff commands check your rights before they do anything. A member who runs one gets a polite refusal.

Normally a member doesn’t even see staff commands. But a server owner can change that in Discord’s own settings, and show any command to anyone.

The gap

When that happens, the command still refuses the member. Good.

But the suggestions come before the command runs. They’re a separate request with a separate handler. And my suggestion handlers didn’t check rights. They just answered: here are the saved reasons, the tags, the form names that start with re.

So a member could type a staff command, never send it, and read names in the list. Nothing dangerous in my case. Still wrong: the command says “you may not”, and the box under it says “but here’s what’s inside”.

One check, in one place

I have a lot of suggestion handlers, one per feature. Fixing each would mean finding each, and the next one I write would forget again.

The bot already has one function that answers “what can this person use here, right now?”. It’s the one behind the help command, which only lists what you can really run. So the fix is a single step before any suggestion handler:

  1. is this a staff command?
  2. if yes, is it in this person’s list?
  3. if not, answer with an empty list

Members’ own commands skip the check, so their suggestions cost nothing extra. That matters, because a bot has three seconds to answer and suggestions can’t ask for more time.

The test that pushed back

I wrote a test that types into every staff command as a plain member and expects an empty list. It passed.

Then the full test run failed on something else: a member typing in the ticket command no longer saw their own tickets. That command is listed as staff, but it has always let a member close their own ticket, and its suggestions only ever showed them their own.

My rule was too simple. That handler already did the right thing by itself, with more detail than my rule had. So it’s left alone, with a comment saying why.

What I keep

Anything that answers before the real action is still an answer. Previews, suggestions, counts, “3 results found”. If the action is protected, the hint about it needs the same protection.

And when a broad rule breaks one honest case, the case is usually telling me something the rule didn’t know.