Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Antispam module's check_username_for_spam raises a TypeError when a user has no display name #245

Closed
squahtx opened this issue Mar 17, 2022 · 1 comment
Assignees
Labels
T-Defect Something isn't working, this is a bug

Comments

@squahtx
Copy link

squahtx commented Mar 17, 2022

Describe the bug
The Synapse documentation incorrectly claims that the check_username_for_spam callback receives a userprofile that is a Dict[str, str] (synapse#12245). In practice, there can be Nones in the userprofile dict, eg.

{
    avatar_url: None, 
    display_name: None, 
    user_id: '@[redacted]:matrix.org'
}

This causes the antispam callback to raise an error:

TypeError: expected string or bytes-like object
  File "synapse/http/server.py", line 268, in _async_render_wrapper
    callback_return = await self._async_render(request)
  File "synapse/http/server.py", line 470, in _async_render
    callback_return = await raw_callback_return
  File "synapse/rest/client/user_directory.py", line 75, in on_POST
    user_id, search_term, limit
  File "synapse/handlers/user_directory.py", line 103, in search_users
    if not await self.spam_checker.check_username_for_spam(user):
  File "synapse/events/spamcheck.py", line 404, in check_username_for_spam
    if await callback(user_profile.copy()):
  File "synapse/events/spamcheck.py", line 152, in run
    return maybe_awaitable(wrapped_func(*args, **kwargs))
  File "mjolnir/antispam.py", line 129, in check_username_for_spam
    user_profile["display_name"]
  File "mjolnir/antispam.py", line 60, in is_user_banned
    if rule.matches(user_id):
  File "mjolnir/list_rule.py", line 54, in matches
    return self.regex.match(victim)

https://sentry.matrix.org/sentry/synapse-matrixorg/issues/243697/

@squahtx squahtx added the T-Defect Something isn't working, this is a bug label Mar 17, 2022
@Yoric
Copy link
Contributor

Yoric commented Mar 17, 2022

@Gnuxie Could you take a look?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T-Defect Something isn't working, this is a bug
Projects
None yet
Development

No branches or pull requests

3 participants