gotosocial
gotosocial copied to clipboard
[feature] Rate limiting of API requests
There's no rate-limiting for inbound requests currently, and this should be implemented to avoid the server being spammed/scraped by bad eggs.
There are a couple of middlewares available for Gin to do rate limiting:
- https://github.com/axiaoxin-com/ratelimiter
- https://github.com/yangxikun/gin-limit-by-key/blob/master/limit.go
- Probably some more that I didn't see yet.
These should be evaluated to see if they fit the needs of GoToSocial.
Ideally, whatever rate limiting implementation is used should have the following characteristics:
- Use the same rate-limit response headers as Mastodon for compatibility with Mastodon applications.
- Use the client IP as a rate-limiting key.
- In-memory implementation (good-enough for now).
- Sliding window limits (might be a bit complicated though -- fixed limits per minute would already be a fine start).
The rate limit implementation should be added to the security package here: https://github.com/superseriousbusiness/gotosocial/tree/main/internal/api/security
I think this is the most popular library:
It meets all your requirements. I could implement it, though I don't know which limits are appropriate. I found these for mastodons API https://docs.joinmastodon.org/api/rate-limits/ Though I would only go with two different rates, one for GET requests and one for POST requests.