Skip to content

Commit 1ac2e81

Browse files
committed
Change blacklist/whitelist to blocklist/allowlist
1 parent b2ef401 commit 1ac2e81

File tree

2 files changed

+37
-37
lines changed

2 files changed

+37
-37
lines changed

lib/safeurl.ex

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ defmodule SafeURL do
22
@moduledoc """
33
`SafeURL` is library for mitigating Server Side Request
44
Forgery vulnerabilities in Elixir. Private/reserved IP
5-
addresses are blacklisted by default, and users can add
6-
additional CIDR ranges to blacklist, or alternatively
7-
whitelist specific CIDR ranges to which the application is
5+
addresses are blocked by default, and users can add
6+
additional CIDR ranges to the blocklist, or alternatively
7+
allow specific CIDR ranges to which the application is
88
allowed to make requests.
99
1010
You can use `allowed?/2` or `validate/2` to check if a
@@ -24,7 +24,7 @@ defmodule SafeURL do
2424
iex> SafeURL.validate("http://230.10.10.10/")
2525
{:error, :restricted}
2626
27-
iex> SafeURL.validate("http://230.10.10.10/", blacklist_reserved: false)
27+
iex> SafeURL.validate("http://230.10.10.10/", block_reserved: false)
2828
:ok
2929
3030
iex> SafeURL.get("https://10.0.0.1/ssrf.txt")
@@ -39,42 +39,42 @@ defmodule SafeURL do
3939
`SafeURL` can be configured to customize and override
4040
validation behaviour by passing the following options:
4141
42-
* `:blacklist_reserved` - Blacklist reserved/private IP
43-
ranges. Defaults to `true`.
42+
* `:block_reserved` - Block reserved/private IP ranges.
43+
Defaults to `true`.
4444
45-
* `:blacklist` - List of CIDR ranges to blacklist. This is
46-
additive with `:blacklist_reserved`. Defaults to `[]`.
45+
* `:blocklist` - List of CIDR ranges to block. This is
46+
additive with `:block_reserved`. Defaults to `[]`.
4747
48-
* `:whitelist` - List of CIDR ranges to whitelist. If
49-
specified, blacklists will be ignored. Defaults to `[]`.
48+
* `:allowlist` - List of CIDR ranges to allow. If
49+
specified, blocklist will be ignored. Defaults to `[]`.
5050
5151
* `:schemes` - List of allowed URL schemes. Defaults to
5252
`["http, "https"]`.
5353
54-
If `:blacklist_reserved` is `true` and additional hosts/ranges
55-
are supplied with `:blacklist`, both of them are included in
56-
the final blacklist to validate the address. If whitelisted
57-
ranges are supplied with `:whitelist`, all blacklists are
58-
ignored and any hosts not explicitly declared in the whitelist
54+
If `:block_reserved` is `true` and additional hosts/ranges
55+
are supplied with `:blocklist`, both of them are included in
56+
the final blocklist to validate the address. If allowed
57+
ranges are supplied with `:allowlist`, all blocklists are
58+
ignored and any hosts not explicitly declared in the allowlist
5959
are rejected.
6060
6161
These options can be set globally in your `config.exs` file:
6262
6363
config :safeurl,
64-
blacklist_reserved: true,
65-
blacklist: ~w[100.0.0.0/16],
64+
block_reserved: true,
65+
blocklist: ~w[100.0.0.0/16],
6666
schemes: ~w[https]
6767
6868
Or they can be passed to the function directly, overriding any
6969
global options if set:
7070
71-
iex> SafeURL.validate("http://10.0.0.1/", blacklist_reserved: false)
71+
iex> SafeURL.validate("http://10.0.0.1/", block_reserved: false)
7272
:ok
7373
74-
iex> SafeURL.validate("https://app.service/", whitelist: ~w[170.0.0.0/24])
74+
iex> SafeURL.validate("https://app.service/", allowlist: ~w[170.0.0.0/24])
7575
:ok
7676
77-
iex> SafeURL.validate("https://app.service/", blacklist: ~w[170.0.0.0/24])
77+
iex> SafeURL.validate("https://app.service/", blocklist: ~w[170.0.0.0/24])
7878
{:error, :restricted}
7979
8080
"""
@@ -104,11 +104,11 @@ defmodule SafeURL do
104104

105105

106106
@doc """
107-
Validate a string URL against a blacklist or whitelist.
107+
Validate a string URL against a blocklist or allowlist.
108108
109109
This method checks if a URL is safe to be called by looking at
110110
its scheme and resolved IP address, and matching it against
111-
reserved CIDR ranges, and any provided whitelist/blacklist.
111+
reserved CIDR ranges, and any provided allowlist/blocklist.
112112
113113
Returns `true` if the URL meets the requirements,
114114
`false` otherwise.
@@ -121,7 +121,7 @@ defmodule SafeURL do
121121
iex> SafeURL.allowed?("http://10.0.0.1/")
122122
false
123123
124-
iex> SafeURL.allowed?("http://10.0.0.1/", whitelist: ~w[10.0.0.0/8])
124+
iex> SafeURL.allowed?("http://10.0.0.1/", allowlist: ~w[10.0.0.0/8])
125125
true
126126
127127
## Options
@@ -139,11 +139,11 @@ defmodule SafeURL do
139139
uri.scheme not in opts.schemes ->
140140
false
141141

142-
opts.whitelist != [] ->
143-
ip_in_ranges?(address, opts.whitelist)
142+
opts.allowlist != [] ->
143+
ip_in_ranges?(address, opts.allowlist)
144144

145145
true ->
146-
!ip_in_ranges?(address, opts.blacklist)
146+
!ip_in_ranges?(address, opts.blocklist)
147147
end
148148
end
149149

@@ -164,7 +164,7 @@ defmodule SafeURL do
164164
iex> SafeURL.validate("http://10.0.0.1/")
165165
{:error, :restricted}
166166
167-
iex> SafeURL.validate("http://10.0.0.1/", whitelist: ~w[10.0.0.0/8])
167+
iex> SafeURL.validate("http://10.0.0.1/", allowlist: ~w[10.0.0.0/8])
168168
:ok
169169
170170
## Options
@@ -228,17 +228,17 @@ defmodule SafeURL do
228228
# Return a map of calculated options
229229
defp build_options(opts) do
230230
schemes = get_option(opts, :schemes)
231-
whitelist = get_option(opts, :whitelist)
232-
blacklist = get_option(opts, :blacklist)
231+
allowlist = get_option(opts, :allowlist)
232+
blocklist = get_option(opts, :blocklist)
233233

234-
blacklist =
235-
if get_option(opts, :blacklist_reserved) do
236-
blacklist ++ @reserved_ranges
234+
blocklist =
235+
if get_option(opts, :block_reserved) do
236+
blocklist ++ @reserved_ranges
237237
else
238-
blacklist
238+
blocklist
239239
end
240240

241-
%{schemes: schemes, whitelist: whitelist, blacklist: blacklist}
241+
%{schemes: schemes, allowlist: allowlist, blocklist: blocklist}
242242
end
243243

244244

mix.exs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@ defmodule SafeURL.MixProject do
4646
defp default_configs do
4747
[
4848
schemes: ~w[http https],
49-
blacklist_reserved: true,
50-
blacklist: [],
51-
whitelist: [],
49+
block_reserved: true,
50+
blocklist: [],
51+
allowlist: [],
5252
]
5353
end
5454

0 commit comments

Comments
 (0)