diff options
author | rinpatch <rinpatch@sdf.org> | 2020-02-28 17:44:59 +0300 |
---|---|---|
committer | rinpatch <rinpatch@sdf.org> | 2020-03-01 01:13:08 +0300 |
commit | ffcebe7e22b4c5ccaf3ba63f3ed2885ac55a6b4d (patch) | |
tree | a74b9123bd1ce852b4c17e39c3db94fb7a876a68 /lib/pleroma/web/mastodon_api/controllers | |
parent | 4d416343fae4a9e0b1654b12bd476017be63a7e9 (diff) | |
download | pleroma-ffcebe7e22b4c5ccaf3ba63f3ed2885ac55a6b4d.tar.gz |
timeline controller: rate limit timelines to 3 requests per 500ms per timeline per ip/user
Diffstat (limited to 'lib/pleroma/web/mastodon_api/controllers')
-rw-r--r-- | lib/pleroma/web/mastodon_api/controllers/timeline_controller.ex | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/lib/pleroma/web/mastodon_api/controllers/timeline_controller.ex b/lib/pleroma/web/mastodon_api/controllers/timeline_controller.ex index 29964a1d4..f58c1f93c 100644 --- a/lib/pleroma/web/mastodon_api/controllers/timeline_controller.ex +++ b/lib/pleroma/web/mastodon_api/controllers/timeline_controller.ex @@ -10,9 +10,20 @@ defmodule Pleroma.Web.MastodonAPI.TimelineController do alias Pleroma.Pagination alias Pleroma.Plugs.OAuthScopesPlug + alias Pleroma.Plugs.RateLimiter alias Pleroma.User alias Pleroma.Web.ActivityPub.ActivityPub + # XXX: Ideally these would be generated instead of copypasted, + # but I haven't been able to overcome an issue with guards when + # trying to generate these. + # See: https://elixirforum.com/t/trouble-plugging-plugs-with-generated-options-in-guards-in-a-phoenix-controller/29465 + plug(RateLimiter, [name: :timeline, bucket_name: :direct_timeline] when action == :direct) + plug(RateLimiter, [name: :timeline, bucket_name: :public_timeline] when action == :public) + plug(RateLimiter, [name: :timeline, bucket_name: :home_timeline] when action == :home) + plug(RateLimiter, [name: :timeline, bucket_name: :hashtag_timeline] when action == :hashtag) + plug(RateLimiter, [name: :timeline, bucket_name: :list_timeline] when action == :list) + plug(OAuthScopesPlug, %{scopes: ["read:statuses"]} when action in [:home, :direct]) plug(OAuthScopesPlug, %{scopes: ["read:lists"]} when action == :list) |