matrix-org / dendrite

Dendrite is a second-generation Matrix homeserver written in Go!
https://matrix-org.github.io/dendrite/
Apache License 2.0
5.75k stars 674 forks source link

spec: dendrite doesn't correctly implement m.room.power_levels defaults #2983

Open bones-was-here opened 1 year ago

bones-was-here commented 1 year ago

Background information

Description

Steps to reproduce

A similar error occurs if removing a user with a power level of eg 7 from the list, which should return them to the default of 0 but instead is denied because the account making the change has power 50, not 90.

If I use a higher powered account to re-add these keys, it fixes the issues.

S7evinK commented 1 year ago

Would it be possible to provide the exact old and new powerlevels? Ideally as the complete events, so I can create a test and check if it's checkUserLevels or NewPowerLevelContentFromAuthEvents (or similar) in GMSL.

bones-was-here commented 1 year ago

All those events were updated several times since patching the bot, I could get something similar for a different room where it's still visible in prev_content if that's useful? It has quite different settings though, eg state_default is not 90.

S7evinK commented 1 year ago

So.. I gave It another try, but still can't reproduce the message from above. Tried to create a test for this here

=== RUN   TestPowerLevels
    eventauth_test.go:1536: Initial powerlevel event: {"auth_events":[],"content":{"ban":50,"events":null,"events_default":0,"invite":50,"kick":50,"notifications":{"room":50},"redact":50,"state_default":50,"users":{"@alice:localhost":100,"@bob:localhost":50},"users_default":0},"depth":0,"hashes":{"sha256":"mDzaoNJBgSCS5Yr4oEwEBG2iWUlAMZEfuiajfiw97Mw"},"origin":"localhost","origin_server_ts":1687355842966,"prev_events":[],"prev_state":[],"room_id":"!room:localhost","sender":"@alice:localhost","signatures":{"localhost":{"ed25519:1":"HFIVAPxZjMITVWwVIrOnb5nHfcMwbu7u1U6R2PhkTw1rnCVAwL/26EX5nIeizwSd2StWaGpl0Qd1+v4/aW1GDA"}},"state_key":"","type":"m.room.power_levels","unsigned":{}}
    eventauth_test.go:1562: Allow mods to change permissions: {"auth_events":[],"content":{"ban":50,"events":{"m.room.power_levels":50},"events_default":0,"invite":50,"kick":50,"notifications":{"room":50},"redact":50,"state_default":50,"users":{"@alice:localhost":100,"@bob:localhost":50},"users_default":0},"depth":0,"hashes":{"sha256":"scpxUgWq4zaeb1togoRpflIstERdzpKMNzvayzytVxQ"},"origin":"localhost","origin_server_ts":1687355842967,"prev_events":[],"prev_state":[],"room_id":"!room:localhost","sender":"@alice:localhost","signatures":{"localhost":{"ed25519:1":"vHv6qRzLVvxqx4PHVvkAvrsMLOIY0CNHRhPBIvV+5ZOEjBUIoBLobiHKLgFo3tofZb6MLeO2tzf+oqrPxkGCDA"}},"state_key":"","type":"m.room.power_levels","unsigned":{"prev_content":{"ban":50,"events":null,"events_default":0,"invite":50,"kick":50,"notifications":{"room":50},"redact":50,"state_default":50,"users":{"@alice:localhost":100,"@bob:localhost":50},"users_default":0}}}
    eventauth_test.go:1580: After setting state_default to 90: {"auth_events":[],"content":{"ban":50,"events":{"m.room.power_levels":50},"events_default":0,"invite":50,"kick":50,"notifications":{"room":50},"redact":50,"state_default":90,"users":{"@alice:localhost":100,"@bob:localhost":50},"users_default":0},"depth":0,"hashes":{"sha256":"b9PdbIZHRwzaK/jMyPaz9xhgv4XbyhBnnymUOBNy+cE"},"origin":"localhost","origin_server_ts":1687355842967,"prev_events":[],"prev_state":[],"room_id":"!room:localhost","sender":"@alice:localhost","signatures":{"localhost":{"ed25519:1":"kbUPzQoJiu8NSfm4Y11ETiBGVJW3QNHWmIvHck1BHzAbFVConYvhUBdCsI2tFqgt7SrH2eSl1i1bBnzXYQzQAQ"}},"state_key":"","type":"m.room.power_levels","unsigned":{"prev_content":{"ban":50,"events":{"m.room.power_levels":50},"events_default":0,"invite":50,"kick":50,"notifications":{"room":50},"redact":50,"state_default":50,"users":{"@alice:localhost":100,"@bob:localhost":50},"users_default":0}}}
    eventauth_test.go:1599: After removing users_default and events_default: {"auth_events":[],"content":{"ban":50,"events":{"m.room.power_levels":50},"invite":50,"kick":50,"notifications":{"room":50},"redact":50,"state_default":90,"users":{"@alice:localhost":100,"@bob:localhost":50}},"depth":0,"hashes":{"sha256":"zsISBV41ZnJPwqXoqUSdc9qwoyE9O0YUzSMr7+2lhZ0"},"origin":"localhost","origin_server_ts":1687355842967,"prev_events":[],"prev_state":[],"room_id":"!room:localhost","sender":"@alice:localhost","signatures":{"localhost":{"ed25519:1":"lhSCT1VHztO65s2BCpT65eKMhkxkvJYK+T2CfjV6XMCWRvCzExlTtqzVbDHXNM51v1vLr2yk58IoluaDr4HfCw"}},"state_key":"","type":"m.room.power_levels","unsigned":{"prev_content":{"ban":50,"events":{"m.room.power_levels":50},"events_default":0,"invite":50,"kick":50,"notifications":{"room":50},"redact":50,"state_default":90,"users":{"@alice:localhost":100,"@bob:localhost":50},"users_default":0}}}
    eventauth_test.go:1633: Trying to add users_default again: {"auth_events":[],"content":{"ban":50,"events":{"m.room.power_levels":50},"invite":50,"kick":50,"notifications":{"room":50},"redact":50,"state_default":90,"users":{"@alice:localhost":100,"@bob:localhost":50},"users_default":1},"depth":0,"hashes":{"sha256":"faoEjxqAo9+ULo2MJj9VcxXB/SxP+/lC6q6fDZzOjFc"},"origin":"localhost","origin_server_ts":1687355842968,"prev_events":[],"prev_state":[],"room_id":"!room:localhost","sender":"@bob:localhost","signatures":{"localhost":{"ed25519:1":"8dgEqwzs1NKCG4yrkz64DrQxoYM7qaukJiqWh6Q5V9l3ywjPbzecrRe29iyHD4f49+DjhcqE0VxqjEtIgXTHCg"}},"state_key":"","type":"m.room.power_levels","unsigned":{"prev_content":{"ban":50,"events":{"m.room.power_levels":50},"invite":50,"kick":50,"notifications":{"room":50},"redact":50,"state_default":90,"users":{"@alice:localhost":100,"@bob:localhost":50}}}}
--- PASS: TestPowerLevels (0.00s)

Aside from the test, I tried to follow your steps in Element Web, but also no issues there.