Điểm qua slab/safeurl-elixir: 73 sao trên GitHub, viết chủ yếu bằng Elixir, thuộc nhóm Security. HTTP client with built-in SSRF protection, compatible with Tesla and HTTPoison
Tóm tắt dựng từ metadata GitHub của chính dự án — chưa có bài review TopGit. Trang sẽ tự động cập nhật khi bài review đầy đủ được xuất bản.
VÌ SAO CHƯA CÓ REVIEW
TopGit viết bài đầy đủ cho repo có nhiều sao nhất và được yêu cầu nhiều nhất. Trang này là snapshot trong thời gian chờ — xem README gốc ở tab READ ME.
SafeURL is a library that aids developers in protecting against a class of vulnerabilities
known as Server Side Request Forgery. It does this by validating a URL against a configurable
allow or block list before making an HTTP request.
See the Documentation on HexDocs.
Installation
To get started, add safeurl to your project dependencies in mix.exs. Optionally, you may
also add HTTPoison to your dependencies for making requests directly
through SafeURL:
def deps do
[
{:safeurl, "~> 1.0"},
{:httpoison, "~> 2.2"}, # Optional
]
end
To use SafeURL with your favorite HTTP Client, see the HTTP Clients section.
Usage
SafeURL blocks private/reserved IP addresses are by default, and users can add additional
CIDR ranges to the blocklist, or alternatively allow specific CIDR ranges to which the
application is allowed to make requests.
You can use allowed?/2 or validate/2 to check if a URL is safe to call. If you have the
HTTPoison application available, you can also call get/4 which will
validate the host automatically before making a web request, and return an error otherwise.
SafeURL can be configured to customize and override validation behaviour by passing the
following options:
:block_reserved - Block reserved/private IP ranges. Defaults to true.
:blocklist - List of CIDR ranges to block. This is additive with :block_reserved.
Defaults to [].
:allowlist - List of CIDR ranges to allow. If specified, blocklist will be ignored.
Defaults to [].
:schemes - List of allowed URL schemes. Defaults to ["http, "https"].
:dns_module - Any module that implements the SafeURL.DNSResolver behaviour.
Defaults to DNS from the :dns package.
:detailed_error - Return specific error if validation fails. If set to false, validate/2 will return {:error, :restricted} regardless of the reason. Defaults to true.
These options can be passed to the function directly or set globally in your config.exs
file:
While SafeURL already provides a convenient SafeURL.HTTPoison.get/3 method to validate hosts
before making GET HTTP requests, you can also write your own wrappers, helpers or
middleware to work with the HTTP Client of your choice.
HTTPoison
For HTTPoison, you can create a wrapper module that validates hosts
before making HTTP requests:
defmodule CustomClient do
def request(method, url, body, headers \\ [], opts \\ []) do
{safeurl_opts, opts} = Keyword.pop(opts, :safeurl, [])
with :ok <- SafeURL.validate(url, safeurl_opts) do
HTTPoison.request(method, url, body, headers, opts)
end
end
def get(url, headers \\ [], opts \\ []), do: request(:get, url, "", headers, opts)
def post(url, body, headers \\ [], opts \\ []), do: request(:post, url, body, headers, opts)
# ...
end
For Tesla, SafeURL provides a helper middleware out-of-the-box, which you can plug anywhere you're using Tesla:
defmodule DocumentService do
use Tesla
plug Tesla.Middleware.BaseUrl, "https://document-service/"
plug Tesla.Middleware.JSON
plug SafeURL.TeslaMiddleware, schemes: ~w[https], allowlist: ["10.0.0.0/24"]
def fetch(id) do
get("/documents/#{id}")
end
end
Custom DNS Resolver
In some cases you might want to use a custom strategy for DNS resolution. You can do so by
passing your own implementation of SafeURL.DNSResolver in the global or local
config.
Trang TopGit này là một snapshot — tab "Readme" hiển thị nguyên văn README của repo (đã bỏ link, giữ ảnh). Repo GitHub ở github.com/slab/safeurl-elixir là nguồn chính thức.
slab/safeurl-elixir có bao nhiêu sao?
slab/safeurl-elixir có 73 sao GitHub — tải lại trang để xem số mới nhất, hoặc xem trực tiếp github.com/slab/safeurl-elixir. TopGit phản chiếu số sao của GitHub nhưng không cam kết đến từng phút.