Pleroma v1.1.9-10-g42f76306+dev Pleroma.Plugs.RateLimiter View Source

Configuration

A keyword list of rate limiters where a key is a limiter name and value is the limiter configuration. The basic configuration is a tuple where:

  • The first element: scale (Integer). The time scale in milliseconds.
  • The second element: limit (Integer). How many requests to limit in the time scale provided.

It is also possible to have different limits for unauthenticated and authenticated users: the keyword value must be a list of two tuples where the first one is a config for unauthenticated users and the second one is for authenticated.

To disable a limiter set its value to nil.

Example

config :pleroma, :rate_limit,
  one: {1000, 10},
  two: [{10_000, 10}, {10_000, 50}],
  foobar: nil

Here we have three limiters:

  • one which is not over 10req/1s
  • two which has two limits: 10req/10s for unauthenticated users and 50req/10s for authenticated users
  • foobar which is disabled

Usage

AllowedSyntax:

plug(Pleroma.Plugs.RateLimiter, :limiter_name)
plug(Pleroma.Plugs.RateLimiter, {:limiter_name, options})

Allowed options:

* `bucket_name` overrides bucket name (e.g. to have a separate limit for a set of actions)
* `params` appends values of specified request params (e.g. ["id"]) to bucket name

Inside a controller:

plug(Pleroma.Plugs.RateLimiter, :one when action == :one)
plug(Pleroma.Plugs.RateLimiter, :two when action in [:two, :three])

plug(
  Pleroma.Plugs.RateLimiter,
  {:status_id_action, bucket_name: "status_id_action:fav_unfav", params: ["id"]}
  when action in ~w(fav_status unfav_status)a
)

or inside a router pipeline:

pipeline :api do
  ...
  plug(Pleroma.Plugs.RateLimiter, :one)
  ...
end

Link to this section Summary

Link to this section Functions