VulnCheck.HTTP behaviour (VulnCheck v1.0.1)

Copy Markdown View Source

Minimal, hardened HTTP client built on :httpc and :ssl.

  • https:// requests always verify the peer certificate against the operating system trust store (:public_key.cacerts_get/0) and check the hostname.
  • Plain http:// is only allowed for loopback hosts (local test servers).
  • Successful responses are streamed with backpressure and aborted beyond :max_body_bytes (default 50 MiB). For other responses, :httpc delivers the buffered body before the client can check its size.
  • Partial responses are rejected because feed requests require a complete body.
  • Transient failures (502, 503, 504, timeouts, closed sockets) are retried up to two times with jitter.
  • Redirects are followed manually (at most 3) so every hop is validated.

The module implements the VulnCheck.HTTP behaviour itself; tests and embedders can pass any other implementation through the :http_client option accepted by the feed modules.

Summary

Functions

Performs a GET request.

TLS options used for https:// requests.

The User-Agent header value sent with every request.

Validates that a URL may be requested: https:// anywhere, http:// only on loopback hosts.

Types

response()

@type response() :: %{
  status: non_neg_integer(),
  headers: %{required(String.t()) => String.t()},
  body: binary()
}

Callbacks

get(url, headers, opts)

@callback get(url :: String.t(), headers :: [{String.t(), String.t()}], opts :: keyword()) ::
  {:ok, response()} | {:error, term()}

Functions

get(url, headers \\ [], opts \\ [])

@spec get(String.t(), [{String.t(), String.t()}], keyword()) ::
  {:ok, response()} | {:error, term()}

Performs a GET request.

Options: :timeout, :connect_timeout, :max_body_bytes, :retries (default 2), :retry_delay_ms (default 300) and :cacerts (trusted DER certificates, defaults to the operating system trust store).

ssl_options(opts \\ [])

@spec ssl_options(keyword()) :: keyword()

TLS options used for https:// requests.

user_agent()

@spec user_agent() :: String.t()

The User-Agent header value sent with every request.

validate_url(url)

@spec validate_url(String.t()) :: :ok | {:error, term()}

Validates that a URL may be requested: https:// anywhere, http:// only on loopback hosts.