Uppercase letters in username break reachable mention check in composer

While investigating Private Topics Plugin - #109 by thoka I stumbled upon the fact, that a mention for a user in a restricted category is not reported, when the username contains uppercase letters.

If I mention @SomeUser, the editor requests
/composer/mentions.json?names[]=SomeUser&topic_id=10728
in the result the username is returned in lowercase, without user_reasons set.

A query for the username in lowercase letters returns "user_reasons": {"someuser":"category"}.

If I use lowercase letters for the usernames in the composer, warnings for people with not sufficient rights will be shown.

If one use the autocompletion provided by the editor, the typed lowercase usernames will be replaced by uppercase names and therefore not reported.

3 Likes

Nice find @thoka !

The problem is here

users returns {"username_lower" => User object }

However if name is not downcased, users[name] does not exist.

Fix:

if user = users[name.downcase]
...
elsif group = groups[name.downcase]
...

Or better: downcase all names at the start of the method because there are a lot of issues in there, groups nicely does .where("lower(name) IN (?)", @names.map(&:downcase)) but functions like visible_group_ids_for_allowed_check, topic_allowed_group_ids, mentionable_group_ids and members_visible_group_ids all do where(name: @names) which introduces case sensitivity issues as well.

3 Likes

The correct fix is

https://github.com/discourse/discourse/pull/37177

but it’s too big a change than I’m confortable merging at this point :grimacing:

Instead, I’m going to fix each “endpoints” one by one to make it simpler to review and less risky.

Here’s first step

https://github.com/discourse/discourse/pull/39482

7 Likes

Since rebuilding discourse for the 188 commits from 645cb014c0 to 102c93e2ea, i’ve noticed what appears to be a regression in the markdown composer.

The warning appears to be misleading in this case, but it appears each time i try to prompt my custom agent @Forum_Research_Assis

I am able to consistantly re-produce this as per the video re-production,

I believe this same commit is missing logic to bypass when the user is mentioning an AI Agent.

Happy to start another pull request when you’re ready, though i already have an open one on my only GitHub account.

1 Like

Looks like my “fix” revealed this issue for AI Agents :thinking:

3 Likes