element-hq / synapse

Synapse: Matrix homeserver written in Python/Twisted.
https://element-hq.github.io/synapse
GNU Affero General Public License v3.0
1.3k stars 157 forks source link

Add ability to rate limit messages per room #16021

Open matrixbot opened 9 months ago

matrixbot commented 9 months ago

This issue has been migrated from #16021.


Description:

I am building an RFQ (request for quotes) system with Matrix/Synapse.

I'd like to have the ability to set per room rate limits.

What is the best way to accomplish this with Matrix today?

I see matrix supports rc_invites per_room, but not rc_message per_room

joergjahnke commented 5 months ago

In a similar way we set the values for invites to very high values:

rc_invites:
  per_room:
    per_second: 500
    burst_count: 5000
  per_user:
    per_second: 4000
    burst_count: 30000
  per_issuer:
    per_second: 5000
    burst_count: 50000

But still we're seeing errors like this in the log file of the server:

2024-04-19 09:38:45,256 - synapse.access.http.8008 - 472 - INFO - POST-44 - 10.182.33.37 - 8008 - {@tk:my.matrix.host} Processed request: 0.084sec/0.000sec (0.004sec, 0.001sec) (0.001sec/0.079sec/8) 85B 403 "POST /_matrix/client/v3/rooms/!peMcdnwstCNtHoQvjZ:my.matrix.host/invite HTTP/1.1" "MatrixClient" [0 dbevts]
2024-04-19 09:38:45,266 - synapse.http.server - 126 - INFO - POST-45 - <XForwardedForRequest at 0x7f052f578110 method='POST' uri='/_matrix/client/v3/rooms/!BxvBAfjOwBuZGVBQxg:my.matrix.host/invite' clientproto='HTTP/1.1' site='8008'> SynapseError: 429 - Too Many Requests (rc_invites.per_issuer)

Might be related.