Apply 2 suggestion(s) to 2 file(s)
authorfeld <feld@feld.me>
Wed, 7 Oct 2020 19:16:53 +0000 (19:16 +0000)
committerfeld <feld@feld.me>
Wed, 7 Oct 2020 19:16:53 +0000 (19:16 +0000)
lib/pleroma/plugs/remote_ip.ex
test/plugs/remote_ip_test.exs

index 51cc87ad8488fc2da0eace9e502c3c8c9c7d6b4b..987022156fdf440ef1ad7f5d2d7e88087d677322 100644 (file)
@@ -43,6 +43,6 @@ defmodule Pleroma.Plugs.RemoteIp do
         InetCidr.v6?(InetCidr.parse_address!(proxy)) -> proxy <> "/128"
       end
 
-    InetCidr.parse(proxy)
+    InetCidr.parse(proxy, true)
   end
 end
index 849c7fc3da4fea6e8ed30d502ecfb05cacb5f19c..2da9f616b6b0bdde469ef70248059ca9b18d81ec 100644 (file)
@@ -92,5 +92,18 @@ defmodule Pleroma.Plugs.RemoteIpTest do
       |> RemoteIp.call(nil)
 
     assert conn.remote_ip == {1, 1, 1, 1}
+
+  test "proxies set `nonsensical` CIDR" do
+    Pleroma.Config.put([RemoteIp, :reserved], ["127.0.0.0/8"])
+    Pleroma.Config.put([RemoteIp, :proxies], ["10.0.0.3/24"])
+
+    conn =
+      conn(:get, "/")
+      |> put_req_header("x-forwarded-for", "10.0.0.3, 1.1.1.1")
+      |> RemoteIp.call(nil)
+
+    assert conn.remote_ip == {1, 1, 1, 1}
+  end
+
   end
 end