Skip to content

l0.DependencyControl.Host

Host = require "l0.DependencyControl.Host"
local Host = require("l0.DependencyControl.Host")

Host

A host — a hostname or IP literal — that reports whether it targets a non-public IP address.

Constructor

host = Host host, resolver
local host = Host(host, resolver)
param type description
host string A hostname or IP-literal string.
resolver? fun(host: string): integer[][]? Address resolver (default: the class-level resolver).

Instance methods

addresses

host\addresses!
host:addresses()

Resolves this host to a list of address byte arrays, cached across calls. A literal host yields its own bytes without resolving; a non-literal host is looked up via the resolver (nil when it can't be resolved).

Returns:

  • addresses integer[][]?

resolvesToPrivate

host\resolvesToPrivate!
host:resolvesToPrivate()

Reports whether this host targets a non-public IP address — private, loopback, link-local, or reserved. Resolves a non-literal host on first call; an unresolvable host reads as false.

Returns:

  • private boolean — True when the host targets a non-public address.

Class methods

fromUrl

Host.fromUrl url, resolver
Host.fromUrl(url, resolver)

Builds a Host from a URL's host component, or nil when the URL carries no host.

param type description
url string The URL to extract the host from.
resolver? fun(host: string): integer[][]? Address resolver (default: the class-level resolver).

Returns:

isPrivateAddress

Host.isPrivateAddress bytes
Host.isPrivateAddress(bytes)

Reports whether a resolved IP address is in a non-public range.

param type description
bytes integer[] The address bytes (length 4 for IPv4, 16 for IPv6).

Returns:

  • private boolean — True when the address is private/loopback/link-local/reserved.

getUrlHostPart

Host.getUrlHostPart url
Host.getUrlHostPart(url)

Extracts the host from a URL, dropping protocol, auth, port and unwrapping a bracketed [IPv6].

param type description
url string The URL to extract the host from.

Returns:

  • host string? — The host, or nil when none could be extracted.

parseIPv4Literal

Host.parseIPv4Literal host
Host.parseIPv4Literal(host)

Parses an IPv4 literal in inet_aton form (dotted/decimal/octal/hex, 1-4 parts) to a 4-byte array. Hand-rolled to catch the legacy encodings the fetcher (curl/WinINet) accepts but a resolver's inet_pton rejects — e.g. decimal 2130706433 (== 127.0.0.1), which could be used to bypass SSRF protection. IPv6 literals have a single canonical form the resolver parses identically, so they don't need this.

param type description
host string The host string to parse.

Returns:

  • bytes integer[]? — The 4 address bytes, or nil when host isn't an IPv4 literal.