TrustedProxyRewriter
An Elixir plug to rewrite the value of remote_ip key of Plug.Conn struct if the request comes from a trusted proxy. It expects the header to contain only one ip address.
Installation
-
Add the plug to your list of dependencies in
mix.exs:
```elixir
def deps do
[
{:trusted_proxy_rewriter, "~> 0.1.0"}
]
end
```-
If you are using Phoenix Framework then put the plug in your application's endpoint
lib\your_app\endpoint.ex:
```elixir
defmodule YourApp.Endpoint do
...
plug TrustedProxyRewriter, proxies: ["192.168.0.1/32"], header: "x-real-ip"
...
plug YourApp.Router
end
```- Configuration:
:proxies - list of trusted proxies
:header - name of the header with ip address
By default no proxy is trusted and the default header is x-real-ipChangelog
0.1.0
Started using the InetCidr library so the proxy list has to be in full CIDR notation