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

user with extremely long MXID causes mjolnir to fail to ban #322

Closed
ninchuka opened this issue Jul 4, 2022 · 8 comments
Closed

user with extremely long MXID causes mjolnir to fail to ban #322

ninchuka opened this issue Jul 4, 2022 · 8 comments

Comments

@ninchuka
Copy link

ninchuka commented Jul 4, 2022

Describe the bug
mjolnir fails to ban a user with a extremely long MXID

To Reproduce
Steps to reproduce the behavior:

  1. attempt to ban @aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa:example.com

Expected behavior
for the user to be banned: There was an error processing your command - see console/log for details

(issue edited to remove offensive mxid)

@FSG-Cat
Copy link

FSG-Cat commented Jul 5, 2022

I would recomend a edit to the Issue descript that replaces the offensive MXID with @111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111:arcticfoxes.net

This new MXID is also 255 characters long but it is also complete junk data instead of a offensive MXID and it will trigger the exact same bug.

Like from my prespective i dont rly see a reason why we need to have this MXID in the issue. The account was deactivated by the HS admin and well the issue isnt unique to this MXID its actually just Mjolnir today fails to handle 255 char MXIDs due to a state key size limit and the way the state key is constructed for policy.

Below is some sanetised Logs of this exact bug being triggered using the MXID from the report btw. Sanetised as in i will replace the MXID with my pure ones version and i am changing the room ID

Jul 04 23:55:59 matrix matrix-bot-mjolnir[3139190]: Mon, 04 Jul 2022 21:55:59 GMT [INFO] [Mjolnir] Command being run by @cat:feline.support: !mjolnir ban FSG-COC @111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111:arcticfoxes.net
Jul 04 23:55:59 matrix matrix-bot-mjolnir[3139190]: Mon, 04 Jul 2022 21:55:59 GMT [ERROR] [MatrixHttpClient (REQ-64982)] [Error: Error during MatrixClient request GET /_matrix/client/r0/user/%40bot.mjolnir%3Afeline.support/account_data/org.matrix.mjolnir.default_list: 404 Not Found -- {"errcode":"M_NOT_FOUND","error":"Account data not found"}]
Jul 04 23:55:59 matrix matrix-bot-mjolnir[3139190]: Mon, 04 Jul 2022 21:55:59 GMT [WARN] [UnbanBanCommand] Non-fatal error getting default ban list
Jul 04 23:55:59 matrix matrix-bot-mjolnir[3139190]: Mon, 04 Jul 2022 21:55:59 GMT [WARN] [UnbanBanCommand] { errcode: 'M_NOT_FOUND', error: 'Account data not found' }
Jul 04 23:55:59 matrix matrix-bot-mjolnir[3139190]: Mon, 04 Jul 2022 21:55:59 GMT [ERROR] [MatrixHttpClient (REQ-64983)] [Error: Error during MatrixClient request PUT /_matrix/client/r0/rooms/!Meow%3Afeline.support/state/m.policy.rule.user/rule%3A%40111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111%3Aarcticfoxes.net: 413 Request Entity Too Large -- {"errcode":"M_TOO_LARGE","error":"'state_key' too large"}]
Jul 04 23:55:59 matrix matrix-bot-mjolnir[3139190]: Mon, 04 Jul 2022 21:55:59 GMT [ERROR] [CommandHandler] { errcode: 'M_TOO_LARGE', error: "'state_key' too large" }

@erkinalp
Copy link

erkinalp commented Jul 7, 2022

The proper remedy is a spec change allowing long state keys and/or jumbo events.

@MTRNord
Copy link

MTRNord commented Jul 7, 2022

The proper remedy is a spec change allowing long state keys and/or jumbo events.

No. Nico (can't remember his github name) already discovered that this is likely a Synapse messup on the size check. That user probably shouldn't even exist.

Iirc the state_key size limit is 255 bytes. So a logic step would be a) to check if the mxid length aligns with this and b) check how in the world that user even was able to join considering that a join would need a join event meaning that somehow that state_key length limit was evaded in the first place 🤔

@Gnuxie
Copy link
Contributor

Gnuxie commented Jul 7, 2022

Yes, state_key size limit is 255 bytes.

@nico-famedly
Copy link

No, the user is fine. The problem is that mjolnir doesn't account for the role: prefix when generating the state key. You can manually create the ban event in the banlist room with a shorter state key. See https://matrix.to/#/%23community-moderation-effort-bl%3Aneko.dev?via=neko.dev&via=jae.fi&via=grapheneos.org&via=matrix.org for example which bans that user too.

@nico-famedly
Copy link

(I would suggest mjolnir generates a random string for the last 127 chars of an mxid to avoid clashes when generating rules if the userid is too long)

Gnuxie added a commit that referenced this issue Aug 10, 2022
1. We keep track of the event that created a list rule so that we
can remove the rule by having a way to determine the original state key for the rule.
This is because the state key of rules can be anything and should not be
relied on by Mjolnir to unban things (which it was doing).

2. The old scheme for producing a state key was causing for some entities to escape bans
#322.

We could have used a hash or something similar, but we know that
the reason for the `rule:${entity}` scheme existed was for ease of debugging
and finding rules in devtools. So instead we have followed a scheme simalar to
bridges where the first character of an mxid is replaced with an underscore.
Everything else just gets put into the state key. Since domains can't have '@'
and room ids, aliases can't either.

3. We have stopped the need for Mjolnir to wait for the next response from sync after banning,
unbanning an entity so that we can apply ACL's sooner.
Gnuxie added a commit that referenced this issue Aug 10, 2022
1. We keep track of the event that created a list rule so that we
can remove the rule by having a way to determine the original state key for the rule.
This is because the state key of rules can be anything and should not be
relied on by Mjolnir to unban things (which it was doing).

2. The old scheme for producing a state key was causing for some entities to escape bans
#322.

We could have used a hash or something similar, but we know that
the reason for the `rule:${entity}` scheme existed was for ease of debugging
and finding rules in devtools. So instead we have followed a scheme simalar to
bridges where the first character of an mxid is replaced with an underscore.
Everything else just gets put into the state key. Since domains can't have '@'
and room ids, aliases can't either.

3. We have stopped the need for Mjolnir to wait for the next response from sync after banning,
unbanning an entity so that we can apply ACL's sooner.
Gnuxie added a commit that referenced this issue Aug 19, 2022
* Rework the banning and unbanning of entities in PolicyLists.

1. We keep track of the event that created a list rule so that we
can remove the rule by having a way to determine the original state key for the rule.
This is because the state key of rules can be anything and should not be
relied on by Mjolnir to unban things (which it was doing).

2. The old scheme for producing a state key was causing for some entities to escape bans
#322.

We could have used a hash or something similar, but we know that
the reason for the `rule:${entity}` scheme existed was for ease of debugging
and finding rules in devtools. So instead we have followed a scheme simalar to
bridges where the first character of an mxid is replaced with an underscore.
Everything else just gets put into the state key. Since domains can't have '@'
and room ids, aliases can't either.

3. We have stopped the need for Mjolnir to wait for the next response from sync after banning,
unbanning an entity so that we can apply ACL's sooner.

* Use PolicyList's `banEntity` method to create imported rules.
@turt2live
Copy link
Member

I believe this has been fixed. If not, please open a new issue.

@FSG-Cat
Copy link

FSG-Cat commented Oct 3, 2024

The 1.6.0 release fixes this so yes its correctly fixed as far as i remember.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants