Perplexed.UrlGuard (Perplexed v0.2.0)

Copy Markdown View Source

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.

Summary

Functions

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

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

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

Functions

check(url, opts \\ [])

@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?(arg1)

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

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

validate(url)

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

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