# `Perplexed.UrlGuard`
[🔗](https://github.com/agoodway/perplexed/blob/v0.2.0/lib/perplexed/url_guard.ex#L1)

Refuses URLs that would point a scrape at a private network.

Perplexed scrapes URLs a model or a search engine chose, so every request
and redirect target is checked here first. The default check allows only
`http`/`https` URLs without credentials whose host resolves only to public
addresses.

A host application can replace the check with `url_validator:
{Module, :fun, extra_args}`, per call (in the options) or in the settings;
it is called as `Module.fun(url, ...extra_args)` and must answer
`{:ok, url}` or `{:error, reason}`.

DNS is resolved here and again by the HTTP client, so a host that changes
its answer between the two (DNS rebinding) is not caught.

# `check`

```elixir
@spec check(String.t(), keyword()) :: {:ok, String.t()} | {:error, atom()}
```

`{:ok, url}` when `url` is safe to fetch, otherwise `{:error, reason}`.
Uses `opts[:url_validator]`, else the configured one, else `validate/1`.

# `private?`

```elixir
@spec private?(:inet.ip_address()) :: boolean()
```

Whether an `:inet` address tuple is loopback, private, link-local or otherwise reserved.

# `validate`

```elixir
@spec validate(String.t()) :: {:ok, String.t()} | {:error, atom()}
```

The built-in check, used when no `:url_validator` is configured.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
