Skip to content

Commit 3218e50

Browse files
Alex Martsinovichmartosaur
authored andcommitted
Polish docs
1 parent a8c4fd2 commit 3218e50

File tree

3 files changed

+11
-12
lines changed

3 files changed

+11
-12
lines changed

lib/safeurl/httpoison.ex

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,33 @@
11
if Code.ensure_loaded?(HTTPoison) do
22
defmodule SafeURL.HTTPoison do
3+
@moduledoc since: "1.0.0"
34
@moduledoc """
45
A utility module that should be a drop-in replacement for `HTTPoison`. Only
56
supports `get/3`.
67
"""
78

9+
@doc since: "1.0.0"
810
@doc """
911
Validate a URL and execute a GET request using `HTTPoison`.
1012
1113
If the URL is safe, this function will execute the request using
1214
`HTTPoison`, returning the result directly. Otherwise, it will
13-
return `{:error, :restricted}`.
15+
return error.
1416
1517
`headers` and `options` will be passed directly to
16-
`HTTPoison` when the request is executed. This function will
17-
raise if `HTTPoison` if not available.
18+
`HTTPoison` when the request is executed.
1819
1920
## Examples
2021
2122
iex> SafeURL.HTTPoison.get("https://10.0.0.1/ssrf.txt")
22-
{:error, :restricted}
23+
{:error, :unsafe_reserved}
2324
2425
iex> SafeURL.HTTPoison.get("https://google.com/")
2526
{:ok, %HTTPoison.Response{...}}
2627
27-
iex> SafeURL.HTTPoison.get("https://google.com/", schemes: ~w[ftp])
28-
{:error, :restricted}
29-
3028
"""
3129
@spec get(binary(), HTTPoison.headers(), Keyword.t()) ::
32-
{:ok, HTTPoison.Response.t()} | {:error, HTTPoison.Error.t()} | {:error, :restricted}
30+
{:ok, HTTPoison.Response.t()} | {:error, HTTPoison.Error.t()} | {:error, SafeURL.error()} | {:error, :restricted}
3331
def get(url, headers \\ [], options \\ []) do
3432
with :ok <- SafeURL.validate(url) do
3533
HTTPoison.get(url, headers, options)

lib/safeurl/safeurl.ex

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ defmodule SafeURL do
8585
:ok
8686
8787
iex> SafeURL.validate("https://app.service/", blocklist: ~w[170.0.0.0/24])
88-
{:error, :restricted}
88+
{:error, :unsafe_blocklist}
8989
9090
"""
9191

@@ -161,7 +161,7 @@ defmodule SafeURL do
161161
:ok
162162
163163
iex> SafeURL.validate("http://10.0.0.1/")
164-
{:error, :restricted}
164+
{:error, :unsafe_reserved}
165165
166166
iex> SafeURL.validate("http://10.0.0.1/", allowlist: ~w[10.0.0.0/8])
167167
:ok
@@ -171,7 +171,7 @@ defmodule SafeURL do
171171
See [`Options`](#module-options) section above.
172172
173173
"""
174-
@spec validate(binary(), Keyword.t()) :: :ok | {:error, error() | :restricted}
174+
@spec validate(binary(), Keyword.t()) :: :ok | {:error, error()} | {:error, :restricted}
175175
def validate(url, opts \\ []) do
176176
uri = URI.parse(url)
177177
opts = build_options(opts)

lib/safeurl/tesla_middleware.ex

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
if Code.ensure_loaded?(Tesla) do
22
defmodule SafeURL.TeslaMiddleware do
3+
@moduledoc since: "1.0.0"
34
@moduledoc """
45
Tesla middleware for validating URLs.
56
67
## Examples
78
89
iex> Tesla.client([SafeURL.TeslaMiddleware]) |> Tesla.get("http://localhost/")
9-
{:error, :restricted}
10+
{:error, :unsafe_reserved}
1011
"""
1112
@behaviour Tesla.Middleware
1213

0 commit comments

Comments
 (0)