ecluse:ecluse-core
Safe HaskellNone
LanguageGHC2021

Ecluse.Core.Security.Authority

Description

Textual extraction of the host[:port] authority an outbound request dials.

These are comparison extractors, not an RFC 3986 parser: a value with no recognisable authority yields the empty string or Nothing, which every guard treats as not-allowed. The SSRF gates in Ecluse.Core.Security.Host consume the extracted HostPort, so the parsing here carries no policy of its own.

Synopsis

The dialled authority

data HostPort Source #

The authority an outbound fetch dials: a bare host with its effective port. The gate authorises the pair, so an allowlisted host at an attacker-chosen port is not authorised.

Constructors

HostPort 

Fields

  • hpHost :: Text

    The bare host: no brackets, no port, lower-cased by both extractors.

  • hpPort :: Word16

    The effective port: the explicit :port, or the caller's portless default.

Instances

Instances details
Show HostPort Source # 
Instance details

Defined in Ecluse.Core.Security.Authority

Eq HostPort Source # 
Instance details

Defined in Ecluse.Core.Security.Authority

Ord HostPort Source # 
Instance details

Defined in Ecluse.Core.Security.Authority

Authority extraction

hostAddress :: Text -> Text Source #

The bare host of a URI or host[:port] authority, lower-cased and unbracketed. A value with no recognisable host yields the empty string, which the guards treat as not-allowed.

hostPortAddress :: Text -> Maybe HostPort Source #

Extract the host and effective port, defaulting to 443. Refuse absent hosts and malformed ports.

hostPortAddressWithDefault :: Word16 -> Text -> Maybe HostPort Source #

hostPortAddress with the caller's own port for a URL that writes none, for a scheme whose portless default is not the gate's 443. The authority split and the port grammar do not change.

splitHostPort :: Text -> Maybe (Text, Text) Source #

Split a host[:port] authority into its bare host and the raw ":port" remainder, empty when no port is present. The split is bracket-aware, and an unclosed opening bracket yields Nothing.

Comparing authorities

data AuthorityText Source #

The only text of a URL that hostPortAddress reads. Equal texts give equal results, so a caller may reuse one's result for the other.

Instances

Instances details
Eq AuthorityText Source # 
Instance details

Defined in Ecluse.Core.Security.Authority

authorityText :: Text -> AuthorityText Source #

The authority of a URI or bare host[:port] value, without userinfo.

authorityHostPort :: AuthorityText -> Maybe HostPort Source #

hostPortAddress from the authority text alone: hostPortAddress = authorityHostPort . authorityText.

Configured-URL refusal

refuseCredentialMaterial :: Text -> Text -> Either Text () Source #

Refuse configured URLs with userinfo, query or fragment before any check quotes the URL. Reasons never quote credentials.

Log-safe rendering

authorityLabel :: Text -> Text Source #

A host and effective port label without credential carriers, or <unresolved> for an invalid authority.

dialledAuthorityLabel :: Text -> Text Source #

A credential-free authority label using port 80 for a portless http:// URL, otherwise 443.

credentialFreeUrl :: Text -> Text Source #

Remove userinfo, query and fragment while retaining the fetched URL's scheme, authority and path.

credentialFreeOrigin :: Text -> Text Source #

The scheme and the authority as written, without userinfo.

dialledOrigin :: Text -> Text Source #

The scheme and the dialled host:port, the part of a URL that names where it was fetched from.

credentialFreePath :: Text -> Text Source #

The path a URL fetches. The query and fragment are cut first, so a slash inside them is never read as the path.