https://github.com/tanguilp/apiac_filter_ip_whitelist
APIac Elixir plug for IP whitelisting
https://github.com/tanguilp/apiac_filter_ip_whitelist
Last synced: about 2 months ago
JSON representation
APIac Elixir plug for IP whitelisting
- Host: GitHub
- URL: https://github.com/tanguilp/apiac_filter_ip_whitelist
- Owner: tanguilp
- License: apache-2.0
- Created: 2018-11-07T13:28:31.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2020-04-29T19:34:45.000Z (about 5 years ago)
- Last Synced: 2025-04-15T07:03:09.698Z (2 months ago)
- Language: Elixir
- Homepage: https://hex.pm/packages/apiac_filter_ip_whitelist
- Size: 20.5 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# APIacFilterIPWhitelist
An `APIac.Filter` plug enabling IP whitelist (IPv4 & IPv6)
## Installation
```elixir
def deps do
[
{:apiac_filter_ip_whitelist, "~> 1.0"},
]
end
```## Plug options
- `whitelist`: a *list* of allowed IPv4 and IPv6 addresses in CIDR notation or a
`(Plug.Conn.t -> [String])` function returning that list of addresses
- `exec_cond`: a `(Plug.Conn.t() -> boolean())` function that determines whether
this filter is to be executed or not. Defaults to `fn _ -> true end`
- `send_error_response`: function called when IP address is not whitelisted.
Defaults to `APIacFilterIPWhitelist.send_error_response/3`
- `error_response_verbosity`: one of `:debug`, `:normal` or `:minimal`.
Defaults to `:normal`## Example
```elixir
plug APIacFilterIPWhitelist, whitelist: [
"192.168.13.0/24",
"2001:45B8:991A::/48",
"23.12.0.0/16",
"20E7:4128:D4F0:0::/64",
"91.23.251.0/24"
]
```## Security considerations
This plug uses the `remote_ip` field of the `Plug.Conn.t` for IP filtering, which means:
- **do use** [`remote_ip`](https://github.com/ajvondrak/remote_ip) or a similar
library if you're behind a proxy
- **do not use** `remote_ip` or a similar library if you're not behind a proxy