Merge branch 'develop' into 'remove-twitter-api'
[akkoma] / lib / pleroma / plugs / rate_limiter / rate_limiter.ex
index c3f6351c87cafe5ae60dfc7278a259b9274f5eaf..c51e2c6349e19b35d2ba11c9c2b45309a6a7d908 100644 (file)
@@ -78,7 +78,7 @@ defmodule Pleroma.Plugs.RateLimiter do
   end
 
   def call(conn, plug_opts) do
-    if disabled?() do
+    if disabled?(conn) do
       handle_disabled(conn)
     else
       action_settings = action_settings(plug_opts)
@@ -87,9 +87,9 @@ defmodule Pleroma.Plugs.RateLimiter do
   end
 
   defp handle_disabled(conn) do
-    if Config.get(:env) == :prod do
-      Logger.warn("Rate limiter is disabled for localhost/socket")
-    end
+    Logger.warn(
+      "Rate limiter disabled due to forwarded IP not being found. Please ensure your reverse proxy is providing the X-Forwarded-For header or disable the RemoteIP plug/rate limiter."
+    )
 
     conn
   end
@@ -109,16 +109,10 @@ defmodule Pleroma.Plugs.RateLimiter do
     end
   end
 
-  def disabled? do
-    localhost_or_socket =
-      Config.get([Pleroma.Web.Endpoint, :http, :ip])
-      |> Tuple.to_list()
-      |> Enum.join(".")
-      |> String.match?(~r/^local|^127.0.0.1/)
-
-    remote_ip_disabled = not Config.get([Pleroma.Plugs.RemoteIp, :enabled])
-
-    localhost_or_socket and remote_ip_disabled
+  def disabled?(conn) do
+    if Map.has_key?(conn.assigns, :remote_ip_found),
+      do: !conn.assigns.remote_ip_found,
+      else: false
   end
 
   @inspect_bucket_not_found {:error, :not_found}